]> granicus.if.org Git - apache/commitdiff
http: Allow unknown response status' lines returned in the form of:
authorYann Ylavic <ylavic@apache.org>
Tue, 15 Nov 2016 09:06:55 +0000 (09:06 +0000)
committerYann Ylavic <ylavic@apache.org>
Tue, 15 Nov 2016 09:06:55 +0000 (09:06 +0000)
    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
include/http_protocol.h
modules/http/http_protocol.c

diff --git a/CHANGES b/CHANGES
index cf119061933562200f55796431b95f6bd36de6e3..6a984cf9642cd20f080b18e4aa7844ae54a51fe1 100644 (file)
--- 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 <IfFile> configuration section to allow any file on disk to be
      used as a conditional.  [Edward Lu, Eric Covener]
 
index 77c9766b60eec8cf2886c98d2449863009b23b45..63c3b0cc651a2d8d55eea671327f34f2ea3d4e24 100644 (file)
@@ -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) */
 
 /**
index b590fa5f29f2e621ed8fa877a31ad8441af6f530..d7b995d0d4ef590ec30d2be3c03260e1a7b59f86 100644 (file)
@@ -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)