REORG: h1: create a new h1m_state

This is the *parsing* state of an HTTP/1 message. Currently the h1_state
is composite as it's made both of parsing and control (100SENT, BODY,
DONE, TUNNEL, ENDING etc). The purpose here is to have a purely H1 state
that can be used by H1 parsers. For now it's equivalent to h1_state.
diff --git a/include/proto/h1.h b/include/proto/h1.h
index 2997383..22b5c6e 100644
--- a/include/proto/h1.h
+++ b/include/proto/h1.h
@@ -74,7 +74,7 @@
 		}                                                         \
 	} while (0)
 
-/* for debugging, reports the HTTP/1 message state name */
+/* for debugging, reports the HTTP/1 message state name (legacy version) */
 static inline const char *h1_msg_state_str(enum h1_state msg_state)
 {
 	switch (msg_state) {
@@ -120,6 +120,52 @@
 	}
 }
 
+/* for debugging, reports the HTTP/1 message state name */
+static inline const char *h1m_state_str(enum h1_state msg_state)
+{
+	switch (msg_state) {
+	case H1_MSG_RQBEFORE:    return "MSG_RQBEFORE";
+	case H1_MSG_RQBEFORE_CR: return "MSG_RQBEFORE_CR";
+	case H1_MSG_RQMETH:      return "MSG_RQMETH";
+	case H1_MSG_RQMETH_SP:   return "MSG_RQMETH_SP";
+	case H1_MSG_RQURI:       return "MSG_RQURI";
+	case H1_MSG_RQURI_SP:    return "MSG_RQURI_SP";
+	case H1_MSG_RQVER:       return "MSG_RQVER";
+	case H1_MSG_RQLINE_END:  return "MSG_RQLINE_END";
+	case H1_MSG_RPBEFORE:    return "MSG_RPBEFORE";
+	case H1_MSG_RPBEFORE_CR: return "MSG_RPBEFORE_CR";
+	case H1_MSG_RPVER:       return "MSG_RPVER";
+	case H1_MSG_RPVER_SP:    return "MSG_RPVER_SP";
+	case H1_MSG_RPCODE:      return "MSG_RPCODE";
+	case H1_MSG_RPCODE_SP:   return "MSG_RPCODE_SP";
+	case H1_MSG_RPREASON:    return "MSG_RPREASON";
+	case H1_MSG_RPLINE_END:  return "MSG_RPLINE_END";
+	case H1_MSG_HDR_FIRST:   return "MSG_HDR_FIRST";
+	case H1_MSG_HDR_NAME:    return "MSG_HDR_NAME";
+	case H1_MSG_HDR_COL:     return "MSG_HDR_COL";
+	case H1_MSG_HDR_L1_SP:   return "MSG_HDR_L1_SP";
+	case H1_MSG_HDR_L1_LF:   return "MSG_HDR_L1_LF";
+	case H1_MSG_HDR_L1_LWS:  return "MSG_HDR_L1_LWS";
+	case H1_MSG_HDR_VAL:     return "MSG_HDR_VAL";
+	case H1_MSG_HDR_L2_LF:   return "MSG_HDR_L2_LF";
+	case H1_MSG_HDR_L2_LWS:  return "MSG_HDR_L2_LWS";
+	case H1_MSG_LAST_LF:     return "MSG_LAST_LF";
+	case H1_MSG_ERROR:       return "MSG_ERROR";
+	case H1_MSG_BODY:        return "MSG_BODY";
+	case H1_MSG_100_SENT:    return "MSG_100_SENT";
+	case H1_MSG_CHUNK_SIZE:  return "MSG_CHUNK_SIZE";
+	case H1_MSG_DATA:        return "MSG_DATA";
+	case H1_MSG_CHUNK_CRLF:  return "MSG_CHUNK_CRLF";
+	case H1_MSG_TRAILERS:    return "MSG_TRAILERS";
+	case H1_MSG_ENDING:      return "MSG_ENDING";
+	case H1_MSG_DONE:        return "MSG_DONE";
+	case H1_MSG_CLOSING:     return "MSG_CLOSING";
+	case H1_MSG_CLOSED:      return "MSG_CLOSED";
+	case H1_MSG_TUNNEL:      return "MSG_TUNNEL";
+	default:                 return "MSG_??????";
+	}
+}
+
 /* This function may be called only in HTTP_MSG_CHUNK_CRLF. It reads the CRLF or
  * a possible LF alone at the end of a chunk. The caller should adjust msg->next
  * in order to include this part into the next forwarding phase.  Note that the
@@ -262,7 +308,7 @@
 /* initializes an H1 message */
 static inline struct h1m *h1m_init(struct h1m *h1m)
 {
-	h1m->state = HTTP_MSG_RQBEFORE;
+	h1m->state = H1_MSG_RQBEFORE;
 	h1m->status = 0;
 	h1m->flags = 0;
 	h1m->curr_len = 0;
diff --git a/include/types/h1.h b/include/types/h1.h
index 3956b6e..8587608 100644
--- a/include/types/h1.h
+++ b/include/types/h1.h
@@ -22,7 +22,9 @@
 #ifndef _TYPES_H1_H
 #define _TYPES_H1_H
 
-/* Possible states while parsing HTTP/1 messages (request|response) */
+/* Legacy version of the HTTP/1 message state, used by the channels, should
+ * ultimately be removed.
+ */
 enum h1_state {
 	HTTP_MSG_RQBEFORE     =  0, // request: leading LF, before start line
 	HTTP_MSG_RQBEFORE_CR  =  1, // request: leading CRLF, before start line
@@ -82,6 +84,66 @@
 } __attribute__((packed));
 
 
+/* Possible states while parsing HTTP/1 messages (request|response) */
+enum h1m_state {
+	H1_MSG_RQBEFORE     =  0, // request: leading LF, before start line
+	H1_MSG_RQBEFORE_CR  =  1, // request: leading CRLF, before start line
+	/* these ones define a request start line */
+	H1_MSG_RQMETH       =  2, // parsing the Method
+	H1_MSG_RQMETH_SP    =  3, // space(s) after the Method
+	H1_MSG_RQURI        =  4, // parsing the Request URI
+	H1_MSG_RQURI_SP     =  5, // space(s) after the Request URI
+	H1_MSG_RQVER        =  6, // parsing the Request Version
+	H1_MSG_RQLINE_END   =  7, // end of request line (CR or LF)
+
+	H1_MSG_RPBEFORE     =  8, // response: leading LF, before start line
+	H1_MSG_RPBEFORE_CR  =  9, // response: leading CRLF, before start line
+
+	/* these ones define a response start line */
+	H1_MSG_RPVER        = 10, // parsing the Response Version
+	H1_MSG_RPVER_SP     = 11, // space(s) after the Response Version
+	H1_MSG_RPCODE       = 12, // response code
+	H1_MSG_RPCODE_SP    = 13, // space(s) after the response code
+	H1_MSG_RPREASON     = 14, // response reason
+	H1_MSG_RPLINE_END   = 15, // end of response line (CR or LF)
+
+	/* common header processing */
+	H1_MSG_HDR_FIRST    = 16, // waiting for first header or last CRLF (no LWS possible)
+	H1_MSG_HDR_NAME     = 17, // parsing header name
+	H1_MSG_HDR_COL      = 18, // parsing header colon
+	H1_MSG_HDR_L1_SP    = 19, // parsing header LWS (SP|HT) before value
+	H1_MSG_HDR_L1_LF    = 20, // parsing header LWS (LF) before value
+	H1_MSG_HDR_L1_LWS   = 21, // checking whether it's a new header or an LWS
+	H1_MSG_HDR_VAL      = 22, // parsing header value
+	H1_MSG_HDR_L2_LF    = 23, // parsing header LWS (LF) inside/after value
+	H1_MSG_HDR_L2_LWS   = 24, // checking whether it's a new header or an LWS
+
+	H1_MSG_LAST_LF      = 25, // parsing last LF
+
+	/* error state : must be before H1_MSG_BODY so that (>=BODY) always indicates
+	 * that data are being processed.
+	 */
+	H1_MSG_ERROR        = 26, // an error occurred
+	/* Body processing.
+	 * The state H1_MSG_BODY is a delimiter to know if we're waiting for headers
+	 * or body. All the sub-states below also indicate we're processing the body,
+	 * with some additional information.
+	 */
+	H1_MSG_BODY         = 27, // parsing body at end of headers
+	H1_MSG_100_SENT     = 28, // parsing body after a 100-Continue was sent
+	H1_MSG_CHUNK_SIZE   = 29, // parsing the chunk size (RFC7230 #4.1)
+	H1_MSG_DATA         = 30, // skipping data chunk / content-length data
+	H1_MSG_CHUNK_CRLF   = 31, // skipping CRLF after data chunk
+	H1_MSG_TRAILERS     = 32, // trailers (post-data entity headers)
+	/* we enter this state when we've received the end of the current message */
+	H1_MSG_ENDING       = 33, // message end received, wait that the filters end too
+	H1_MSG_DONE         = 34, // message end received, waiting for resync or close
+	H1_MSG_CLOSING      = 35, // shutdown_w done, not all bytes sent yet
+	H1_MSG_CLOSED       = 36, // shutdown_w done, all bytes sent
+	H1_MSG_TUNNEL       = 37, // tunneled data after DONE
+} __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
@@ -90,7 +152,7 @@
 
 /* basic HTTP/1 message state for use in parsers */
 struct h1m {
-	enum h1_state state;        // H1 message state (HTTP_MSG_*)
+	enum h1m_state state;       // H1 message state (H1_MSG_*)
 	/* 8 bits available here */
 	uint16_t status;            // HTTP status code
 	uint32_t flags;             // H1 message flags (H1_MF_*)
diff --git a/src/h1.c b/src/h1.c
index 325f5b6..63f284e 100644
--- a/src/h1.c
+++ b/src/h1.c
@@ -683,7 +683,7 @@
  *
  * This function returns :
  *    -1 in case of error. In this case, h1m->err_state is filled (if h1m is
- *       set) with the state the error occurred in and h2-m>err_pos with the
+ *       set) with the state the error occurred in and h1m->err_pos with the
  *       the position relative to <start>
  *    -2 if the output is full (hdr_num reached). err_state and err_pos also
  *       indicate where it failed.
@@ -695,7 +695,7 @@
                            struct http_hdr *hdr, unsigned int hdr_num,
                            struct h1m *h1m)
 {
-	enum h1_state state = HTTP_MSG_RPBEFORE;
+	enum h1m_state state = H1_MSG_RPBEFORE;
 	register char *ptr  = start;
 	register const char *end  = stop;
 	unsigned int hdr_count = 0;
@@ -713,7 +713,7 @@
 		goto http_msg_ood;
 
 	switch (state)	{
-	case HTTP_MSG_RPBEFORE:
+	case H1_MSG_RPBEFORE:
 	http_msg_rpbefore:
 		if (likely(HTTP_IS_TOKEN(*ptr))) {
 			/* we have a start of message, we may have skipped some
@@ -724,39 +724,39 @@
 
 			sol = 0;
 			hdr_count = 0;
-			state = HTTP_MSG_RPVER;
+			state = H1_MSG_RPVER;
 			goto http_msg_rpver;
 		}
 
 		if (unlikely(!HTTP_IS_CRLF(*ptr))) {
-			state = HTTP_MSG_RPBEFORE;
+			state = H1_MSG_RPBEFORE;
 			goto http_msg_invalid;
 		}
 
 		if (unlikely(*ptr == '\n'))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpbefore, http_msg_ood, state, HTTP_MSG_RPBEFORE);
-		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpbefore_cr, http_msg_ood, state, HTTP_MSG_RPBEFORE_CR);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpbefore, http_msg_ood, state, H1_MSG_RPBEFORE);
+		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpbefore_cr, http_msg_ood, state, H1_MSG_RPBEFORE_CR);
 		/* stop here */
 
-	case HTTP_MSG_RPBEFORE_CR:
+	case H1_MSG_RPBEFORE_CR:
 	http_msg_rpbefore_cr:
-		EXPECT_LF_HERE(ptr, http_msg_invalid, state, HTTP_MSG_RPBEFORE_CR);
-		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpbefore, http_msg_ood, state, HTTP_MSG_RPBEFORE);
+		EXPECT_LF_HERE(ptr, http_msg_invalid, state, H1_MSG_RPBEFORE_CR);
+		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpbefore, http_msg_ood, state, H1_MSG_RPBEFORE);
 		/* stop here */
 
-	case HTTP_MSG_RPVER:
+	case H1_MSG_RPVER:
 	http_msg_rpver:
 		if (likely(HTTP_IS_VER_TOKEN(*ptr)))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpver, http_msg_ood, state, HTTP_MSG_RPVER);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpver, http_msg_ood, state, H1_MSG_RPVER);
 
 		if (likely(HTTP_IS_SPHT(*ptr))) {
 			/* version length = ptr - start */
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpver_sp, http_msg_ood, state, HTTP_MSG_RPVER_SP);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpver_sp, http_msg_ood, state, H1_MSG_RPVER_SP);
 		}
