Skip to content

Commit 0940a1e

Browse files
committed
Merge pull request #153 from bixuehujin/improve_http
Improvements for http protocol
2 parents f37e784 + 812b39e commit 0940a1e

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

include/Http.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C"
2727

2828
enum http_method
2929
{
30-
HTTP_DELETE = 1, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT,
30+
HTTP_DELETE = 1, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH,
3131
/* pathological */
3232
HTTP_CONNECT, HTTP_OPTIONS, HTTP_TRACE,
3333
/* webdav */

src/network/ReactorThread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ int swReactorThread_onReceive_http_request(swReactor *reactor, swEvent *event)
11151115
}
11161116
}
11171117
//POST PUT
1118-
else if(request->method == HTTP_POST || request->method == HTTP_PUT)
1118+
else if(request->method == HTTP_POST || request->method == HTTP_PUT || request->method == HTTP_PATCH)
11191119
{
11201120
if (request->content_length == 0)
11211121
{

src/protocol/Http.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ int swHttpRequest_get_protocol(swHttpRequest *request)
4646
request->offset = 4;
4747
buf += 4;
4848
}
49+
else if (memcmp(buf, "PATCH", 5) == 0) {
50+
request->method = HTTP_PATCH;
51+
request->offset = 6;
52+
buf += 6;
53+
}
4954
else if (memcmp(buf, "DELETE", 6) == 0)
5055
{
5156
request->method = HTTP_DELETE;
@@ -155,7 +160,7 @@ int swHttpRequest_get_content_length(swHttpRequest *request)
155160
{
156161
if (memcmp(p + 2, SW_STRL("\r\n") - 1) == 0)
157162
{
158-
request->header_length = p - buffer->str + request->offset - 1;
163+
request->header_length = p - buffer->str + sizeof("\r\n\r\n") - 1;
159164
buffer->offset = request->header_length;
160165
return SW_OK;
161166
}

swoole_http.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ static int http_request_on_header_value(php_http_parser *parser, const char *at,
307307
zval *header = zend_read_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("header"), 1 TSRMLS_CC);
308308
add_assoc_stringl_ex(header, header_name, client->current_header_name_len + 1, (char *) at, length, 1);
309309
}
310-
else if (parser->method == PHP_HTTP_POST && memcmp(header_name, ZEND_STRL("content-type")) == 0
310+
else if ((parser->method == PHP_HTTP_POST || parser->method == PHP_HTTP_PUT || parser->method == PHP_HTTP_PATCH)
311+
&& memcmp(header_name, ZEND_STRL("content-type")) == 0
311312
&& memcmp(at, ZEND_STRL("application/x-www-form-urlencoded")) == 0)
312313
{
313314
client->request.post_form_urlencoded = 1;
@@ -1138,7 +1139,7 @@ PHP_METHOD(swoole_http_response, end)
11381139

11391140
if(client->request.method == PHP_HTTP_OPTIONS)
11401141
{
1141-
swString_append_ptr(response, ZEND_STRL("Allow: GET, POST, PUT, DELETE, HEAD, OPTIONS\r\nContent-Length: 0\r\n"));
1142+
swString_append_ptr(response, ZEND_STRL("Allow: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS\r\nContent-Length: 0\r\n"));
11421143
}
11431144
else
11441145
{

0 commit comments

Comments
 (0)