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