-		state = HTTP_MSG_RPVER;
+		state = H1_MSG_RPVER;
 		goto http_msg_invalid;
 
-	case HTTP_MSG_RPVER_SP:
+	case H1_MSG_RPVER_SP:
 	http_msg_rpver_sp:
 		if (likely(!HTTP_IS_LWS(*ptr))) {
 			code = 0;
@@ -764,26 +764,26 @@
 			goto http_msg_rpcode;
 		}
 		if (likely(HTTP_IS_SPHT(*ptr)))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpver_sp, http_msg_ood, state, HTTP_MSG_RPVER_SP);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpver_sp, http_msg_ood, state, H1_MSG_RPVER_SP);
 		/* so it's a CR/LF, this is invalid */
-		state = HTTP_MSG_RPVER_SP;
+		state = H1_MSG_RPVER_SP;
 		goto http_msg_invalid;
 
-	case HTTP_MSG_RPCODE:
+	case H1_MSG_RPCODE:
 	http_msg_rpcode:
 		if (likely(HTTP_IS_DIGIT(*ptr))) {
 			code = code * 10 + *ptr - '0';
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode, http_msg_ood, state, HTTP_MSG_RPCODE);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode, http_msg_ood, state, H1_MSG_RPCODE);
 		}
 
 		if (unlikely(!HTTP_IS_LWS(*ptr))) {
-			state = HTTP_MSG_RPCODE;
+			state = H1_MSG_RPCODE;
 			goto http_msg_invalid;
 		}
 
 		if (likely(HTTP_IS_SPHT(*ptr))) {
 			st_c_l = ptr - start - st_c;
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode_sp, http_msg_ood, state, HTTP_MSG_RPCODE_SP);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode_sp, http_msg_ood, state, H1_MSG_RPCODE_SP);
 		}
 
 		/* so it's a CR/LF, so there is no reason phrase */
