diff options
Diffstat (limited to 'src/examples/mhd2spdy_http.c')
-rw-r--r-- | src/examples/mhd2spdy_http.c | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/src/examples/mhd2spdy_http.c b/src/examples/mhd2spdy_http.c index 7881d57a..1f7dec97 100644 --- a/src/examples/mhd2spdy_http.c +++ b/src/examples/mhd2spdy_http.c | |||
@@ -36,6 +36,7 @@ const char * uri) | |||
36 | 36 | ||
37 | PRINT_INFO2("log uri '%s'\n", uri); | 37 | PRINT_INFO2("log uri '%s'\n", uri); |
38 | 38 | ||
39 | //TODO not freed once in a while | ||
39 | if(NULL == (http_uri = au_malloc(sizeof(struct HTTP_URI )))) | 40 | if(NULL == (http_uri = au_malloc(sizeof(struct HTTP_URI )))) |
40 | DIE("no memory"); | 41 | DIE("no memory"); |
41 | http_uri->uri = strdup(uri); | 42 | http_uri->uri = strdup(uri); |
@@ -176,6 +177,7 @@ http_cb_request (void *cls, | |||
176 | int ret; | 177 | int ret; |
177 | struct Proxy *proxy; | 178 | struct Proxy *proxy; |
178 | struct SPDY_Headers spdy_headers; | 179 | struct SPDY_Headers spdy_headers; |
180 | bool with_body = false; | ||
179 | 181 | ||
180 | //PRINT_INFO2("request cb %i; %s", *ptr,url); | 182 | //PRINT_INFO2("request cb %i; %s", *ptr,url); |
181 | 183 | ||
@@ -185,14 +187,14 @@ http_cb_request (void *cls, | |||
185 | 187 | ||
186 | if(NULL == http_uri->proxy) | 188 | if(NULL == http_uri->proxy) |
187 | { | 189 | { |
188 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) | 190 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET) && 0 != strcmp (method, MHD_HTTP_METHOD_POST)) |
189 | { | 191 | { |
190 | free(http_uri->uri); | 192 | free(http_uri->uri); |
191 | free(http_uri); | 193 | free(http_uri); |
192 | PRINT_INFO2("unexpected method %s", method); | 194 | PRINT_INFO2("unexpected method %s", method); |
193 | return MHD_NO; | 195 | return MHD_NO; |
194 | } | 196 | } |
195 | 197 | ||
196 | if(NULL == (proxy = au_malloc(sizeof(struct Proxy)))) | 198 | if(NULL == (proxy = au_malloc(sizeof(struct Proxy)))) |
197 | { | 199 | { |
198 | PRINT_INFO("No memory"); | 200 | PRINT_INFO("No memory"); |
@@ -211,14 +213,62 @@ http_cb_request (void *cls, | |||
211 | 213 | ||
212 | if(proxy->spdy_active) | 214 | if(proxy->spdy_active) |
213 | { | 215 | { |
216 | if(0 == strcmp (method, MHD_HTTP_METHOD_POST)) | ||
217 | { | ||
218 | PRINT_INFO("POST processing"); | ||
219 | |||
220 | int rc= spdylay_session_resume_data(proxy->spdy_connection->session, proxy->stream_id); | ||
221 | PRINT_INFO2("rc is %i stream is %i", rc, proxy->stream_id); | ||
222 | proxy->spdy_connection->want_io |= WANT_WRITE; | ||
223 | |||
224 | if(0 == *upload_data_size) | ||
225 | { | ||
226 | PRINT_INFO("POST http EOF"); | ||
227 | proxy->receiving_done = true; | ||
228 | return MHD_YES; | ||
229 | } | ||
230 | |||
231 | if(!copy_buffer(upload_data, *upload_data_size, &proxy->received_body, &proxy->received_body_size)) | ||
232 | { | ||
233 | //TODO handle it better? | ||
234 | PRINT_INFO("not enough memory (malloc/realloc returned NULL)"); | ||
235 | return MHD_NO; | ||
236 | } | ||
237 | /* | ||
238 | if(NULL == proxy->received_body) | ||
239 | proxy->received_body = malloc(*upload_data_size); | ||
240 | else | ||
241 | proxy->received_body = realloc(proxy->received_body, proxy->received_body_size + *upload_data_size); | ||
242 | if(NULL == proxy->received_body) | ||
243 | { | ||
244 | //TODO handle it better? | ||
245 | PRINT_INFO("not enough memory (realloc returned NULL)"); | ||
246 | return MHD_NO; | ||
247 | } | ||
248 | |||
249 | memcpy(proxy->received_body + proxy->received_body_size, upload_data, *upload_data_size); | ||
250 | proxy->received_body_size += *upload_data_size; | ||
251 | */ | ||
252 | *upload_data_size = 0; | ||
253 | |||
254 | //raise(SIGINT); | ||
255 | |||
256 | return MHD_YES; | ||
257 | } | ||
258 | |||
214 | //already handled | 259 | //already handled |
215 | PRINT_INFO("unnecessary call to http_cb_request"); | 260 | PRINT_INFO("unnecessary call to http_cb_request"); |
216 | return MHD_YES; | 261 | return MHD_YES; |
217 | } | 262 | } |
218 | 263 | ||
219 | PRINT_INFO2("received request for '%s %s %s'\n", method, http_uri->uri, version); | 264 | PRINT_INFO2("received request for '%s %s %s'", method, http_uri->uri, version); |
220 | 265 | ||
221 | proxy->url = http_uri->uri; | 266 | proxy->url = http_uri->uri; |
267 | |||
268 | with_body = 0 == strcmp (method, MHD_HTTP_METHOD_POST) && 0 != strcmp ("0", | ||
269 | MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH)); | ||
270 | |||
271 | PRINT_INFO2("body will be sent %i", with_body); | ||
222 | 272 | ||
223 | ret = parse_uri(&glob_opt.uri_preg, proxy->url, &proxy->uri); | 273 | ret = parse_uri(&glob_opt.uri_preg, proxy->url, &proxy->uri); |
224 | if(ret != 0) | 274 | if(ret != 0) |
@@ -232,7 +282,7 @@ http_cb_request (void *cls, | |||
232 | NULL); | 282 | NULL); |
233 | if(NULL == (spdy_headers.nv = au_malloc(((spdy_headers.num + 5) * 2 + 1) * sizeof(char *)))) | 283 | if(NULL == (spdy_headers.nv = au_malloc(((spdy_headers.num + 5) * 2 + 1) * sizeof(char *)))) |
234 | DIE("no memory"); | 284 | DIE("no memory"); |
235 | spdy_headers.nv[0] = ":method"; spdy_headers.nv[1] = "GET"; | 285 | spdy_headers.nv[0] = ":method"; spdy_headers.nv[1] = method; |
236 | spdy_headers.nv[2] = ":path"; spdy_headers.nv[3] = proxy->uri->path_and_more; | 286 | spdy_headers.nv[2] = ":path"; spdy_headers.nv[3] = proxy->uri->path_and_more; |
237 | spdy_headers.nv[4] = ":version"; spdy_headers.nv[5] = (char *)version; | 287 | spdy_headers.nv[4] = ":version"; spdy_headers.nv[5] = (char *)version; |
238 | spdy_headers.nv[6] = ":scheme"; spdy_headers.nv[7] = proxy->uri->scheme; | 288 | spdy_headers.nv[6] = ":scheme"; spdy_headers.nv[7] = proxy->uri->scheme; |
@@ -248,7 +298,7 @@ http_cb_request (void *cls, | |||
248 | if(NULL == spdy_headers.nv[9]) | 298 | if(NULL == spdy_headers.nv[9]) |
249 | spdy_headers.nv[9] = proxy->uri->host_and_port; | 299 | spdy_headers.nv[9] = proxy->uri->host_and_port; |
250 | 300 | ||
251 | if(0 != spdy_request(spdy_headers.nv, proxy)) | 301 | if(0 != spdy_request(spdy_headers.nv, proxy, with_body)) |
252 | { | 302 | { |
253 | free(spdy_headers.nv); | 303 | free(spdy_headers.nv); |
254 | free_proxy(proxy); | 304 | free_proxy(proxy); |