]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: Add function to parse value of the header Status
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 16 Sep 2019 09:37:05 +0000 (11:37 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 Sep 2019 08:18:54 +0000 (10:18 +0200)
It will be used by the mux FCGI to get the status a response.

include/common/http.h
src/http.c

index 537be5a01acbdf149fcfaa82019fdfdf919140d6..fbbc33c0c266a660c7f8bc330387ae979c413136 100644 (file)
@@ -154,6 +154,7 @@ int http_find_next_url_param(const char **chunks,
 
 int http_parse_header(const struct ist hdr, struct ist *name, struct ist *value);
 int http_parse_stline(const struct ist line, struct ist *p1, struct ist *p2, struct ist *p3);
+int http_parse_status_val(const struct ist value, struct ist *status, struct ist *reason);
 
 /*
  * Given a path string and its length, find the position of beginning of the
index c77f8c8bcc25cf41b31397362e774d31425c82e0..fe7ed4cdf7a1ffdf2bd5913108a6c459bf50b585 100644 (file)
@@ -980,3 +980,34 @@ int http_parse_stline(const struct ist line, struct ist *p1, struct ist *p2, str
 
         return 1;
 }
+
+/* Parses value of a Status header with the following format: "Status: Code[
+ * Reason]".  The parsing is pretty naive and just skip spaces. It return the
+ * numeric value of the status code.
+ */
+int http_parse_status_val(const struct ist value, struct ist *status, struct ist *reason)
+{
+       char *p   = value.ptr;
+        char *end = p + value.len;
+       uint16_t code;
+
+       status->len = reason->len = 0;
+
+       /* Skip leading spaces */
+        for (; p < end && HTTP_IS_SPHT(*p); p++);
+
+        /* Set the status part */
+        status->ptr = p;
+        for (; p < end && HTTP_IS_TOKEN(*p); p++);
+        status->len = p - status->ptr;
+
+       /* Skip spaces between status and reason */
+        for (; p < end && HTTP_IS_SPHT(*p); p++);
+
+       /* the remaining is the reason */
+        reason->ptr = p;
+        reason->len = end - p;
+
+       code = strl2ui(status->ptr, status->len);
+       return code;
+}