REORG: http: move some very http1-specific parts to h1.{c,h}
Certain types and enums are very specific to the HTTP/1 parser, and we'll
need to share them with the HTTP/2 to HTTP/1 translation code. Let's move
them to h1.c/h1.h. Those with very few occurrences or only used locally
were renamed to explicitly mention the relevant HTTP version :
enum ht_state -> h1_state.
http_msg_state_str -> h1_msg_state_str
HTTP_FLG_* -> H1_FLG_*
http_char_classes -> h1_char_classes
Others like HTTP_IS_*, HTTP_MSG_* are left to be done later.
diff --git a/include/proto/h1.h b/include/proto/h1.h
new file mode 100644
index 0000000..7dff096
--- /dev/null
+++ b/include/proto/h1.h
@@ -0,0 +1,125 @@
+/*
+ * include/proto/h1.h
+ * This file contains HTTP/1 protocol definitions.
+ *
+ * Copyright (C) 2000-2017 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _PROTO_H1_H
+#define _PROTO_H1_H
+
+#include <common/compiler.h>
+#include <common/config.h>
+#include <types/h1.h>
+
+extern const uint8_t h1_char_classes[256];
+
+#define H1_FLG_CTL 0x01
+#define H1_FLG_SEP 0x02
+#define H1_FLG_LWS 0x04
+#define H1_FLG_SPHT 0x08
+#define H1_FLG_CRLF 0x10
+#define H1_FLG_TOK 0x20
+#define H1_FLG_VER 0x40
+
+#define HTTP_IS_CTL(x) (h1_char_classes[(uint8_t)(x)] & H1_FLG_CTL)
+#define HTTP_IS_SEP(x) (h1_char_classes[(uint8_t)(x)] & H1_FLG_SEP)
+#define HTTP_IS_LWS(x) (h1_char_classes[(uint8_t)(x)] & H1_FLG_LWS)
+#define HTTP_IS_SPHT(x) (h1_char_classes[(uint8_t)(x)] & H1_FLG_SPHT)
+#define HTTP_IS_CRLF(x) (h1_char_classes[(uint8_t)(x)] & H1_FLG_CRLF)
+#define HTTP_IS_TOKEN(x) (h1_char_classes[(uint8_t)(x)] & H1_FLG_TOK)
+#define HTTP_IS_VER_TOKEN(x) (h1_char_classes[(uint8_t)(x)] & H1_FLG_VER)
+
+
+/* Macros used in the HTTP/1 parser, to check for the expected presence of
+ * certain bytes (ef: LF) or to skip to next byte and yield in case of failure.
+ */
+
+
+/* Expects to find an LF at <ptr>. If not, set <state> to <where> and jump to
+ * <bad>.
+ */
+#define EXPECT_LF_HERE(ptr, bad, state, where) \
+ do { \
+ if (unlikely(*(ptr) != '\n')) { \
+ state = (where); \
+ goto bad; \
+ } \
+ } while (0)
+
+/* Increments pointer <ptr>, continues to label <more> if it's still below
+ * pointer <end>, or goes to <stop> and sets <state> to <where> if the end
+ * of buffer was reached.
+ */
+#define EAT_AND_JUMP_OR_RETURN(ptr, end, more, stop, state, where) \
+ do { \
+ if (likely(++(ptr) < (end))) \
+ goto more; \
+ else { \
+ state = (where); \
+ goto stop; \
+ } \
+ } while (0)
+
+/* for debugging, reports the HTTP/1 message state name */
+static inline const char *h1_msg_state_str(enum h1_state msg_state)
+{
+ switch (msg_state) {
+ case HTTP_MSG_RQBEFORE: return "MSG_RQBEFORE";
+ case HTTP_MSG_RQBEFORE_CR: return "MSG_RQBEFORE_CR";
+ case HTTP_MSG_RQMETH: return "MSG_RQMETH";
+ case HTTP_MSG_RQMETH_SP: return "MSG_RQMETH_SP";
+ case HTTP_MSG_RQURI: return "MSG_RQURI";
+ case HTTP_MSG_RQURI_SP: return "MSG_RQURI_SP";
+ case HTTP_MSG_RQVER: return "MSG_RQVER";
+ case HTTP_MSG_RQLINE_END: return "MSG_RQLINE_END";
+ case HTTP_MSG_RPBEFORE: return "MSG_RPBEFORE";
+ case HTTP_MSG_RPBEFORE_CR: return "MSG_RPBEFORE_CR";
+ case HTTP_MSG_RPVER: return "MSG_RPVER";
+ case HTTP_MSG_RPVER_SP: return "MSG_RPVER_SP";
+ case HTTP_MSG_RPCODE: return "MSG_RPCODE";
+ case HTTP_MSG_RPCODE_SP: return "MSG_RPCODE_SP";
+ case HTTP_MSG_RPREASON: return "MSG_RPREASON";
+ case HTTP_MSG_RPLINE_END: return "MSG_RPLINE_END";
+ case HTTP_MSG_HDR_FIRST: return "MSG_HDR_FIRST";
+ case HTTP_MSG_HDR_NAME: return "MSG_HDR_NAME";
+ case HTTP_MSG_HDR_COL: return "MSG_HDR_COL";
+ case HTTP_MSG_HDR_L1_SP: return "MSG_HDR_L1_SP";
+ case HTTP_MSG_HDR_L1_LF: return "MSG_HDR_L1_LF";
+ case HTTP_MSG_HDR_L1_LWS: return "MSG_HDR_L1_LWS";
+ case HTTP_MSG_HDR_VAL: return "MSG_HDR_VAL";
+ case HTTP_MSG_HDR_L2_LF: return "MSG_HDR_L2_LF";
+ case HTTP_MSG_HDR_L2_LWS: return "MSG_HDR_L2_LWS";
+ case HTTP_MSG_LAST_LF: return "MSG_LAST_LF";
+ case HTTP_MSG_ERROR: return "MSG_ERROR";
+ case HTTP_MSG_BODY: return "MSG_BODY";
+ case HTTP_MSG_100_SENT: return "MSG_100_SENT";
+ case HTTP_MSG_CHUNK_SIZE: return "MSG_CHUNK_SIZE";
+ case HTTP_MSG_DATA: return "MSG_DATA";
+ case HTTP_MSG_CHUNK_CRLF: return "MSG_CHUNK_CRLF";
+ case HTTP_MSG_TRAILERS: return "MSG_TRAILERS";
+ case HTTP_MSG_ENDING: return "MSG_ENDING";
+ case HTTP_MSG_DONE: return "MSG_DONE";
+ case HTTP_MSG_CLOSING: return "MSG_CLOSING";
+ case HTTP_MSG_CLOSED: return "MSG_CLOSED";
+ case HTTP_MSG_TUNNEL: return "MSG_TUNNEL";
+ default: return "MSG_??????";
+ }
+}
+
+
+#endif /* _PROTO_H1_H */
diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h
index 0fe7790..d046f53 100644
--- a/include/proto/proto_http.h
+++ b/include/proto/proto_http.h
@@ -27,6 +27,7 @@
#include <types/proto_http.h>
#include <types/stream.h>
#include <types/task.h>
+#include <proto/h1.h>
/*
* some macros used for the request parsing.
@@ -42,55 +43,6 @@
* ver_token = 'H', 'P', 'T', '/', '.', and digits.
*/
-extern const unsigned char http_char_classes[256];
-
-#define HTTP_FLG_CTL 0x01
-#define HTTP_FLG_SEP 0x02
-#define HTTP_FLG_LWS 0x04
-#define HTTP_FLG_SPHT 0x08
-#define HTTP_FLG_CRLF 0x10
-#define HTTP_FLG_TOK 0x20
-#define HTTP_FLG_VER 0x40
-
-#define HTTP_IS_CTL(x) (http_char_classes[(unsigned char)(x)] & HTTP_FLG_CTL)
-#define HTTP_IS_SEP(x) (http_char_classes[(unsigned char)(x)] & HTTP_FLG_SEP)
-#define HTTP_IS_LWS(x) (http_char_classes[(unsigned char)(x)] & HTTP_FLG_LWS)
-#define HTTP_IS_SPHT(x) (http_char_classes[(unsigned char)(x)] & HTTP_FLG_SPHT)
-#define HTTP_IS_CRLF(x) (http_char_classes[(unsigned char)(x)] & HTTP_FLG_CRLF)
-#define HTTP_IS_TOKEN(x) (http_char_classes[(unsigned char)(x)] & HTTP_FLG_TOK)
-#define HTTP_IS_VER_TOKEN(x) (http_char_classes[(unsigned char)(x)] & HTTP_FLG_VER)
-
-/* Macros used in the HTTP parser, to check for the expected presence of
- * certain bytes (ef: LF) or to skip to next byte and yield in case of failure.
- */
-
-
-/* Expects to find an LF at <ptr>. If not, set <state> to <where> and jump to
- * <bad>.
- */
-#define EXPECT_LF_HERE(ptr, bad, state, where) \
- do { \
- if (unlikely(*(ptr) != '\n')) { \
- state = (where); \
- goto bad; \
- } \
- } while (0)
-
-/* Increments pointer <ptr>, continues to label <more> if it's still below
- * pointer <end>, or goes to <stop> and sets <state> to <where> if the end
- * of buffer was reached.
- */
-#define EAT_AND_JUMP_OR_RETURN(ptr, end, more, stop, state, where) \
- do { \
- if (likely(++(ptr) < (end))) \
- goto more; \
- else { \
- state = (where); \
- goto stop; \
- } \
- } while (0)
-
-
extern const int http_err_codes[HTTP_ERR_SIZE];
extern struct chunk http_err_chunks[HTTP_ERR_SIZE];
extern const char *HTTP_302;
@@ -147,7 +99,7 @@
void http_return_srv_error(struct stream *s, struct stream_interface *si);
void http_capture_bad_message(struct error_snapshot *es, struct stream *s,
struct http_msg *msg,
- enum ht_state state, struct proxy *other_end);
+ enum h1_state state, struct proxy *other_end);
unsigned int http_get_hdr(const struct http_msg *msg, const char *hname, int hlen,
struct hdr_idx *idx, int occ,
struct hdr_ctx *ctx, char **vptr, int *vlen);
@@ -282,52 +234,6 @@
return trk_action - ACT_ACTION_TRK_SC0;
}
-/* for debugging, reports the HTTP message state name */
-static inline const char *http_msg_state_str(int msg_state)
-{
- switch (msg_state) {
- case HTTP_MSG_RQBEFORE: return "MSG_RQBEFORE";
- case HTTP_MSG_RQBEFORE_CR: return "MSG_RQBEFORE_CR";
- case HTTP_MSG_RQMETH: return "MSG_RQMETH";
- case HTTP_MSG_RQMETH_SP: return "MSG_RQMETH_SP";
- case HTTP_MSG_RQURI: return "MSG_RQURI";
- case HTTP_MSG_RQURI_SP: return "MSG_RQURI_SP";
- case HTTP_MSG_RQVER: return "MSG_RQVER";
- case HTTP_MSG_RQLINE_END: return "MSG_RQLINE_END";
- case HTTP_MSG_RPBEFORE: return "MSG_RPBEFORE";
- case HTTP_MSG_RPBEFORE_CR: return "MSG_RPBEFORE_CR";
- case HTTP_MSG_RPVER: return "MSG_RPVER";
- case HTTP_MSG_RPVER_SP: return "MSG_RPVER_SP";
- case HTTP_MSG_RPCODE: return "MSG_RPCODE";
- case HTTP_MSG_RPCODE_SP: return "MSG_RPCODE_SP";
- case HTTP_MSG_RPREASON: return "MSG_RPREASON";
- case HTTP_MSG_RPLINE_END: return "MSG_RPLINE_END";
- case HTTP_MSG_HDR_FIRST: return "MSG_HDR_FIRST";
- case HTTP_MSG_HDR_NAME: return "MSG_HDR_NAME";
- case HTTP_MSG_HDR_COL: return "MSG_HDR_COL";
- case HTTP_MSG_HDR_L1_SP: return "MSG_HDR_L1_SP";
- case HTTP_MSG_HDR_L1_LF: return "MSG_HDR_L1_LF";
- case HTTP_MSG_HDR_L1_LWS: return "MSG_HDR_L1_LWS";
- case HTTP_MSG_HDR_VAL: return "MSG_HDR_VAL";
- case HTTP_MSG_HDR_L2_LF: return "MSG_HDR_L2_LF";
- case HTTP_MSG_HDR_L2_LWS: return "MSG_HDR_L2_LWS";
- case HTTP_MSG_LAST_LF: return "MSG_LAST_LF";
- case HTTP_MSG_ERROR: return "MSG_ERROR";
- case HTTP_MSG_BODY: return "MSG_BODY";
- case HTTP_MSG_100_SENT: return "MSG_100_SENT";
- case HTTP_MSG_CHUNK_SIZE: return "MSG_CHUNK_SIZE";
- case HTTP_MSG_DATA: return "MSG_DATA";
- case HTTP_MSG_CHUNK_CRLF: return "MSG_CHUNK_CRLF";
- case HTTP_MSG_TRAILERS: return "MSG_TRAILERS";
- case HTTP_MSG_ENDING: return "MSG_ENDING";
- case HTTP_MSG_DONE: return "MSG_DONE";
- case HTTP_MSG_CLOSING: return "MSG_CLOSING";
- case HTTP_MSG_CLOSED: return "MSG_CLOSED";
- case HTTP_MSG_TUNNEL: return "MSG_TUNNEL";
- default: return "MSG_??????";
- }
-}
-
#endif /* _PROTO_PROTO_HTTP_H */
/*
diff --git a/include/types/h1.h b/include/types/h1.h
new file mode 100644
index 0000000..8a146c3
--- /dev/null
+++ b/include/types/h1.h
@@ -0,0 +1,85 @@
+/*
+ * include/types/h1.h
+ * This file contains HTTP/1 protocol definitions.
+ *
+ * Copyright (C) 2000-2017 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _TYPES_H1_H
+#define _TYPES_H1_H
+
+/* Possible states while parsing HTTP/1 messages (request|response) */
+enum h1_state {
+ HTTP_MSG_RQBEFORE = 0, // request: leading LF, before start line
+ HTTP_MSG_RQBEFORE_CR = 1, // request: leading CRLF, before start line
+ /* these ones define a request start line */
+ HTTP_MSG_RQMETH = 2, // parsing the Method
+ HTTP_MSG_RQMETH_SP = 3, // space(s) after the Method
+ HTTP_MSG_RQURI = 4, // parsing the Request URI
+ HTTP_MSG_RQURI_SP = 5, // space(s) after the Request URI
+ HTTP_MSG_RQVER = 6, // parsing the Request Version
+ HTTP_MSG_RQLINE_END = 7, // end of request line (CR or LF)
+
+ HTTP_MSG_RPBEFORE = 8, // response: leading LF, before start line
+ HTTP_MSG_RPBEFORE_CR = 9, // response: leading CRLF, before start line
+
+ /* these ones define a response start line */
+ HTTP_MSG_RPVER = 10, // parsing the Response Version
+ HTTP_MSG_RPVER_SP = 11, // space(s) after the Response Version
+ HTTP_MSG_RPCODE = 12, // response code
+ HTTP_MSG_RPCODE_SP = 13, // space(s) after the response code
+ HTTP_MSG_RPREASON = 14, // response reason
+ HTTP_MSG_RPLINE_END = 15, // end of response line (CR or LF)
+
+ /* common header processing */
+ HTTP_MSG_HDR_FIRST = 16, // waiting for first header or last CRLF (no LWS possible)
+ HTTP_MSG_HDR_NAME = 17, // parsing header name
+ HTTP_MSG_HDR_COL = 18, // parsing header colon
+ HTTP_MSG_HDR_L1_SP = 19, // parsing header LWS (SP|HT) before value
+ HTTP_MSG_HDR_L1_LF = 20, // parsing header LWS (LF) before value
+ HTTP_MSG_HDR_L1_LWS = 21, // checking whether it's a new header or an LWS
+ HTTP_MSG_HDR_VAL = 22, // parsing header value
+ HTTP_MSG_HDR_L2_LF = 23, // parsing header LWS (LF) inside/after value
+ HTTP_MSG_HDR_L2_LWS = 24, // checking whether it's a new header or an LWS
+
+ HTTP_MSG_LAST_LF = 25, // parsing last LF
+
+ /* error state : must be before HTTP_MSG_BODY so that (>=BODY) always indicates
+ * that data are being processed.
+ */
+ HTTP_MSG_ERROR = 26, // an error occurred
+ /* Body processing.
+ * The state HTTP_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.
+ */
+ HTTP_MSG_BODY = 27, // parsing body at end of headers
+ HTTP_MSG_100_SENT = 28, // parsing body after a 100-Continue was sent
+ HTTP_MSG_CHUNK_SIZE = 29, // parsing the chunk size (RFC7230 #4.1)
+ HTTP_MSG_DATA = 30, // skipping data chunk / content-length data
+ HTTP_MSG_CHUNK_CRLF = 31, // skipping CRLF after data chunk
+ HTTP_MSG_TRAILERS = 32, // trailers (post-data entity headers)
+ /* we enter this state when we've received the end of the current message */
+ HTTP_MSG_ENDING = 33, // message end received, wait that the filters end too
+ HTTP_MSG_DONE = 34, // message end received, waiting for resync or close
+ HTTP_MSG_CLOSING = 35, // shutdown_w done, not all bytes sent yet
+ HTTP_MSG_CLOSED = 36, // shutdown_w done, all bytes sent
+ HTTP_MSG_TUNNEL = 37, // tunneled data after DONE
+} __attribute__((packed));
+
+
+#endif /* _TYPES_H1_H */
diff --git a/include/types/hlua.h b/include/types/hlua.h
index c7405a3..bff29d0 100644
--- a/include/types/hlua.h
+++ b/include/types/hlua.h
@@ -62,7 +62,7 @@
union {
struct {
int dir;
- enum ht_state state;
+ enum h1_state state;
} http;
} data;
};
diff --git a/include/types/proto_http.h b/include/types/proto_http.h
index 1d378ac..3f99df7 100644
--- a/include/types/proto_http.h
+++ b/include/types/proto_http.h
@@ -27,6 +27,7 @@
#include <common/mini-clist.h>
#include <common/regex.h>
+#include <types/h1.h>
#include <types/hdr_idx.h>
#include <types/filters.h>
#include <types/sample.h>
@@ -124,65 +125,6 @@
*
*/
-/* Possible states while parsing HTTP messages (request|response) */
-enum ht_state {
- HTTP_MSG_RQBEFORE = 0, // request: leading LF, before start line
- HTTP_MSG_RQBEFORE_CR = 1, // request: leading CRLF, before start line
- /* these ones define a request start line */
- HTTP_MSG_RQMETH = 2, // parsing the Method
- HTTP_MSG_RQMETH_SP = 3, // space(s) after the Method
- HTTP_MSG_RQURI = 4, // parsing the Request URI
- HTTP_MSG_RQURI_SP = 5, // space(s) after the Request URI
- HTTP_MSG_RQVER = 6, // parsing the Request Version
- HTTP_MSG_RQLINE_END = 7, // end of request line (CR or LF)
-
- HTTP_MSG_RPBEFORE = 8, // response: leading LF, before start line
- HTTP_MSG_RPBEFORE_CR = 9, // response: leading CRLF, before start line
-
- /* these ones define a response start line */
- HTTP_MSG_RPVER = 10, // parsing the Response Version
- HTTP_MSG_RPVER_SP = 11, // space(s) after the Response Version
- HTTP_MSG_RPCODE = 12, // response code
- HTTP_MSG_RPCODE_SP = 13, // space(s) after the response code
- HTTP_MSG_RPREASON = 14, // response reason
- HTTP_MSG_RPLINE_END = 15, // end of response line (CR or LF)
-
- /* common header processing */
- HTTP_MSG_HDR_FIRST = 16, // waiting for first header or last CRLF (no LWS possible)
- HTTP_MSG_HDR_NAME = 17, // parsing header name
- HTTP_MSG_HDR_COL = 18, // parsing header colon
- HTTP_MSG_HDR_L1_SP = 19, // parsing header LWS (SP|HT) before value
- HTTP_MSG_HDR_L1_LF = 20, // parsing header LWS (LF) before value
- HTTP_MSG_HDR_L1_LWS = 21, // checking whether it's a new header or an LWS
- HTTP_MSG_HDR_VAL = 22, // parsing header value
- HTTP_MSG_HDR_L2_LF = 23, // parsing header LWS (LF) inside/after value
- HTTP_MSG_HDR_L2_LWS = 24, // checking whether it's a new header or an LWS
-
- HTTP_MSG_LAST_LF = 25, // parsing last LF
-
- /* error state : must be before HTTP_MSG_BODY so that (>=BODY) always indicates
- * that data are being processed.
- */
- HTTP_MSG_ERROR = 26, // an error occurred
- /* Body processing.
- * The state HTTP_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.
- */
- HTTP_MSG_BODY = 27, // parsing body at end of headers
- HTTP_MSG_100_SENT = 28, // parsing body after a 100-Continue was sent
- HTTP_MSG_CHUNK_SIZE = 29, // parsing the chunk size (RFC7230 #4.1)
- HTTP_MSG_DATA = 30, // skipping data chunk / content-length data
- HTTP_MSG_CHUNK_CRLF = 31, // skipping CRLF after data chunk
- HTTP_MSG_TRAILERS = 32, // trailers (post-data entity headers)
- /* we enter this state when we've received the end of the current message */
- HTTP_MSG_ENDING = 33, // message end received, wait that the filters end too
- HTTP_MSG_DONE = 34, // message end received, waiting for resync or close
- HTTP_MSG_CLOSING = 35, // shutdown_w done, not all bytes sent yet
- HTTP_MSG_CLOSED = 36, // shutdown_w done, all bytes sent
- HTTP_MSG_TUNNEL = 37, // tunneled data after DONE
-} __attribute__((packed));
-
/*
* HTTP message status flags (msg->flags)
*/
@@ -323,8 +265,8 @@
* care for wrapping (no addition overflow nor subtract underflow).
*/
struct http_msg {
- enum ht_state msg_state; /* where we are in the current message parsing */
- enum ht_state err_state; /* the state where the parsing error was detected, only is MSG_ERROR */
+ enum h1_state msg_state; /* where we are in the current message parsing */
+ enum h1_state err_state; /* the state where the parsing error was detected, only is MSG_ERROR */
unsigned char flags; /* flags describing the message (HTTP version, ...) */
/* 5 bytes unused here */
struct channel *chn; /* pointer to the channel transporting the message */