MCPcopy Create free account
hub / github.com/apache/httpd / cgi_handle_response

Function cgi_handle_response

modules/generators/cgi_common.h:420–552  ·  view source on GitHub ↗

Handle the CGI response output, having set up the brigade with the * CGI or PIPE bucket as appropriate. */

Source from the content-addressed store, hash-verified

418/* Handle the CGI response output, having set up the brigade with the
419 * CGI or PIPE bucket as appropriate. */
420static int cgi_handle_response(request_rec *r, int nph, apr_bucket_brigade *bb,
421 apr_interval_time_t timeout, cgi_server_conf *conf,
422 char *logdata, apr_file_t *script_err)
423{
424 apr_status_t rv;
425
426 /* Handle script return... */
427 if (!nph) {
428 const char *location;
429 char sbuf[MAX_STRING_LEN];
430 int ret;
431
432 ret = ap_scan_script_header_err_brigade_ex(r, bb, sbuf,
433 APLOG_MODULE_INDEX);
434
435 /* xCGI has its own body framing mechanism which we don't
436 * match against any provided Content-Length, so let the
437 * core determine C-L vs T-E based on what's actually sent.
438 */
439 if (!apr_table_get(r->subprocess_env, AP_TRUST_CGILIKE_CL_ENVVAR))
440 apr_table_unset(r->headers_out, "Content-Length");
441 apr_table_unset(r->headers_out, "Transfer-Encoding");
442
443 if (ret != OK) {
444 /* In the case of a timeout reading script output, clear
445 * the brigade to avoid a second attempt to read the
446 * output. */
447 if (ret == HTTP_GATEWAY_TIME_OUT) {
448 apr_brigade_cleanup(bb);
449 }
450
451 ret = log_script(r, conf, ret, logdata, sbuf, bb, script_err);
452
453 /*
454 * ret could be HTTP_NOT_MODIFIED in the case that the CGI script
455 * does not set an explicit status and ap_meets_conditions, which
456 * is called by ap_scan_script_header_err_brigade, detects that
457 * the conditions of the requests are met and the response is
458 * not modified.
459 * In this case set r->status and return OK in order to prevent
460 * running through the error processing stack as this would
461 * break with mod_cache, if the conditions had been set by
462 * mod_cache itself to validate a stale entity.
463 * BTW: We circumvent the error processing stack anyway if the
464 * CGI script set an explicit status code (whatever it is) and
465 * the only possible values for ret here are:
466 *
467 * HTTP_NOT_MODIFIED (set by ap_meets_conditions)
468 * HTTP_PRECONDITION_FAILED (set by ap_meets_conditions)
469 * HTTP_INTERNAL_SERVER_ERROR (if something went wrong during the
470 * processing of the response of the CGI script, e.g broken headers
471 * or a crashed CGI process).
472 */
473 if (ret == HTTP_NOT_MODIFIED) {
474 r->status = ret;
475 return OK;
476 }
477

Callers 2

cgid_handlerFunction · 0.85
cgi_handlerFunction · 0.85

Calls 6

discard_script_outputFunction · 0.85
log_script_errFunction · 0.85
ap_pass_brigadeFunction · 0.85
log_scriptFunction · 0.70

Tested by

no test coverage detected