diff --git a/include/proto/h1.h b/include/proto/h1.h index 8a0e26541..6bd753776 100644 --- a/include/proto/h1.h +++ b/include/proto/h1.h @@ -267,5 +267,16 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s return -buffer_count(buf, ptr, ptr_stop); } +/* initializes an H1 message */ +static inline struct h1m *h1m_init(struct h1m *h1m) +{ + h1m->state = HTTP_MSG_RQBEFORE; + h1m->flags = 0; + h1m->curr_len = 0; + h1m->body_len = 0; + h1m->err_pos = 0; + h1m->err_state = 0; + return h1m; +} #endif /* _PROTO_H1_H */ diff --git a/include/types/h1.h b/include/types/h1.h index 8a146c3ca..230102c00 100644 --- a/include/types/h1.h +++ b/include/types/h1.h @@ -82,4 +82,20 @@ enum h1_state { } __attribute__((packed)); +/* HTTP/1 message flags (32 bit), for use in h1m->flags only */ +#define H1_MF_NONE 0x00000000 +#define H1_MF_CLEN 0x00000001 // content-length present +#define H1_MF_CHNK 0x00000002 // chunk present, exclusive with c-l + + +/* basic HTTP/1 message state for use in parsers */ +struct h1m { + enum h1_state state; // H1 message state (HTTP_MSG_*) + 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 + int err_pos; // position in the byte stream of the first error (H1 or H2) + int err_state; // state where the first error was met (H1 or H2) +}; + #endif /* _TYPES_H1_H */