@@ -794,21 +794,21 @@
 		/* reason length = 0 */
 		goto http_msg_rpline_eol;
 
-	case HTTP_MSG_RPCODE_SP:
+	case H1_MSG_RPCODE_SP:
 	http_msg_rpcode_sp:
 		if (likely(!HTTP_IS_LWS(*ptr))) {
 			/* reason = ptr - start */
 			goto http_msg_rpreason;
 		}
 		if (likely(HTTP_IS_SPHT(*ptr)))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode_sp, http_msg_ood, state, HTTP_MSG_RPCODE_SP);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode_sp, http_msg_ood, state, H1_MSG_RPCODE_SP);
 		/* so it's a CR/LF, so there is no reason phrase */
 		goto http_msg_rsp_reason;
 
-	case HTTP_MSG_RPREASON:
+	case H1_MSG_RPREASON:
 	http_msg_rpreason:
 		if (likely(!HTTP_IS_CRLF(*ptr)))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpreason, http_msg_ood, state, HTTP_MSG_RPREASON);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpreason, http_msg_ood, state, H1_MSG_RPREASON);
 		/* reason length = ptr - start - reason */
 	http_msg_rpline_eol:
 		/* We have seen the end of line. Note that we do not
@@ -819,7 +819,7 @@
 		 */
 
 		if (unlikely(hdr_count >= hdr_num)) {
-			state = HTTP_MSG_RPREASON;
+			state = H1_MSG_RPREASON;
 			goto http_output_full;
 		}
 		http_set_hdr(&hdr[hdr_count++], ist(":status"), ist2(start + st_c, st_c_l));
