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