@@ -348,18 +348,33 @@ static void append_http_status_line(smart_str *buffer, int protocol_version, int
348
348
smart_str_appendl_ex (buffer , "\r\n" , 2 , persistent );
349
349
} /* }}} */
350
350
351
- static void append_essential_headers (smart_str * buffer , php_cli_server_client * client , int persistent ) /* {{{ */
351
+ static void append_essential_headers (smart_str * buffer , php_cli_server_client * client , int persistent , sapi_headers_struct * sapi_headers ) /* {{{ */
352
352
{
353
353
char * val ;
354
354
struct timeval tv = {0 };
355
+ bool append_date_header = true;
356
+
357
+ if (sapi_headers != NULL ) {
358
+ zend_llist_position pos ;
359
+ sapi_header_struct * h = (sapi_header_struct * )zend_llist_get_first_ex (& sapi_headers -> headers , & pos );
360
+ while (h ) {
361
+ if (h -> header_len > strlen ("Date:" )) {
362
+ if (strncasecmp (h -> header , "Date:" , strlen ("Date:" )) == 0 ) {
363
+ append_date_header = false;
364
+ break ;
365
+ }
366
+ }
367
+ h = (sapi_header_struct * )zend_llist_get_next_ex (& sapi_headers -> headers , & pos );
368
+ }
369
+ }
355
370
356
371
if (NULL != (val = zend_hash_str_find_ptr (& client -> request .headers , "host" , sizeof ("host" )- 1 ))) {
357
372
smart_str_appends_ex (buffer , "Host: " , persistent );
358
373
smart_str_appends_ex (buffer , val , persistent );
359
374
smart_str_appends_ex (buffer , "\r\n" , persistent );
360
375
}
361
376
362
- if (!gettimeofday (& tv , NULL )) {
377
+ if (append_date_header && !gettimeofday (& tv , NULL )) {
363
378
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 );
364
379
smart_str_appends_ex (buffer , "Date: " , persistent );
365
380
smart_str_appends_ex (buffer , dt -> val , persistent );
@@ -552,7 +567,7 @@ static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers) /* {{
552
567
append_http_status_line (& buffer , client -> request .protocol_version , SG (sapi_headers ).http_response_code , 0 );
553
568
}
554
569
555
- append_essential_headers (& buffer , client , 0 );
570
+ append_essential_headers (& buffer , client , 0 , sapi_headers );
556
571
557
572
h = (sapi_header_struct * )zend_llist_get_first_ex (& sapi_headers -> headers , & pos );
558
573
while (h ) {
@@ -1997,7 +2012,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server
1997
2012
/* out of memory */
1998
2013
goto fail ;
1999
2014
}
2000
- append_essential_headers (& buffer , client , 1 );
2015
+ append_essential_headers (& buffer , client , 1 , NULL );
2001
2016
smart_str_appends_ex (& buffer , "Content-Type: text/html; charset=UTF-8\r\n" , 1 );
2002
2017
smart_str_appends_ex (& buffer , "Content-Length: " , 1 );
2003
2018
smart_str_append_unsigned_ex (& buffer , php_cli_server_buffer_size (& client -> content_sender .buffer ), 1 );
@@ -2093,7 +2108,7 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv
2093
2108
php_cli_server_log_response (client , 500 , NULL );
2094
2109
return FAILURE ;
2095
2110
}
2096
- append_essential_headers (& buffer , client , 1 );
2111
+ append_essential_headers (& buffer , client , 1 , NULL );
2097
2112
if (mime_type ) {
2098
2113
smart_str_appendl_ex (& buffer , "Content-Type: " , sizeof ("Content-Type: " ) - 1 , 1 );
2099
2114
smart_str_appends_ex (& buffer , mime_type , 1 );
0 commit comments