@@ -347,18 +347,33 @@ static void append_http_status_line(smart_str *buffer, int protocol_version, int
347
347
smart_str_appendl_ex (buffer , "\r\n" , 2 , persistent );
348
348
} /* }}} */
349
349
350
- static void append_essential_headers (smart_str * buffer , php_cli_server_client * client , bool persistent ) /* {{{ */
350
+ static void append_essential_headers (smart_str * buffer , php_cli_server_client * client , bool persistent , sapi_headers_struct * sapi_headers ) /* {{{ */
351
351
{
352
352
zval * val ;
353
353
struct timeval tv = {0 };
354
+ bool append_date_header = true;
355
+
356
+ if (sapi_headers != NULL ) {
357
+ zend_llist_position pos ;
358
+ sapi_header_struct * h = (sapi_header_struct * )zend_llist_get_first_ex (& sapi_headers -> headers , & pos );
359
+ while (h ) {
360
+ if (h -> header_len > strlen ("Date:" )) {
361
+ if (strncasecmp (h -> header , "Date:" , strlen ("Date:" )) == 0 ) {
362
+ append_date_header = false;
363
+ break ;
364
+ }
365
+ }
366
+ h = (sapi_header_struct * )zend_llist_get_next_ex (& sapi_headers -> headers , & pos );
367
+ }
368
+ }
354
369
355
370
if (NULL != (val = zend_hash_str_find (& client -> request .headers , "host" , sizeof ("host" )- 1 ))) {
356
371
smart_str_appends_ex (buffer , "Host: " , persistent );
357
372
smart_str_append_ex (buffer , Z_STR_P (val ), persistent );
358
373
smart_str_appends_ex (buffer , "\r\n" , persistent );
359
374
}
360
375
361
- if (!gettimeofday (& tv , NULL )) {
376
+ if (append_date_header && !gettimeofday (& tv , NULL )) {
362
377
zend_string * dt = php_format_date ("D, d M Y H:i:s" , sizeof ("D, d M Y H:i:s" ) - 1 , tv .tv_sec , 0 );
363
378
smart_str_appends_ex (buffer , "Date: " , persistent );
364
379
smart_str_append_ex (buffer , dt , persistent );
@@ -542,7 +557,7 @@ static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers) /* {{
542
557
append_http_status_line (& buffer , client -> request .protocol_version , SG (sapi_headers ).http_response_code , 0 );
543
558
}
544
559
545
- append_essential_headers (& buffer , client , 0 );
560
+ append_essential_headers (& buffer , client , 0 , sapi_headers );
546
561
547
562
h = (sapi_header_struct * )zend_llist_get_first_ex (& sapi_headers -> headers , & pos );
548
563
while (h ) {
@@ -2039,7 +2054,7 @@ static zend_result php_cli_server_send_error_page(php_cli_server *server, php_cl
2039
2054
/* out of memory */
2040
2055
goto fail ;
2041
2056
}
2042
- append_essential_headers (& buffer , client , 1 );
2057
+ append_essential_headers (& buffer , client , 1 , NULL );
2043
2058
smart_str_appends_ex (& buffer , "Content-Type: text/html; charset=UTF-8\r\n" , 1 );
2044
2059
smart_str_appends_ex (& buffer , "Content-Length: " , 1 );
2045
2060
smart_str_append_unsigned_ex (& buffer , php_cli_server_buffer_size (& client -> content_sender .buffer ), 1 );
@@ -2155,7 +2170,7 @@ static zend_result php_cli_server_begin_send_static(php_cli_server *server, php_
2155
2170
php_cli_server_log_response (client , 500 , NULL );
2156
2171
return FAILURE ;
2157
2172
}
2158
- append_essential_headers (& buffer , client , 1 );
2173
+ append_essential_headers (& buffer , client , 1 , NULL );
2159
2174
if (mime_type ) {
2160
2175
smart_str_appendl_ex (& buffer , "Content-Type: " , sizeof ("Content-Type: " ) - 1 , 1 );
2161
2176
smart_str_appends_ex (& buffer , mime_type , 1 );
0 commit comments