public
Last active

Quick hack to add DELETE to siege-2.7.2

  • Download Gist
Siege-DELETE-hack
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
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;
/**

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.