Skip to content

Commit fe317d6

Browse files
committed
add upgrade key
1 parent db83129 commit fe317d6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

php_uv.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,11 @@ static int on_url_cb(http_parser *p, const char *at, size_t len)
23452345
return 0;
23462346
}
23472347

2348+
static int on_status_cb(http_parser *p, const char *at, size_t len)
2349+
{
2350+
return 0;
2351+
}
2352+
23482353
char *php_uv_strtoupper(char *s, size_t len)
23492354
{
23502355
unsigned char *c, *e;
@@ -6326,11 +6331,11 @@ PHP_FUNCTION(uv_http_parser_init)
63266331
ctx->settings.on_header_field = header_field_cb;
63276332
ctx->settings.on_header_value = header_value_cb;
63286333
ctx->settings.on_url = on_url_cb;
6334+
ctx->settings.on_status = on_status_cb;
63296335
ctx->settings.on_body = on_body_cb;
63306336
ctx->settings.on_headers_complete = on_headers_complete;
63316337
ctx->settings.on_message_complete = on_message_complete;
63326338

6333-
63346339
ZEND_REGISTER_RESOURCE(return_value, ctx, uv_httpparser_handle);
63356340
}
63366341

@@ -6342,6 +6347,7 @@ PHP_FUNCTION(uv_http_parser_execute)
63426347
php_http_parser_context *context;
63436348
char *body;
63446349
int body_len;
6350+
size_t nparsed = 0;
63456351

63466352
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
63476353
"rs/a",&z_parser, &body, &body_len, &result) == FAILURE) {
@@ -6356,17 +6362,24 @@ PHP_FUNCTION(uv_http_parser_execute)
63566362
}
63576363

63586364
context->parser.data = context;
6359-
http_parser_execute(&context->parser, &context->settings, body, body_len);
6365+
nparsed = http_parser_execute(&context->parser, &context->settings, body, body_len);
63606366

63616367
if (result) {
63626368
zval_dtor(result);
63636369
}
6370+
6371+
if (nparsed != body_len) {
6372+
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "parse failed.");
6373+
RETURN_FALSE;
6374+
}
6375+
63646376
ZVAL_ZVAL(result, context->data, 1, 0);
63656377
if (context->is_response == 0) {
63666378
add_assoc_string(result, "REQUEST_METHOD", (char*)http_method_str(context->parser.method), 1);
63676379
} else {
63686380
add_assoc_long(result, "STATUS_CODE", (long)context->parser.status_code);
63696381
}
6382+
add_assoc_long(result, "UPGRADE", (long)context->parser.upgrade);
63706383

63716384
MAKE_STD_ZVAL(headers);
63726385
ZVAL_ZVAL(headers, context->headers, 1, 0);

0 commit comments

Comments
 (0)