@@ -128,6 +128,7 @@ static void _set_content_type(const char *nonnull content_type)
128128static  void  _set_output (const  char  * nonnull  output , size_t  length )
129129{
130130    size_t  written  =  php_output_write (output , length );
131+     mlog_g (dd_log_debug , "php_output_write() returned %zu" , written );
131132    if  (written  !=  length ) {
132133        mlog (dd_log_info , "could not write full response (written: %zu)" ,
133134            written );
@@ -146,8 +147,8 @@ static dd_response_type _get_response_type_from_accept_header(
146147        dd_php_get_string_elem_cstr (_server , LSTRARG ("HTTP_ACCEPT" ));
147148    if  (!accept_zstr ) {
148149        mlog (dd_log_info ,
149-             "Could not find Accept header, using default content-type" );
150-         goto  exit ;
150+             "Could not find Accept header, using default content-type (json) " );
151+         return   response_type_json ;
151152    }
152153
153154    const  char  * accept_end  =  ZSTR_VAL (accept_zstr ) +  ZSTR_LEN (accept_zstr );
@@ -172,7 +173,7 @@ static dd_response_type _get_response_type_from_accept_header(
172173        return  response_type_html ;
173174    }
174175
175- exit : 
176+      mlog_g ( dd_log_debug ,  "No recognized accept header, defaulting to json" ); 
176177    return  response_type_json ;
177178}
178179
@@ -214,13 +215,17 @@ void dd_request_abort_redirect()
214215    }
215216
216217    if  (!_abort_prelude ()) {
218+         mlog (dd_log_debug , "_abort_prelude has failed" );
217219        return ;
218220    }
219221
220222    char  * line ;
221223    uint  line_len  =  (uint )spprintf (
222224        & line , 0 , "Location: %s" , ZSTR_VAL (_redirection_location ));
223225
226+     mlog_g (dd_log_debug , "Will forward to %s with status %d" ,
227+         ZSTR_VAL (_redirection_location ), _redirection_response_code );
228+ 
224229    SG (sapi_headers ).http_response_code  =  _redirection_response_code ;
225230    int  res  =  sapi_header_op (SAPI_HEADER_REPLACE ,
226231        & (sapi_header_line ){.line  =  line , .line_len  =  line_len });
@@ -232,7 +237,7 @@ void dd_request_abort_redirect()
232237    efree (line );
233238
234239    if  (sapi_flush () ==  SUCCESS ) {
235-         mlog (dd_log_debug , "Successful call to sapi_flush()" );
240+         mlog_g (dd_log_debug , "Successful call to sapi_flush()" );
236241    } else  {
237242        mlog (dd_log_warning , "Call to sapi_flush() failed" );
238243    }
@@ -299,6 +304,7 @@ void _request_abort_static_page(int response_code, int type)
299304    }
300305
301306    if  (!_abort_prelude ()) {
307+         mlog (dd_log_debug , "_abort_prelude has failed" );
302308        zend_string_release (body );
303309        return ;
304310    }
@@ -434,8 +440,10 @@ static void _suppress_error_reporting(void);
434440ATTR_FORMAT (1 , 2 )
435441static  void  _emit_error (const  char  * format , ...)
436442{
437-     va_list  args ;
443+     mlog_g (dd_log_debug , "_emit_error() called: during_request_startup: %d" ,
444+         PG (during_request_startup ));
438445
446+     va_list  args ;
439447    va_start (args , format );
440448    if  (PG (during_request_startup )) {
441449        /* if emitting error during startup, RSHUTDOWN will not run (except fpm) 
@@ -615,6 +623,7 @@ static zend_string *nonnull _get_json_blocking_template()
615623            return  _empty_zstr ;
616624        }
617625        if  (ZSTR_LEN (body_error_json ) ==  0 ) {
626+             zend_string_release (body_error_json );
618627            return  _body_error_json_def ;
619628        }
620629
@@ -635,6 +644,7 @@ static zend_string *nonnull _get_html_blocking_template()
635644            return  _empty_zstr ;
636645        }
637646        if  (ZSTR_LEN (body_error_html ) ==  0 ) {
647+             zend_string_release (body_error_html );
638648            return  _body_error_html_def ;
639649        }
640650
0 commit comments