@@ -342,16 +342,15 @@ bool swoole_http_token_list_contains_value(const char *at, size_t length, const
342
342
static int http_request_on_header_value (swoole_http_parser *parser, const char *at, size_t length) {
343
343
HttpContext *ctx = (HttpContext *) parser->data ;
344
344
zval *zheader = ctx->request .zheader ;
345
+ char *header_name = ctx->current_header_name ;
345
346
size_t header_len = ctx->current_header_name_len ;
346
- char header_name[header_len];
347
- zend_str_tolower_copy (header_name, ctx->current_header_name , header_len);
348
347
349
- if (ctx->parse_cookie && SW_STREQ (header_name, header_len, " cookie" )) {
348
+ if (ctx->parse_cookie && SW_STRCASEEQ (header_name, header_len, " cookie" )) {
350
349
zval *zcookie = swoole_http_init_and_read_property (
351
350
swoole_http_request_ce, ctx->request .zobject , &ctx->request .zcookie , SW_ZSTR_KNOWN (SW_ZEND_STR_COOKIE));
352
351
swoole_http_parse_cookie (zcookie, at, length);
353
352
return 0 ;
354
- } else if (SW_STREQ (header_name, header_len, " upgrade" ) &&
353
+ } else if (SW_STRCASEEQ (header_name, header_len, " upgrade" ) &&
355
354
swoole_http_token_list_contains_value (at, length, " websocket" )) {
356
355
ctx->websocket = 1 ;
357
356
if (ctx->co_socket ) {
@@ -372,7 +371,7 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char *
372
371
}
373
372
} else if ((parser->method == PHP_HTTP_POST || parser->method == PHP_HTTP_PUT ||
374
373
parser->method == PHP_HTTP_DELETE || parser->method == PHP_HTTP_PATCH) &&
375
- SW_STREQ (header_name, header_len, " content-type" )) {
374
+ SW_STRCASEEQ (header_name, header_len, " content-type" )) {
376
375
if (SW_STR_ISTARTS_WITH (at, length, " application/x-www-form-urlencoded" )) {
377
376
ctx->request .post_form_urlencoded = 1 ;
378
377
} else if (SW_STR_ISTARTS_WITH (at, length, " multipart/form-data" )) {
@@ -387,11 +386,11 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char *
387
386
}
388
387
}
389
388
#ifdef SW_HAVE_COMPRESSION
390
- else if (ctx->enable_compression && SW_STREQ (header_name, header_len, " accept-encoding" )) {
389
+ else if (ctx->enable_compression && SW_STRCASEEQ (header_name, header_len, " accept-encoding" )) {
391
390
ctx->set_compression_method (at, length);
392
391
}
393
392
#endif
394
- else if (SW_STREQ (header_name, header_len, " transfer-encoding" ) && SW_STR_ISTARTS_WITH (at, length, " chunked" )) {
393
+ else if (SW_STRCASEEQ (header_name, header_len, " transfer-encoding" ) && SW_STR_ISTARTS_WITH (at, length, " chunked" )) {
395
394
ctx->recv_chunked = 1 ;
396
395
}
397
396
@@ -402,24 +401,27 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char *
402
401
/* *
403
402
* some common request header key
404
403
*/
405
- if (SW_STREQ (header_name, header_len, " host" )) {
404
+ if (SW_STRCASEEQ (header_name, header_len, " host" )) {
406
405
zend_hash_update (Z_ARR_P (zheader), SW_ZSTR_KNOWN (SW_ZEND_STR_HOST), &tmp);
407
- } else if (SW_STREQ (header_name, header_len, " user-agent" )) {
406
+ } else if (SW_STRCASEEQ (header_name, header_len, " user-agent" )) {
408
407
zend_hash_update (Z_ARR_P (zheader), SW_ZSTR_KNOWN (SW_ZEND_STR_USER_AGENT), &tmp);
409
- } else if (SW_STREQ (header_name, header_len, " accept" )) {
408
+ } else if (SW_STRCASEEQ (header_name, header_len, " accept" )) {
410
409
zend_hash_update (Z_ARR_P (zheader), SW_ZSTR_KNOWN (SW_ZEND_STR_ACCEPT), &tmp);
411
- } else if (SW_STREQ (header_name, header_len, " content-type" )) {
410
+ } else if (SW_STRCASEEQ (header_name, header_len, " content-type" )) {
412
411
zend_hash_update (Z_ARR_P (zheader), SW_ZSTR_KNOWN (SW_ZEND_STR_CONTENT_TYPE), &tmp);
413
- } else if (SW_STREQ (header_name, header_len, " content-length" )) {
412
+ } else if (SW_STRCASEEQ (header_name, header_len, " content-length" )) {
414
413
zend_hash_update (Z_ARR_P (zheader), SW_ZSTR_KNOWN (SW_ZEND_STR_CONTENT_LENGTH), &tmp);
415
- } else if (SW_STREQ (header_name, header_len, " authorization" )) {
414
+ } else if (SW_STRCASEEQ (header_name, header_len, " authorization" )) {
416
415
zend_hash_update (Z_ARR_P (zheader), SW_ZSTR_KNOWN (SW_ZEND_STR_AUTHORIZATION), &tmp);
417
- } else if (SW_STREQ (header_name, header_len, " connection" )) {
416
+ } else if (SW_STRCASEEQ (header_name, header_len, " connection" )) {
418
417
zend_hash_update (Z_ARR_P (zheader), SW_ZSTR_KNOWN (SW_ZEND_STR_CONNECTION), &tmp);
419
- } else if (SW_STREQ (header_name, header_len, " accept-encoding" )) {
418
+ } else if (SW_STRCASEEQ (header_name, header_len, " accept-encoding" )) {
420
419
zend_hash_update (Z_ARR_P (zheader), SW_ZSTR_KNOWN (SW_ZEND_STR_ACCEPT_ENCODING), &tmp);
421
420
} else {
422
- zend_hash_str_update (Z_ARR_P (zheader), header_name, header_len, &tmp);
421
+ char *new_header_name = estrndup (header_name, header_len);
422
+ zend_str_tolower_copy (new_header_name, header_name, header_len);
423
+ zend_hash_str_update (Z_ARR_P (zheader), new_header_name, header_len, &tmp);
424
+ efree (new_header_name);
423
425
}
424
426
425
427
return 0 ;
0 commit comments