Skip to content

Commit

Permalink
Merge pull request #153 from bixuehujin/improve_http
Browse files Browse the repository at this point in the history
Improvements for http protocol
  • Loading branch information
matyhtf committed Dec 22, 2014
2 parents f37e784 + 812b39e commit 0940a1e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/Http.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/network/ReactorThread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 6 additions & 1 deletion src/protocol/Http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -155,7 +160,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;
}
Expand Down
5 changes: 3 additions & 2 deletions swoole_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 0940a1e

Please sign in to comment.