@@ -828,17 +828,17 @@
 
 		sol = ptr - start;
 		if (likely(*ptr == '\r'))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpline_end, http_msg_ood, state, HTTP_MSG_RPLINE_END);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpline_end, http_msg_ood, state, H1_MSG_RPLINE_END);
 		goto http_msg_rpline_end;
 
-	case HTTP_MSG_RPLINE_END:
+	case H1_MSG_RPLINE_END:
 	http_msg_rpline_end:
 		/* sol must point to the first of CR or LF. */
-		EXPECT_LF_HERE(ptr, http_msg_invalid, state, HTTP_MSG_RPLINE_END);
-		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_first, http_msg_ood, state, HTTP_MSG_HDR_FIRST);
+		EXPECT_LF_HERE(ptr, http_msg_invalid, state, H1_MSG_RPLINE_END);
+		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_first, http_msg_ood, state, H1_MSG_HDR_FIRST);
 		/* stop here */
 
-	case HTTP_MSG_HDR_FIRST:
+	case H1_MSG_HDR_FIRST:
 	http_msg_hdr_first:
 		sol = ptr - start;
 		if (likely(!HTTP_IS_CRLF(*ptr))) {
@@ -846,26 +846,26 @@
 		}
 
 		if (likely(*ptr == '\r'))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_last_lf, http_msg_ood, state, HTTP_MSG_LAST_LF);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_last_lf, http_msg_ood, state, H1_MSG_LAST_LF);
 		goto http_msg_last_lf;
 
