diff --git a/include/common/h2.h b/include/common/h2.h index 6c1475bd9..e0684270c 100644 --- a/include/common/h2.h +++ b/include/common/h2.h @@ -31,8 +31,8 @@ #include #include +#include #include -#include /* indexes of most important pseudo headers can be simplified to an almost diff --git a/include/proto/htx.h b/include/common/htx.h similarity index 79% rename from include/proto/htx.h rename to include/common/htx.h index 3fd8fbab1..93031cd1f 100644 --- a/include/proto/htx.h +++ b/include/common/htx.h @@ -1,5 +1,5 @@ /* - * include/proto/hx.h + * include/common/htx.h * This file defines everything related to the internal HTTP messages. * * Copyright (C) 2018 HAProxy Technologies, Christopher Faulet @@ -19,14 +19,151 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _PROTO_HTX_H -#define _PROTO_HTX_H +#ifndef _COMMON_HTX_H +#define _COMMON_HTX_H +#include #include #include -#include +#include +#include #include -#include +#include + +/* + * The internal representation of an HTTP message is a contiguous array + * containing both the blocks (htx_blk) and their contents. Blocks are stored + * starting from the end of the array while their contents are stored at the + * beginning. + * + * As data are sent to the peer, blocks and contents are released at the + * edges. This free space is reused when no more space left. So blocks and + * contents may wrap, not necessarily the same time. + * + * An HTTP block is as well a header as a body part or a trailer part. For all + * these types of block, a content is attached to the block. It can also be a + * mark, like the end-of-headers or end-of-message. For these blocks, there is + * no content but it count for a byte. It is important to not skip it when data + * are forwarded. An HTTP block is composed of 2 fields: + * + * - .info : It a 32 bits field containing the block's type on 4 bits + * followed by content' length. See below for details. + * + * - .addr : The content's address, if any, relatively to the beginning the + * array used to store the HTTP message itself. + * + * htx_blk.info representation: + * + * 0b 0000 0000 0000 0000 0000 0000 0000 0000 + * ---- ------------------------ --------- + * type value (1 MB max) name length (header) + * ---------------------------------- + * data length (256 MB max) + * (body, method, path, version, status, reason, trailers) + * + * types: + * - 0000 = request start-line + * - 0001 = response start-line + * - 0010 = header + * - 0011 = pseudo-header ou "special" header + * - 0100 = end-of-headers + * - 0101 = data + * - 0110 = end-of-data + * - 0111 = trailer + * - 1000 = end-of-message + * ... + * - 1101 = out-of-band + * - 1110 = error + * - 1111 = unused + * + */ + +/*HTX start-line flags */ +#define HTX_SL_F_NONE 0x00000000 +#define HTX_SL_F_IS_RESP 0x00000001 /* It is the response start-line (unset means the request one) */ +#define HTX_SL_F_XFER_LEN 0x00000002 /* The message xfer size can be dertermined */ +#define HTX_SL_F_XFER_ENC 0x00000004 /* The transfer-encoding header was found in message */ +#define HTX_SL_F_CLEN 0x00000008 /* The content-length header was found in message */ +#define HTX_SL_F_CHNK 0x00000010 /* The message payload is chunked */ +#define HTX_SL_F_VER_11 0x00000020 /* The message indicates version 1.1 or above */ +#define HTX_SL_F_BODYLESS 0x00000040 /* The message has no body (content-length = 0) */ + +/* HTX flags */ +#define HTX_FL_NONE 0x00000000 +#define HTX_FL_PARSING_ERROR 0x00000001 + + +/* Pseudo header types (max 255). */ +enum htx_phdr_type { + HTX_PHDR_UNKNOWN = 0, + HTX_PHDR_SIZE, +}; + +/* HTTP block's type (max 15). */ +enum htx_blk_type { + HTX_BLK_REQ_SL = 0, /* Request start-line */ + HTX_BLK_RES_SL = 1, /* Response start-line */ + HTX_BLK_HDR = 2, /* header name/value block */ + HTX_BLK_PHDR = 3, /* pseudo header block */ + HTX_BLK_EOH = 4, /* end-of-headers block */ + HTX_BLK_DATA = 5, /* data block */ + HTX_BLK_EOD = 6, /* end-of-data block */ + HTX_BLK_TLR = 7, /* trailer name/value block */ + HTX_BLK_EOM = 8, /* end-of-message block */ + /* 9 .. 13 unused */ + HTX_BLK_OOB = 14, /* Out of band block, don't alter the parser */ + HTX_BLK_UNUSED = 15, /* unused/removed block */ +}; + +/* One HTTP block descriptor */ +struct htx_blk { + uint32_t addr; /* relative storage address of a data block */ + uint32_t info; /* information about data stored */ +}; + +struct htx_ret { + int32_t ret; + struct htx_blk *blk; +}; + +struct htx_sl { + unsigned int flags; /* HTX_SL_F_* */ + union { + struct { + enum http_meth_t meth; /* method */ + } req; + struct { + uint16_t status; /* status code */ + } res; + } info; + + /* XXX 2 bytes unused */ + + unsigned int len[3]; /* length of differnt parts of the start-line */ + char l[0]; +}; + +/* Internal representation of an HTTP message */ +struct htx { + uint32_t size; /* the array size, in bytes, used to store the HTTP message itself */ + uint32_t data; /* the data size, in bytes. To known to total size used by all allocated + * blocks (blocks and their contents), you need to add size used by blocks, + * i.e. [ used * sizeof(struct htx_blk *) ] */ + + uint32_t used; /* number of blocks in use */ + uint32_t tail; /* last inserted block */ + uint32_t front; /* block's position of the first content before the blocks table */ + uint32_t wrap; /* the position were the blocks table wraps, if any */ + + uint64_t extra; /* known bytes amount remaining to receive */ + uint32_t flags; /* HTX_FL_* */ + + int32_t sl_off; /* Offset of the start-line of the HTTP message relatively to the beginning the + data block. -1 if unset */ + + struct htx_blk blocks[0]; /* Blocks representing the HTTP message itself */ +}; + extern struct htx htx_empty; @@ -88,10 +225,10 @@ int htx_trailer_to_h1(const struct ist tlr, struct buffer *chk); #define HTX_SL_RES_CPTR(sl) HTX_SL_P2_PTR(sl) #define HTX_SL_RES_RPTR(sl) HTX_SL_P3_PTR(sl) - static inline const struct ist htx_sl_p1(const struct htx_sl *sl) - { - return ist2(HTX_SL_P1_PTR(sl), HTX_SL_P1_LEN(sl)); - } +static inline const struct ist htx_sl_p1(const struct htx_sl *sl) +{ + return ist2(HTX_SL_P1_PTR(sl), HTX_SL_P1_LEN(sl)); +} static inline const struct ist htx_sl_p2(const struct htx_sl *sl) { @@ -103,7 +240,6 @@ static inline const struct ist htx_sl_p3(const struct htx_sl *sl) return ist2(HTX_SL_P3_PTR(sl), HTX_SL_P3_LEN(sl)); } - static inline const struct ist htx_sl_req_meth(const struct htx_sl *sl) { return htx_sl_p1(sl); @@ -671,7 +807,7 @@ static inline void htx_dump(struct htx *htx) fprintf(stderr, "\n"); } -#endif /* _PROTO_HTX_H */ +#endif /* _COMMON_HTX_H */ /* * Local variables: diff --git a/include/proto/channel.h b/include/proto/channel.h index dd9b1afa2..5d9c7a8aa 100644 --- a/include/proto/channel.h +++ b/include/proto/channel.h @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -36,7 +37,6 @@ #include #include #include -#include #include diff --git a/include/types/http_htx.h b/include/types/http_htx.h index c8f4197d0..3f9a7f4b0 100644 --- a/include/types/http_htx.h +++ b/include/types/http_htx.h @@ -23,8 +23,8 @@ #ifndef _TYPES_HTTP_HTX_H #define _TYPES_HTTP_HTX_H +#include #include -#include /* Context used to find/remove an HTTP header. */ struct http_hdr_ctx { diff --git a/include/types/htx.h b/include/types/htx.h deleted file mode 100644 index 1146b9af4..000000000 --- a/include/types/htx.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * include/types/htx.h - * This file contains the internal HTTP definitions. - * - * Copyright (C) 2018 HAProxy Technologies, Christopher Faulet - * - * 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_HTX_H -#define _TYPES_HTX_H - -#include -#include - -/* - * The internal representation of an HTTP message is a contiguous array - * containing both the blocks (htx_blk) and their contents. Blocks are stored - * starting from the end of the array while their contents are stored at the - * beginning. - * - * As data are sent to the peer, blocks and contents are released at the - * edges. This free space is reused when no more space left. So blocks and - * contents may wrap, not necessarily the same time. - * - * An HTTP block is as well a header as a body part or a trailer part. For all - * these types of block, a content is attached to the block. It can also be a - * mark, like the end-of-headers or end-of-message. For these blocks, there is - * no content but it count for a byte. It is important to not skip it when data - * are forwarded. An HTTP block is composed of 2 fields: - * - * - .info : It a 32 bits field containing the block's type on 4 bits - * followed by content' length. See below for details. - * - * - .addr : The content's address, if any, relatively to the beginning the - * array used to store the HTTP message itself. - * - * htx_blk.info representation: - * - * 0b 0000 0000 0000 0000 0000 0000 0000 0000 - * ---- ------------------------ --------- - * type value (1 MB max) name length (header) - * ---------------------------------- - * data length (256 MB max) - * (body, method, path, version, status, reason, trailers) - * - * types: - * - 0000 = request start-line - * - 0001 = response start-line - * - 0010 = header - * - 0011 = pseudo-header ou "special" header - * - 0100 = end-of-headers - * - 0101 = data - * - 0110 = end-of-data - * - 0111 = trailer - * - 1000 = end-of-message - * ... - * - 1101 = out-of-band - * - 1110 = error - * - 1111 = unused - * - */ - -/*HTX start-line flags */ -#define HTX_SL_F_NONE 0x00000000 -#define HTX_SL_F_IS_RESP 0x00000001 /* It is the response start-line (unset means the request one) */ -#define HTX_SL_F_XFER_LEN 0x00000002 /* The message xfer size can be dertermined */ -#define HTX_SL_F_XFER_ENC 0x00000004 /* The transfer-encoding header was found in message */ -#define HTX_SL_F_CLEN 0x00000008 /* The content-length header was found in message */ -#define HTX_SL_F_CHNK 0x00000010 /* The message payload is chunked */ -#define HTX_SL_F_VER_11 0x00000020 /* The message indicates version 1.1 or above */ -#define HTX_SL_F_BODYLESS 0x00000040 /* The message has no body (content-length = 0) */ - -/* HTX flags */ -#define HTX_FL_NONE 0x00000000 -#define HTX_FL_PARSING_ERROR 0x00000001 - - -/* Pseudo header types (max 255). */ -enum htx_phdr_type { - HTX_PHDR_UNKNOWN = 0, - HTX_PHDR_SIZE, -}; - -/* HTTP block's type (max 15). */ -enum htx_blk_type { - HTX_BLK_REQ_SL = 0, /* Request start-line */ - HTX_BLK_RES_SL = 1, /* Response start-line */ - HTX_BLK_HDR = 2, /* header name/value block */ - HTX_BLK_PHDR = 3, /* pseudo header block */ - HTX_BLK_EOH = 4, /* end-of-headers block */ - HTX_BLK_DATA = 5, /* data block */ - HTX_BLK_EOD = 6, /* end-of-data block */ - HTX_BLK_TLR = 7, /* trailer name/value block */ - HTX_BLK_EOM = 8, /* end-of-message block */ - /* 9 .. 13 unused */ - HTX_BLK_OOB = 14, /* Out of band block, don't alter the parser */ - HTX_BLK_UNUSED = 15, /* unused/removed block */ -}; - -/* One HTTP block descriptor */ -struct htx_blk { - uint32_t addr; /* relative storage address of a data block */ - uint32_t info; /* information about data stored */ -}; - -struct htx_ret { - int32_t ret; - struct htx_blk *blk; -}; - -struct htx_sl { - unsigned int flags; /* HTX_SL_F_* */ - union { - struct { - enum http_meth_t meth; /* method */ - } req; - struct { - uint16_t status; /* status code */ - } res; - } info; - - /* XXX 2 bytes unused */ - - unsigned int len[3]; /* length of differnt parts of the start-line */ - char l[0]; -}; - -/* Internal representation of an HTTP message */ -struct htx { - uint32_t size; /* the array size, in bytes, used to store the HTTP message itself */ - uint32_t data; /* the data size, in bytes. To known to total size used by all allocated - * blocks (blocks and their contents), you need to add size used by blocks, - * i.e. [ used * sizeof(struct htx_blk *) ] */ - - uint32_t used; /* number of blocks in use */ - uint32_t tail; /* last inserted block */ - uint32_t front; /* block's position of the first content before the blocks table */ - uint32_t wrap; /* the position were the blocks table wraps, if any */ - - uint64_t extra; /* known bytes amount remaining to receive */ - uint32_t flags; /* HTX_FL_* */ - - int32_t sl_off; /* Offset of the start-line of the HTTP message relatively to the beginning the - data block. -1 if unset */ - - struct htx_blk blocks[0]; /* Blocks representing the HTTP message itself */ -}; - -#endif /* _TYPES_HTX_H */ - -/* - * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * End: - */ diff --git a/src/cache.c b/src/cache.c index 407d150f9..9cfb5350b 100644 --- a/src/cache.c +++ b/src/cache.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -36,6 +35,7 @@ #include #include +#include #include /* flt_cache_store */ diff --git a/src/filters.c b/src/filters.c index d082261b5..4f3fae7e3 100644 --- a/src/filters.c +++ b/src/filters.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -28,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index 2d1a7fd42..aaab32e72 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/src/flt_trace.c b/src/flt_trace.c index 0ccf1fc3f..1daeb22b9 100644 --- a/src/flt_trace.c +++ b/src/flt_trace.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -28,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/src/http_fetch.c b/src/http_fetch.c index 5f579d1f1..995622b06 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/src/http_htx.c b/src/http_htx.c index 83768f6fb..401e7f1b5 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -13,10 +13,10 @@ #include #include #include +#include #include #include -#include struct buffer htx_err_chunks[HTTP_ERR_SIZE]; diff --git a/src/htx.c b/src/htx.c index 78bfd5772..bda293b43 100644 --- a/src/htx.c +++ b/src/htx.c @@ -11,7 +11,7 @@ */ #include -#include +#include struct htx htx_empty = { .size = 0, .data = 0, .used = 0 }; diff --git a/src/mux_h1.c b/src/mux_h1.c index fa3ffa8d0..037b239e0 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -11,6 +11,7 @@ */ #include #include +#include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/src/mux_h2.c b/src/mux_h2.c index 15fd304cf..8962be8c8 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -16,12 +16,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include diff --git a/src/proto_htx.c b/src/proto_htx.c index 2ba383e3b..6c637cb83 100644 --- a/src/proto_htx.c +++ b/src/proto_htx.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/src/stats.c b/src/stats.c index c85d411d4..be70dde3a 100644 --- a/src/stats.c +++ b/src/stats.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -54,7 +55,6 @@ #include #include #include -#include #include #include #include diff --git a/src/stream.c b/src/stream.c index d79f86c72..7add3dcc9 100644 --- a/src/stream.c +++ b/src/stream.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -46,7 +47,6 @@ #include #include #include -#include #include #include #include