From ce3be4994778e794f7bf7860f85bf0bb2e9e5eb6 Mon Sep 17 00:00:00 2001 From: Jin Hu Date: Mon, 22 Dec 2014 00:25:53 +0800 Subject: [PATCH 1/2] Fixed header_length not computed correctly --- src/protocol/Http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocol/Http.c b/src/protocol/Http.c index bcfdde876cf..14e85da7d48 100644 --- a/src/protocol/Http.c +++ b/src/protocol/Http.c @@ -155,7 +155,7 @@ int swHttpRequest_get_content_length(swHttpRequest *request) { if (memcmp(p + 2, SW_STRL("\r\n") - 1) == 0) { - request->header_length = p - buffer->str + request->offset - 1; + request->header_length = p - buffer->str + sizeof("\r\n\r\n") - 1; buffer->offset = request->header_length; return SW_OK; } From 812b39e6ca21022166b3adb83447db554ad8918c Mon Sep 17 00:00:00 2001 From: Jin Hu Date: Mon, 22 Dec 2014 00:41:29 +0800 Subject: [PATCH 2/2] Added PATCH http verb support --- include/Http.h | 2 +- src/network/ReactorThread.c | 2 +- src/protocol/Http.c | 5 +++++ swoole_http.c | 5 +++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/Http.h b/include/Http.h index 9e344bf0bfb..a59a389c743 100644 --- a/include/Http.h +++ b/include/Http.h @@ -27,7 +27,7 @@ extern "C" enum http_method { - HTTP_DELETE = 1, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, + HTTP_DELETE = 1, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, /* pathological */ HTTP_CONNECT, HTTP_OPTIONS, HTTP_TRACE, /* webdav */ diff --git a/src/network/ReactorThread.c b/src/network/ReactorThread.c index c125d162948..7c4372b5d2a 100644 --- a/src/network/ReactorThread.c +++ b/src/network/ReactorThread.c @@ -1115,7 +1115,7 @@ int swReactorThread_onReceive_http_request(swReactor *reactor, swEvent *event) } } //POST PUT - else if(request->method == HTTP_POST || request->method == HTTP_PUT) + else if(request->method == HTTP_POST || request->method == HTTP_PUT || request->method == HTTP_PATCH) { if (request->content_length == 0) { diff --git a/src/protocol/Http.c b/src/protocol/Http.c index 14e85da7d48..413767531ea 100644 --- a/src/protocol/Http.c +++ b/src/protocol/Http.c @@ -46,6 +46,11 @@ int swHttpRequest_get_protocol(swHttpRequest *request) request->offset = 4; buf += 4; } + else if (memcmp(buf, "PATCH", 5) == 0) { + request->method = HTTP_PATCH; + request->offset = 6; + buf += 6; + } else if (memcmp(buf, "DELETE", 6) == 0) { request->method = HTTP_DELETE; diff --git a/swoole_http.c b/swoole_http.c index 6935982c970..582fb58eee1 100644 --- a/swoole_http.c +++ b/swoole_http.c @@ -307,7 +307,8 @@ static int http_request_on_header_value(php_http_parser *parser, const char *at, zval *header = zend_read_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("header"), 1 TSRMLS_CC); add_assoc_stringl_ex(header, header_name, client->current_header_name_len + 1, (char *) at, length, 1); } - else if (parser->method == PHP_HTTP_POST && memcmp(header_name, ZEND_STRL("content-type")) == 0 + else if ((parser->method == PHP_HTTP_POST || parser->method == PHP_HTTP_PUT || parser->method == PHP_HTTP_PATCH) + && memcmp(header_name, ZEND_STRL("content-type")) == 0 && memcmp(at, ZEND_STRL("application/x-www-form-urlencoded")) == 0) { client->request.post_form_urlencoded = 1; @@ -1138,7 +1139,7 @@ PHP_METHOD(swoole_http_response, end) if(client->request.method == PHP_HTTP_OPTIONS) { - swString_append_ptr(response, ZEND_STRL("Allow: GET, POST, PUT, DELETE, HEAD, OPTIONS\r\nContent-Length: 0\r\n")); + swString_append_ptr(response, ZEND_STRL("Allow: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS\r\nContent-Length: 0\r\n")); } else {