-	case HTTP_MSG_HDR_NAME:
+	case H1_MSG_HDR_NAME:
 	http_msg_hdr_name:
 		/* assumes sol points to the first char */
 		if (likely(HTTP_IS_TOKEN(*ptr))) {
 			/* turn it to lower case if needed */
 			if (isupper((unsigned char)*ptr))
 				*ptr = tolower(*ptr);
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_name, http_msg_ood, state, HTTP_MSG_HDR_NAME);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_name, http_msg_ood, state, H1_MSG_HDR_NAME);
 		}
 
 		if (likely(*ptr == ':')) {
 			col = ptr - start;
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l1_sp, http_msg_ood, state, HTTP_MSG_HDR_L1_SP);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l1_sp, http_msg_ood, state, H1_MSG_HDR_L1_SP);
 		}
 
 		if (HTTP_IS_LWS(*ptr)) {
-			state = HTTP_MSG_HDR_NAME;
+			state = H1_MSG_HDR_NAME;
 			goto http_msg_invalid;
 		}
 
@@ -874,13 +874,13 @@
 		 * was acceptable. If we find it here, it was considered
 		 * acceptable due to configuration rules so we obey.
 		 */
-		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_name, http_msg_ood, state, HTTP_MSG_HDR_NAME);
+		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_name, http_msg_ood, state, H1_MSG_HDR_NAME);
 
-	case HTTP_MSG_HDR_L1_SP:
+	case H1_MSG_HDR_L1_SP:
 	http_msg_hdr_l1_sp:
 		/* assumes sol points to the first char */
 		if (likely(HTTP_IS_SPHT(*ptr)))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l1_sp, http_msg_ood, state, HTTP_MSG_HDR_L1_SP);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l1_sp, http_msg_ood, state, H1_MSG_HDR_L1_SP);
 
 		/* header value can be basically anything except CR/LF */
 		sov = ptr - start;
@@ -890,15 +890,15 @@
 		}
 
 		if (likely(*ptr == '\r'))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l1_lf, http_msg_ood, state, HTTP_MSG_HDR_L1_LF);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l1_lf, http_msg_ood, state, H1_MSG_HDR_L1_LF);
 		goto http_msg_hdr_l1_lf;
 
-	case HTTP_MSG_HDR_L1_LF:
+	case H1_MSG_HDR_L1_LF:
 	http_msg_hdr_l1_lf:
-		EXPECT_LF_HERE(ptr, http_msg_invalid, state, HTTP_MSG_HDR_L1_LF);
-		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l1_lws, http_msg_ood, state, HTTP_MSG_HDR_L1_LWS);
+		EXPECT_LF_HERE(ptr, http_msg_invalid, state, H1_MSG_HDR_L1_LF);
+		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l1_lws, http_msg_ood, state, H1_MSG_HDR_L1_LWS);
 
-	case HTTP_MSG_HDR_L1_LWS:
+	case H1_MSG_HDR_L1_LWS:
 	http_msg_hdr_l1_lws:
 		if (likely(HTTP_IS_SPHT(*ptr))) {
 			/* replace HT,CR,LF with spaces */
@@ -910,7 +910,7 @@
 		eol = sov;
 		goto http_msg_complete_header;
 
-	case HTTP_MSG_HDR_VAL:
+	case H1_MSG_HDR_VAL:
 	http_msg_hdr_val:
 		/* assumes sol points to the first char, and sov
 		 * points to the first character of the value.
@@ -938,12 +938,12 @@
 		}
 #endif
 		if (ptr >= end) {
-			state = HTTP_MSG_HDR_VAL;
+			state = H1_MSG_HDR_VAL;
 			goto http_msg_ood;
 		}
 	http_msg_hdr_val2:
 		if (likely(!HTTP_IS_CRLF(*ptr)))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_val2, http_msg_ood, state, HTTP_MSG_HDR_VAL);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_val2, http_msg_ood, state, H1_MSG_HDR_VAL);
 
 		eol = ptr - start;
 		/* Note: we could also copy eol into ->eoh so that we have the
@@ -951,15 +951,15 @@
 		 * really needed ?
 		 */
 		if (likely(*ptr == '\r'))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l2_lf, http_msg_ood, state, HTTP_MSG_HDR_L2_LF);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l2_lf, http_msg_ood, state, H1_MSG_HDR_L2_LF);
 		goto http_msg_hdr_l2_lf;
 
