]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h1: store the status code in the H1 message
authorWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 07:02:24 +0000 (08:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 07:43:29 +0000 (08:43 +0100)
It was painful not to have the status code available, especially when
it was computed. Let's store it and ensure we don't claim content-length
anymore on 1xx, only 0 body bytes.

include/proto/h1.h
include/types/h1.h
src/h1.c

index e7d364d3d78554c1d453d9d32e5e4c5d6471f0b3..b7229507b9dd9c3499a905d24ef143818ecbae9b 100644 (file)
@@ -275,6 +275,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
 static inline struct h1m *h1m_init(struct h1m *h1m)
 {
        h1m->state = HTTP_MSG_RQBEFORE;
+       h1m->status = 0;
        h1m->flags = 0;
        h1m->curr_len = 0;
        h1m->body_len = 0;
index 230102c008b92f3f134fbe4272fd1c4d4c9618ec..3956b6e6ce8b2ca88ecb07d730d996b4703de8b7 100644 (file)
@@ -91,6 +91,8 @@ enum h1_state {
 /* basic HTTP/1 message state for use in parsers */
 struct h1m {
        enum h1_state state;        // H1 message state (HTTP_MSG_*)
+       /* 8 bits available here */
+       uint16_t status;            // HTTP status code
        uint32_t flags;             // H1 message flags (H1_MF_*)
        uint64_t curr_len;          // content-length or last chunk length
        uint64_t body_len;          // total known size of the body length
index 856b654ddfae70259bea79c5c42d3422a48bc994..bbfaabcf76000b7979d08044cbef38423b22a9ca 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -910,7 +910,7 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
        case HTTP_MSG_RPCODE:
        http_msg_rpcode:
                if (likely(!HTTP_IS_LWS(*ptr))) {
-                       code = (code << 8) + *ptr;
+                       code = code * 10 + *ptr - '0';
                        EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode, http_msg_ood, state, HTTP_MSG_RPCODE);
                }
 
@@ -956,6 +956,8 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
                        goto http_output_full;
                }
                http_set_hdr(&hdr[hdr_count++], ist(":status"), ist2(start + st_c, st_c_l));
+               if (h1m)
+                       h1m->status = code;
 
                sol = ptr - start;
                if (likely(*ptr == '\r'))
@@ -1127,9 +1129,9 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
                if (h1m) {
                        long long cl;
 
-                       if (start[st_c] == '1' || /* 100..199 */
-                           isteq(ist2(start + st_c, st_c_l), ist("204")) ||
-                           isteq(ist2(start + st_c, st_c_l), ist("304"))) {
+                       if (h1m->status >= 100 && h1m->status < 200)
+                               h1m->curr_len = h1m->body_len = 0;
+                       else if (h1m->status == 304 || h1m->status == 204) {
                                /* no contents, claim c-len is present and set to zero */
                                h1m->flags |= H1_MF_CLEN;
                                h1m->curr_len = h1m->body_len = 0;