Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Quick hack to add DELETE to siege-2.7.2
diff --git a/src/client.c b/src/client.c
index 09ebf64..7d63887 100644
--- a/src/client.c
+++ b/src/client.c
@@ -304,7 +304,13 @@ http_request(CONN *C, URL *U, CLIENT *client)
socket_close(C);
return FALSE;
}
- } else {
+ } else if (U->calltype == URL_DELETE) {
+ if ((http_delete(C, U)) < 0) {
+ C->connection.reuse = 0;
+ socket_close(C);
+ return FALSE;
+ }
+ } else if (U->calltype == URL_GET) {
if ((http_get(C, U)) < 0) {
C->connection.reuse = 0;
socket_close(C);
diff --git a/src/http.c b/src/http.c
index b4f8508..baf6f76 100644
--- a/src/http.c
+++ b/src/http.c
@@ -315,6 +315,121 @@ http_post(CONN *C, URL *U)
return 0;
}
+/**
+ * returns int, ( < 0 == error )
+ * formats and sends an HTTP/1.0 request
+ */
+int
+http_delete(CONN *C, URL *U)
+{
+ int rlen;
+ char *protocol;
+ char *keepalive;
+ char hoststr[512];
+ char authwww[512];
+ char authpxy[512];
+ char request[REQBUF+MAX_COOKIE_SIZE+8];
+ char portstr[16];
+ char fullpath[4096];
+ char cookie[MAX_COOKIE_SIZE+8];
+ time_t now;
+ char *ifmod = url_get_if_modified_since(U);
+ char *ifnon = url_get_etag(U);
+
+ now = time(NULL);
+
+ memset(hoststr, 0, sizeof hoststr);
+ memset(cookie, 0, sizeof cookie);
+ memset(request, 0, sizeof request);
+ memset(portstr, 0, sizeof portstr);
+
+ /* Request path based on proxy settings */
+ if(my.proxy.required){
+ sprintf(
+ fullpath, "%s://%s:%d%s", C->prot == HTTP?"http":"https", U->hostname, U->port, U->pathname
+ );
+ } else {
+ sprintf(fullpath, "%s", U->pathname);
+ }
+
+ if((U->port==80 && C->prot==HTTP) || (U->port==443 && C->prot==HTTPS)){
+ portstr[0] = '\0';
+ } else {
+ snprintf(portstr, sizeof portstr, ":%d", U->port);
+ }
+
+ /* HTTP protocol string */
+ protocol = (my.protocol == TRUE)?"HTTP/1.1":"HTTP/1.0";
+ keepalive = (C->connection.keepalive == TRUE)?"keep-alive":"close";
+ get_cookie_header(pthread_self(), U->hostname, cookie);
+ if(C->auth.www){
+ if(C->auth.type.www==DIGEST){
+ char *tmp;
+ tmp = digest_generate_authorization(C->auth.wwwchlg, C->auth.wwwcred, "GET", fullpath);
+ rlen = snprintf(authwww, sizeof(authwww), "Authorization: %s\015\012", tmp);
+ free(tmp);
+ } else {
+ rlen = snprintf(authwww, sizeof(authwww), "Authorization: Basic %s\015\012", my.auth.encode);
+ }
+ }
+ if(C->auth.proxy){
+ if(C->auth.type.proxy==DIGEST){
+ char *tmp;
+
+ tmp = digest_generate_authorization(C->auth.proxychlg, C->auth.proxycred, "GET", fullpath);
+ rlen = snprintf( authpxy, sizeof(authpxy), "Proxy-Authorization: %s\015\012", tmp);
+ free(tmp);
+ } else {
+ rlen = snprintf( authpxy, sizeof(authpxy), "Proxy-Authorization: Basic %s\015\012", my.proxy.encode);
+ }
+ }
+
+ /* Only send the Host header if one wasn't provided. */
+ if(strncasestr(my.extra, "host:", sizeof(my.extra)) == NULL){
+ rlen = snprintf(hoststr, sizeof(hoststr), "Host: %s%s\015\012", U->hostname, portstr);
+ }
+
+ /**
+ * build a request string to pass to the server
+ */
+ rlen = snprintf(
+ request, sizeof( request ),
+ "DELETE %s %s\015\012" /* fullpath, protocol */
+ "%s" /* hoststr */
+ "%s" /* authwww or empty str */
+ "%s" /* authproxy or empty str */
+ "%s" /* cookie or empty str */
+ "%s" /* ifmod or empty str */
+ "%s" /* ifnon or empty str */
+ "Accept: */*\015\012" /* */
+ "Accept-Encoding: %s\015\012" /* my.encoding */
+ "User-Agent: %s\015\012" /* my uagent */
+ "%s" /* my.extra */
+ "Connection: %s\015\012\015\012", /* keepalive */
+ fullpath, protocol, hoststr,
+ (C->auth.www==TRUE)?authwww:"",
+ (C->auth.proxy==TRUE)?authpxy:"",
+ (strlen(cookie) > 8)?cookie:"",
+ (ifmod!=NULL)?ifmod:"",
+ (ifnon!=NULL)?ifnon:"",
+ my.encoding, my.uagent, my.extra, keepalive
+ );
+
+ if(my.debug || my.get){ printf("%s\n", request); fflush(stdout); }
+ if(rlen < 0 || rlen > (int)sizeof(request)){
+ NOTIFY(FATAL, "HTTP DELETE: request buffer overrun!");
+ }
+ if((socket_write(C, request, rlen)) < 0){
+ xfree(ifmod);
+ xfree(ifnon);
+ return -1;
+ }
+
+ xfree(ifmod);
+ xfree(ifnon);
+ return 0;
+}
+
void
http_free_headers(HEADERS *h)
{
diff --git a/src/http.h b/src/http.h
index 96d0d1c..3ba7e44 100644
--- a/src/http.h
+++ b/src/http.h
@@ -76,6 +76,8 @@ struct headers
/* http function prototypes */
int http_get (CONN *C, URL *U);
int http_post(CONN *C, URL *U);
+int http_delete (CONN *C, URL *U);
+
void http_free_headers(HEADERS *h);
HEADERS *http_read_headers(CONN *C, URL *U);
ssize_t http_read(CONN *C);
diff --git a/src/url.c b/src/url.c
index 037a174..5d696bd 100644
--- a/src/url.c
+++ b/src/url.c
@@ -341,6 +341,12 @@ build_url(char *url, int defaultport, int id)
*post_cmd = 0;
post_cmd += 5;
+}
+
void
http_free_headers(HEADERS *h)
{
diff --git a/src/http.h b/src/http.h
index 96d0d1c..3ba7e44 100644
--- a/src/http.h
+++ b/src/http.h
@@ -76,6 +76,8 @@ struct headers
/* http function prototypes */
int http_get (CONN *C, URL *U);
int http_post(CONN *C, URL *U);
+int http_delete (CONN *C, URL *U);
+
void http_free_headers(HEADERS *h);
HEADERS *http_read_headers(CONN *C, URL *U);
ssize_t http_read(CONN *C);
diff --git a/src/url.c b/src/url.c
index 037a174..5d696bd 100644
--- a/src/url.c
+++ b/src/url.c
@@ -341,6 +341,12 @@ build_url(char *url, int defaultport, int id)
*post_cmd = 0;
post_cmd += 5;
process_post_data(U, post_cmd);
+ } else if (strstr(url, " DELETE")){
+ U->calltype = URL_DELETE;
+ U->postdata = NULL;
+ U->posttemp = NULL;
+ U->postlen = 0;
+ *strstr(url, " DELETE")=0;
} else {
U->calltype = URL_GET;
U->postdata = NULL;
diff --git a/src/url.h b/src/url.h
index 93dd8c2..94e43e5 100644
--- a/src/url.h
+++ b/src/url.h
@@ -31,7 +31,8 @@
*/
typedef enum {
URL_GET = 0,
- URL_POST = 1
+ URL_POST = 1,
+ URL_DELETE = 2,
} DIRECTIVE;
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.