-	case HTTP_MSG_HDR_L2_LF:
+	case H1_MSG_HDR_L2_LF:
 	http_msg_hdr_l2_lf:
-		EXPECT_LF_HERE(ptr, http_msg_invalid, state, HTTP_MSG_HDR_L2_LF);
-		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l2_lws, http_msg_ood, state, HTTP_MSG_HDR_L2_LWS);
+		EXPECT_LF_HERE(ptr, http_msg_invalid, state, H1_MSG_HDR_L2_LF);
+		EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l2_lws, http_msg_ood, state, H1_MSG_HDR_L2_LWS);
 
-	case HTTP_MSG_HDR_L2_LWS:
+	case H1_MSG_HDR_L2_LWS:
 	http_msg_hdr_l2_lws:
 		if (unlikely(HTTP_IS_SPHT(*ptr))) {
 			/* LWS: replace HT,CR,LF with spaces */
@@ -988,7 +988,7 @@
 		v = ist2(start + sov, eol - sov);
 
 		if (unlikely(hdr_count >= hdr_num)) {
-			state = HTTP_MSG_HDR_L2_LWS;
+			state = H1_MSG_HDR_L2_LWS;
 			goto http_output_full;
 		}
 		http_set_hdr(&hdr[hdr_count++], n, v);
@@ -1019,23 +1019,23 @@
 			goto http_msg_hdr_name;
 
 		if (likely(*ptr == '\r'))
-			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_last_lf, http_msg_ood, state, HTTP_MSG_LAST_LF);
+			EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_last_lf, http_msg_ood, state, H1_MSG_LAST_LF);
 		goto http_msg_last_lf;
 
-	case HTTP_MSG_LAST_LF:
+	case H1_MSG_LAST_LF:
 	http_msg_last_lf:
-		EXPECT_LF_HERE(ptr, http_msg_invalid, state, HTTP_MSG_LAST_LF);
+		EXPECT_LF_HERE(ptr, http_msg_invalid, state, H1_MSG_LAST_LF);
 		ptr++;
 		/* <ptr> now points to the first byte of payload. If needed sol
 		 * still points to the first of either CR or LF of the empty
 		 * line ending the headers block.
 		 */
 		if (unlikely(hdr_count >= hdr_num)) {
-			state = HTTP_MSG_LAST_LF;
+			state = H1_MSG_LAST_LF;
 			goto http_output_full;
 		}
 		http_set_hdr(&hdr[hdr_count++], ist(""), ist(""));
-		state = HTTP_MSG_BODY;
+		state = H1_MSG_BODY;
 		break;
 
 	default:
@@ -1044,7 +1044,7 @@
 	}
 
 	/* reaching here, we've parsed the whole message and the state is
-	 * HTTP_MSG_BODY.
+	 * H1_MSG_BODY.
 	 */
 	return ptr - start + skip;
 
diff --git a/src/mux_h2.c b/src/mux_h2.c
index a0fadcd..595d66b 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -3222,7 +3222,7 @@
 		// trim any possibly pending data (eg: inconsistent content-length)
 		ret += max;
 
-		h1m->state = HTTP_MSG_DONE;
+		h1m->state = H1_MSG_DONE;
 		h2s->flags |= H2_SF_ES_SENT;
 		if (h2s->st == H2_SS_OPEN)
 			h2s->st = H2_SS_HLOC;
@@ -3231,13 +3231,13 @@
 	}
 	else if (h1m->status >= 100 && h1m->status < 200) {
 		/* we'll let the caller check if it has more headers to send */
-		h1m->state = HTTP_MSG_RPBEFORE;
+		h1m->state = H1_MSG_RPBEFORE;
 		h1m->status = 0;
 		h1m->flags = 0;
 		goto end;
 	}
 	else
