From ef6e478b7831e43f475c47920c52a278e5359000 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Tue, 15 Nov 2016 09:06:55 +0000 Subject: [PATCH] http: Allow unknown response status' lines returned in the form of: HTTP/x.x xxx Status xxx git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1769760 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ include/http_protocol.h | 11 +++++++++++ modules/http/http_protocol.c | 37 +++++++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index cf11906193..6a984cf964 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) http: Allow unknown response status' lines returned in the form of + "HTTP/x.x xxx Status xxx". [Yann Ylavic] + *) core: Add configuration section to allow any file on disk to be used as a conditional. [Edward Lu, Eric Covener] diff --git a/include/http_protocol.h b/include/http_protocol.h index 77c9766b60..63c3b0cc65 100644 --- a/include/http_protocol.h +++ b/include/http_protocol.h @@ -473,6 +473,17 @@ AP_DECLARE(int) ap_index_of_response(int status); */ AP_DECLARE(const char *) ap_get_status_line(int status); +/** + * Return the Status-Line for a given status code (excluding the + * HTTP-Version field). If an invalid status code is passed, + * "500 Internal Server Error" will be returned, whereas an unknown + * status will be returned like "xxx Status xxx". + * @param p The pool to allocate from when status is unknown + * @param status The HTTP status code + * @return The Status-Line + */ +AP_DECLARE(const char *) ap_get_status_line_ex(apr_pool_t *p, int status); + /* Reading a block of data from the client connection (e.g., POST arg) */ /** diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index b590fa5f29..d7b995d0d4 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -801,14 +801,17 @@ AP_DECLARE(const char *) ap_method_name_of(apr_pool_t *p, int methnum) * from status_lines[shortcut[i]] to status_lines[shortcut[i+1]-1]; * or use NULL to fill the gaps. */ -AP_DECLARE(int) ap_index_of_response(int status) +static int index_of_response(int status) { - static int shortcut[6] = {0, LEVEL_200, LEVEL_300, LEVEL_400, - LEVEL_500, RESPONSE_CODES}; + static int shortcut[6] = {0, LEVEL_200, LEVEL_300, LEVEL_400, LEVEL_500, + RESPONSE_CODES}; int i, pos; - if (status < 100) { /* Below 100 is illegal for HTTP status */ - return LEVEL_500; + if (status < 100) { /* Below 100 is illegal for HTTP status */ + return -1; + } + if (status > 999) { /* Above 999 is also illegal for HTTP status */ + return -1; } for (i = 0; i < 5; i++) { @@ -819,11 +822,31 @@ AP_DECLARE(int) ap_index_of_response(int status) return pos; } else { - return LEVEL_500; /* status unknown (falls in gap) */ + break; } } } - return LEVEL_500; /* 600 or above is also illegal */ + return 0; /* Status unknown (falls in gap) or above 600 */ +} + +AP_DECLARE(int) ap_index_of_response(int status) +{ + int index = index_of_response(status); + return (index <= 0) ? LEVEL_500 : index; +} + +AP_DECLARE(const char *) ap_get_status_line_ex(apr_pool_t *p, int status) +{ + int index = index_of_response(status); + if (index < 0) { + return status_lines[LEVEL_500]; + } + else if (index == 0) { + return apr_psprintf(p, "%i Status %i", status, status); + } + else { + return status_lines[index]; + } } AP_DECLARE(const char *) ap_get_status_line(int status) -- 2.50.1