@@ -106,6 +106,17 @@ static inline void strip_header(char *header_bag, char *lc_header_bag,
106
106
}
107
107
}
108
108
109
+ static zend_bool check_has_header (const char * headers , const char * header ) {
110
+ const char * s = headers ;
111
+ while ((s = strstr (s , header ))) {
112
+ if (s == headers || * (s - 1 ) == '\r' || * (s - 1 ) == '\n' || * (s - 1 ) == '\t' || * (s - 1 ) == ' ' ) {
113
+ return 1 ;
114
+ }
115
+ s ++ ;
116
+ }
117
+ return 0 ;
118
+ }
119
+
109
120
static php_stream * php_stream_url_wrap_http_ex (php_stream_wrapper * wrapper ,
110
121
const char * path , const char * mode , int options , zend_string * * opened_path ,
111
122
php_stream_context * context , int redirect_max , int flags ,
@@ -460,74 +471,26 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
460
471
strip_header (user_headers , t , "content-type:" );
461
472
}
462
473
463
- s = t ;
464
- while ((s = strstr (s , "user-agent:" ))) {
465
- if (s == t || * (s - 1 ) == '\r' || * (s - 1 ) == '\n' ||
466
- * (s - 1 ) == '\t' || * (s - 1 ) == ' ' ) {
467
- have_header |= HTTP_HEADER_USER_AGENT ;
468
- break ;
469
- }
470
- s ++ ;
474
+ if (check_has_header (t , "user-agent:" )) {
475
+ have_header |= HTTP_HEADER_USER_AGENT ;
471
476
}
472
-
473
- s = t ;
474
- while ((s = strstr (s , "host:" ))) {
475
- if (s == t || * (s - 1 ) == '\r' || * (s - 1 ) == '\n' ||
476
- * (s - 1 ) == '\t' || * (s - 1 ) == ' ' ) {
477
- have_header |= HTTP_HEADER_HOST ;
478
- break ;
479
- }
480
- s ++ ;
477
+ if (check_has_header (t , "host:" )) {
478
+ have_header |= HTTP_HEADER_HOST ;
481
479
}
482
-
483
- s = t ;
484
- while ((s = strstr (s , "from:" ))) {
485
- if (s == t || * (s - 1 ) == '\r' || * (s - 1 ) == '\n' ||
486
- * (s - 1 ) == '\t' || * (s - 1 ) == ' ' ) {
487
- have_header |= HTTP_HEADER_FROM ;
488
- break ;
489
- }
490
- s ++ ;
480
+ if (check_has_header (t , "from:" )) {
481
+ have_header |= HTTP_HEADER_FROM ;
491
482
}
492
-
493
- s = t ;
494
- while ((s = strstr (s , "authorization:" ))) {
495
- if (s == t || * (s - 1 ) == '\r' || * (s - 1 ) == '\n' ||
496
- * (s - 1 ) == '\t' || * (s - 1 ) == ' ' ) {
497
- have_header |= HTTP_HEADER_AUTH ;
498
- break ;
499
- }
500
- s ++ ;
483
+ if (check_has_header (t , "authorization:" )) {
484
+ have_header |= HTTP_HEADER_AUTH ;
501
485
}
502
-
503
- s = t ;
504
- while ((s = strstr (s , "content-length:" ))) {
505
- if (s == t || * (s - 1 ) == '\r' || * (s - 1 ) == '\n' ||
506
- * (s - 1 ) == '\t' || * (s - 1 ) == ' ' ) {
507
- have_header |= HTTP_HEADER_CONTENT_LENGTH ;
508
- break ;
509
- }
510
- s ++ ;
486
+ if (check_has_header (t , "content-length:" )) {
487
+ have_header |= HTTP_HEADER_CONTENT_LENGTH ;
511
488
}
512
-
513
- s = t ;
514
- while ((s = strstr (s , "content-type:" ))) {
515
- if (s == t || * (s - 1 ) == '\r' || * (s - 1 ) == '\n' ||
516
- * (s - 1 ) == '\t' || * (s - 1 ) == ' ' ) {
517
- have_header |= HTTP_HEADER_TYPE ;
518
- break ;
519
- }
520
- s ++ ;
489
+ if (check_has_header (t , "content-type:" )) {
490
+ have_header |= HTTP_HEADER_TYPE ;
521
491
}
522
-
523
- s = t ;
524
- while ((s = strstr (s , "connection:" ))) {
525
- if (s == t || * (s - 1 ) == '\r' || * (s - 1 ) == '\n' ||
526
- * (s - 1 ) == '\t' || * (s - 1 ) == ' ' ) {
527
- have_header |= HTTP_HEADER_CONNECTION ;
528
- break ;
529
- }
530
- s ++ ;
492
+ if (check_has_header (t , "connection:" )) {
493
+ have_header |= HTTP_HEADER_CONNECTION ;
531
494
}
532
495
533
496
/* remove Proxy-Authorization header */
0 commit comments