-		h1m->state = (h1m->flags & H1_MF_CHNK) ? HTTP_MSG_CHUNK_SIZE : HTTP_MSG_BODY;
+		h1m->state = (h1m->flags & H1_MF_CHNK) ? H1_MSG_CHUNK_SIZE : H1_MSG_BODY;
 
  end:
 	//fprintf(stderr, "[%d] sent simple H2 response (sid=%d) = %d bytes (%d in, ep=%u, es=%s)\n", h2c->st0, h2s->id, outbuf.len, ret, h1m->err_pos, h1_msg_state_str(h1m->err_state));
@@ -3311,7 +3311,7 @@
 			size = h1m->curr_len;
 		break;
 	default:          /* te:chunked : parse chunks */
-		if (h1m->state == HTTP_MSG_CHUNK_CRLF) {
+		if (h1m->state == H1_MSG_CHUNK_CRLF) {
 			ret = h1_skip_chunk_crlf(buf, ofs, ofs + max);
 			if (!ret)
 				goto end;
@@ -3325,10 +3325,10 @@
 			max -= ret;
 			ofs += ret;
 			total += ret;
-			h1m->state = HTTP_MSG_CHUNK_SIZE;
+			h1m->state = H1_MSG_CHUNK_SIZE;
 		}
 
-		if (h1m->state == HTTP_MSG_CHUNK_SIZE) {
+		if (h1m->state == H1_MSG_CHUNK_SIZE) {
 			unsigned int chunk;
 			ret = h1_parse_chunk_size(buf, ofs, ofs + max, &chunk);
 			if (!ret)
@@ -3347,7 +3347,7 @@
 			max -= ret;
 			ofs += ret;
 			total += ret;
-			h1m->state = size ? HTTP_MSG_DATA : HTTP_MSG_TRAILERS;
+			h1m->state = size ? H1_MSG_DATA : H1_MSG_TRAILERS;
 			if (!size)
 				goto send_empty;
 		}
@@ -3447,7 +3447,7 @@
 	 *
 	 */
 	if (((h1m->flags & H1_MF_CLEN) && !(h1m->curr_len - size)) ||
-	    !h1m->curr_len || h1m->state >= HTTP_MSG_DONE)
+	    !h1m->curr_len || h1m->state >= H1_MSG_DONE)
 		es_now = 1;
 
 	/* update the frame's size */
@@ -3469,7 +3469,7 @@
 		h2c->mws -= size;
 
 		if (size && !h1m->curr_len && (h1m->flags & H1_MF_CHNK)) {
-			h1m->state = HTTP_MSG_CHUNK_CRLF;
+			h1m->state = H1_MSG_CHUNK_CRLF;
 			goto new_frame;
 		}
 	}
@@ -3486,7 +3486,7 @@
 			ofs += max;
 			max = 0;
 
-			h1m->state = HTTP_MSG_DONE;
+			h1m->state = H1_MSG_DONE;
 		}
 
 		h2s->flags |= H2_SF_ES_SENT;
@@ -3566,14 +3566,14 @@
 	if (!(h2s->flags & H2_SF_OUTGOING_DATA) && count)
 		h2s->flags |= H2_SF_OUTGOING_DATA;
 
-	while (h2s->res.state < HTTP_MSG_DONE && count) {
-		if (h2s->res.state < HTTP_MSG_BODY) {
+	while (h2s->res.state < H1_MSG_DONE && count) {
+		if (h2s->res.state < H1_MSG_BODY) {
 			ret = h2s_frt_make_resp_headers(h2s, buf, total, count);
 		}
-		else if (h2s->res.state < HTTP_MSG_TRAILERS) {
+		else if (h2s->res.state < H1_MSG_TRAILERS) {
 			ret = h2s_frt_make_resp_data(h2s, buf, total, count);
 		}
-		else if (h2s->res.state == HTTP_MSG_TRAILERS) {
+		else if (h2s->res.state == H1_MSG_TRAILERS) {
 			/* consume the trailers if any (we don't forward them for now) */
 			ret = h1_measure_trailers(buf, total, count);
 
@@ -3585,7 +3585,7 @@
 			// trim any possibly pending data (eg: extra CR-LF, ...)
 			total += count;
 			count  = 0;
-			h2s->res.state = HTTP_MSG_DONE;
+			h2s->res.state = H1_MSG_DONE;
 			break;
 		}
 		else {