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

Function ap_send_error_response

modules/http/http_protocol.c:1376–1542  ·  view source on GitHub ↗

We should have named this send_canned_response, since it is used for any * response that can be generated by the server from the request record. * This includes all 204 (no content), 3xx (redirect), 4xx (client error), * and 5xx (server error) messages that have not been redirected to another * handler via the ErrorDocument feature. */

Source from the content-addressed store, hash-verified

1374 * handler via the ErrorDocument feature.
1375 */
1376AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error)
1377{
1378 int status = r->status;
1379 int idx = ap_index_of_response(status);
1380 char *custom_response;
1381 const char *location = apr_table_get(r->headers_out, "Location");
1382
1383 /* At this point, we are starting the response over, so we have to reset
1384 * this value.
1385 */
1386 r->eos_sent = 0;
1387
1388 /* and we need to get rid of any RESOURCE filters that might be lurking
1389 * around, thinking they are in the middle of the original request
1390 */
1391
1392 r->output_filters = r->proto_output_filters;
1393
1394 ap_run_insert_error_filter(r);
1395
1396 /* We need to special-case the handling of 204 and 304 responses,
1397 * since they have specific HTTP requirements and do not include a
1398 * message body. Note that being assbackwards here is not an option.
1399 */
1400 if (AP_STATUS_IS_HEADER_ONLY(status)) {
1401 ap_finalize_request_protocol(r);
1402 return;
1403 }
1404
1405 /*
1406 * It's possible that the Location field might be in r->err_headers_out
1407 * instead of r->headers_out; use the latter if possible, else the
1408 * former.
1409 */
1410 if (location == NULL) {
1411 location = apr_table_get(r->err_headers_out, "Location");
1412 }
1413
1414 if (!r->assbackwards) {
1415 apr_table_t *tmp = r->headers_out;
1416
1417 /* For all HTTP/1.x responses for which we generate the message,
1418 * we need to avoid inheriting the "normal status" header fields
1419 * that may have been set by the request handler before the
1420 * error or redirect, except for Location on external redirects.
1421 */
1422 r->headers_out = r->err_headers_out;
1423 r->err_headers_out = tmp;
1424 apr_table_clear(r->err_headers_out);
1425
1426 if (ap_is_HTTP_REDIRECT(status) || (status == HTTP_CREATED)) {
1427 if ((location != NULL) && *location) {
1428 apr_table_setn(r->headers_out, "Location", location);
1429 }
1430 else {
1431 location = ""; /* avoids coredump when printing, below */
1432 }
1433 }

Callers 1

ap_die_rFunction · 0.85

Calls 10

ap_index_of_responseFunction · 0.85
ap_set_content_type_exFunction · 0.85
make_allowFunction · 0.85
ap_response_code_stringFunction · 0.85
ap_rputsFunction · 0.85
ap_rvputs_proto_in_asciiFunction · 0.85
get_canned_error_stringFunction · 0.85
ap_psignatureFunction · 0.85

Tested by

no test coverage detected