MINOR: h1: store the status code in the H1 message

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.
This commit is contained in:
Willy Tarreau 2017-10-31 08:02:24 +01:00
parent a3c77cfdd7
commit d22e83abd9
3 changed files with 9 additions and 4 deletions

View 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;

View 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

View File

@ -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;