"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/h2.c" between
haproxy-1.9.3.tar.gz and haproxy-1.9.4.tar.gz

About: HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments.

h2.c  (haproxy-1.9.3):h2.c  (haproxy-1.9.4)
skipping to change at line 34 skipping to change at line 34
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <stdint.h> #include <stdint.h>
#include <common/config.h> #include <common/config.h>
#include <common/h2.h> #include <common/h2.h>
#include <common/http-hdr.h> #include <common/http-hdr.h>
#include <common/ist.h> #include <common/ist.h>
struct h2_frame_definition h2_frame_definition[H2_FT_ENTRIES] = {
[H2_FT_DATA ] = { .dir = 3, .min_id = 1, .max_id = H2_MAX_STREAM
_ID, .min_len = 0, .max_len = H2_MAX_FRAME_LEN, },
[H2_FT_HEADERS ] = { .dir = 3, .min_id = 1, .max_id = H2_MAX_STREAM
_ID, .min_len = 1, .max_len = H2_MAX_FRAME_LEN, },
[H2_FT_PRIORITY ] = { .dir = 3, .min_id = 1, .max_id = H2_MAX_STREAM
_ID, .min_len = 5, .max_len = 5, },
[H2_FT_RST_STREAM ] = { .dir = 3, .min_id = 1, .max_id = H2_MAX_STREAM
_ID, .min_len = 4, .max_len = 4, },
[H2_FT_SETTINGS ] = { .dir = 3, .min_id = 0, .max_id = 0,
.min_len = 0, .max_len = H2_MAX_FRAME_LEN, },
[H2_FT_PUSH_PROMISE ] = { .dir = 0, .min_id = 1, .max_id = H2_MAX_STREAM
_ID, .min_len = 4, .max_len = H2_MAX_FRAME_LEN, },
[H2_FT_PING ] = { .dir = 3, .min_id = 0, .max_id = 0,
.min_len = 8, .max_len = 8, },
[H2_FT_GOAWAY ] = { .dir = 3, .min_id = 0, .max_id = 0,
.min_len = 8, .max_len = H2_MAX_FRAME_LEN, },
[H2_FT_WINDOW_UPDATE] = { .dir = 3, .min_id = 0, .max_id = H2_MAX_STREAM
_ID, .min_len = 4, .max_len = 4, },
[H2_FT_CONTINUATION ] = { .dir = 3, .min_id = 1, .max_id = H2_MAX_STREAM
_ID, .min_len = 0, .max_len = H2_MAX_FRAME_LEN, },
};
/* Prepare the request line into <*ptr> (stopping at <end>) from pseudo headers /* Prepare the request line into <*ptr> (stopping at <end>) from pseudo headers
* stored in <phdr[]>. <fields> indicates what was found so far. This should be * stored in <phdr[]>. <fields> indicates what was found so far. This should be
* called once at the detection of the first general header field or at the end * called once at the detection of the first general header field or at the end
* of the request if no general header field was found yet. Returns 0 on success * of the request if no general header field was found yet. Returns 0 on success
* or a negative error code on failure. Upon success, <msgf> is updated with a * or a negative error code on failure. Upon success, <msgf> is updated with a
* few H2_MSGF_* flags indicating what was found while parsing. * few H2_MSGF_* flags indicating what was found while parsing.
*/ */
static int h2_prepare_h1_reqline(uint32_t fields, struct ist *phdr, char **ptr, char *end, unsigned int *msgf) static int h2_prepare_h1_reqline(uint32_t fields, struct ist *phdr, char **ptr, char *end, unsigned int *msgf)
{ {
char *out = *ptr; char *out = *ptr;
skipping to change at line 132 skipping to change at line 145
* - n.name != NULL, n.len > 0 : literal header name * - n.name != NULL, n.len > 0 : literal header name
* - n.name == NULL, n.len > 0 : indexed pseudo header name number <n.len> * - n.name == NULL, n.len > 0 : indexed pseudo header name number <n.len>
* among H2_PHDR_IDX_* * among H2_PHDR_IDX_*
* - n.name ignored, n.len == 0 : end of list * - n.name ignored, n.len == 0 : end of list
* - in all cases except the end of list, v.name and v.len must designate a * - in all cases except the end of list, v.name and v.len must designate a
* valid value. * valid value.
* *
* The Cookie header will be reassembled at the end, and for this, the <list> * The Cookie header will be reassembled at the end, and for this, the <list>
* will be used to create a linked list, so its contents may be destroyed. * will be used to create a linked list, so its contents may be destroyed.
*/ */
int h2_make_h1_request(struct http_hdr *list, char *out, int osize, unsigned int *msgf) int h2_make_h1_request(struct http_hdr *list, char *out, int osize, unsigned int *msgf, unsigned long long *body_len)
{ {
struct ist phdr_val[H2_PHDR_NUM_ENTRIES]; struct ist phdr_val[H2_PHDR_NUM_ENTRIES];
char *out_end = out + osize; char *out_end = out + osize;
uint32_t fields; /* bit mask of H2_PHDR_FND_* */ uint32_t fields; /* bit mask of H2_PHDR_FND_* */
uint32_t idx; uint32_t idx;
int ck, lck; /* cookie index and last cookie index */ int ck, lck; /* cookie index and last cookie index */
int phdr; int phdr;
int ret; int ret;
int i; int i;
skipping to change at line 193 skipping to change at line 206
/* no more pseudo-headers, time to build the request line */ /* no more pseudo-headers, time to build the request line */
ret = h2_prepare_h1_reqline(fields, phdr_val, &out, out_e nd, msgf); ret = h2_prepare_h1_reqline(fields, phdr_val, &out, out_e nd, msgf);
if (ret != 0) if (ret != 0)
goto leave; goto leave;
fields |= H2_PHDR_FND_NONE; fields |= H2_PHDR_FND_NONE;
} }
if (isteq(list[idx].n, ist("host"))) if (isteq(list[idx].n, ist("host")))
fields |= H2_PHDR_FND_HOST; fields |= H2_PHDR_FND_HOST;
if ((*msgf & (H2_MSGF_BODY|H2_MSGF_BODY_TUNNEL|H2_MSGF_BODY_CL)) if (isteq(list[idx].n, ist("content-length"))) {
== H2_MSGF_BODY && ret = h2_parse_cont_len_header(msgf, &list[idx].v, body_l
isteq(list[idx].n, ist("content-length"))) en);
*msgf |= H2_MSGF_BODY_CL; if (ret < 0)
goto fail;
if (ret == 0)
continue; // skip this duplicate
}
/* these ones are forbidden in requests (RFC7540#8.1.2.2) */ /* these ones are forbidden in requests (RFC7540#8.1.2.2) */
if (isteq(list[idx].n, ist("connection")) || if (isteq(list[idx].n, ist("connection")) ||
isteq(list[idx].n, ist("proxy-connection")) || isteq(list[idx].n, ist("proxy-connection")) ||
isteq(list[idx].n, ist("keep-alive")) || isteq(list[idx].n, ist("keep-alive")) ||
isteq(list[idx].n, ist("upgrade")) || isteq(list[idx].n, ist("upgrade")) ||
isteq(list[idx].n, ist("transfer-encoding"))) isteq(list[idx].n, ist("transfer-encoding")))
goto fail; goto fail;
if (isteq(list[idx].n, ist("te")) && !isteq(list[idx].v, ist("tra ilers"))) if (isteq(list[idx].n, ist("te")) && !isteq(list[idx].v, ist("tra ilers")))
skipping to change at line 558 skipping to change at line 576
* - n.name != NULL, n.len > 0 : literal header name * - n.name != NULL, n.len > 0 : literal header name
* - n.name == NULL, n.len > 0 : indexed pseudo header name number <n.len> * - n.name == NULL, n.len > 0 : indexed pseudo header name number <n.len>
* among H2_PHDR_IDX_* * among H2_PHDR_IDX_*
* - n.name ignored, n.len == 0 : end of list * - n.name ignored, n.len == 0 : end of list
* - in all cases except the end of list, v.name and v.len must designate a * - in all cases except the end of list, v.name and v.len must designate a
* valid value. * valid value.
* *
* The Cookie header will be reassembled at the end, and for this, the <list> * The Cookie header will be reassembled at the end, and for this, the <list>
* will be used to create a linked list, so its contents may be destroyed. * will be used to create a linked list, so its contents may be destroyed.
*/ */
int h2_make_htx_request(struct http_hdr *list, struct htx *htx, unsigned int *ms gf) int h2_make_htx_request(struct http_hdr *list, struct htx *htx, unsigned int *ms gf, unsigned long long *body_len)
{ {
struct ist phdr_val[H2_PHDR_NUM_ENTRIES]; struct ist phdr_val[H2_PHDR_NUM_ENTRIES];
uint32_t fields; /* bit mask of H2_PHDR_FND_* */ uint32_t fields; /* bit mask of H2_PHDR_FND_* */
uint32_t idx; uint32_t idx;
int ck, lck; /* cookie index and last cookie index */ int ck, lck; /* cookie index and last cookie index */
int phdr; int phdr;
int ret; int ret;
int i; int i;
struct htx_sl *sl = NULL; struct htx_sl *sl = NULL;
unsigned int sl_flags = 0; unsigned int sl_flags = 0;
unsigned long long body_len;
lck = ck = -1; // no cookie for now lck = ck = -1; // no cookie for now
fields = 0; fields = 0;
for (idx = 0; list[idx].n.len != 0; idx++) { for (idx = 0; list[idx].n.len != 0; idx++) {
if (!list[idx].n.ptr) { if (!list[idx].n.ptr) {
/* this is an indexed pseudo-header */ /* this is an indexed pseudo-header */
phdr = list[idx].n.len; phdr = list[idx].n.len;
} }
else { else {
/* this can be any type of header */ /* this can be any type of header */
skipping to change at line 622 skipping to change at line 639
sl = h2_prepare_htx_reqline(fields, phdr_val, htx, msgf); sl = h2_prepare_htx_reqline(fields, phdr_val, htx, msgf);
if (!sl) if (!sl)
goto fail; goto fail;
fields |= H2_PHDR_FND_NONE; fields |= H2_PHDR_FND_NONE;
} }
if (isteq(list[idx].n, ist("host"))) if (isteq(list[idx].n, ist("host")))
fields |= H2_PHDR_FND_HOST; fields |= H2_PHDR_FND_HOST;
if (isteq(list[idx].n, ist("content-length"))) { if (isteq(list[idx].n, ist("content-length"))) {
ret = h2_parse_cont_len_header(msgf, &list[idx].v, &body_ len); ret = h2_parse_cont_len_header(msgf, &list[idx].v, body_l en);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
sl_flags |= HTX_SL_F_CLEN; sl_flags |= HTX_SL_F_CLEN;
if (ret == 0) if (ret == 0)
continue; // skip this duplicate continue; // skip this duplicate
} }
/* these ones are forbidden in requests (RFC7540#8.1.2.2) */ /* these ones are forbidden in requests (RFC7540#8.1.2.2) */
if (isteq(list[idx].n, ist("connection")) || if (isteq(list[idx].n, ist("connection")) ||
skipping to change at line 786 skipping to change at line 803
* if a body is detected (!ES). * if a body is detected (!ES).
* *
* The headers list <list> must be composed of : * The headers list <list> must be composed of :
* - n.name != NULL, n.len > 0 : literal header name * - n.name != NULL, n.len > 0 : literal header name
* - n.name == NULL, n.len > 0 : indexed pseudo header name number <n.len> * - n.name == NULL, n.len > 0 : indexed pseudo header name number <n.len>
* among H2_PHDR_IDX_* * among H2_PHDR_IDX_*
* - n.name ignored, n.len == 0 : end of list * - n.name ignored, n.len == 0 : end of list
* - in all cases except the end of list, v.name and v.len must designate a * - in all cases except the end of list, v.name and v.len must designate a
* valid value. * valid value.
*/ */
int h2_make_htx_response(struct http_hdr *list, struct htx *htx, unsigned int *m sgf) int h2_make_htx_response(struct http_hdr *list, struct htx *htx, unsigned int *m sgf, unsigned long long *body_len)
{ {
struct ist phdr_val[H2_PHDR_NUM_ENTRIES]; struct ist phdr_val[H2_PHDR_NUM_ENTRIES];
uint32_t fields; /* bit mask of H2_PHDR_FND_* */ uint32_t fields; /* bit mask of H2_PHDR_FND_* */
uint32_t idx; uint32_t idx;
int phdr; int phdr;
int ret; int ret;
int i; int i;
struct htx_sl *sl = NULL; struct htx_sl *sl = NULL;
unsigned int sl_flags = 0; unsigned int sl_flags = 0;
unsigned long long body_len;
fields = 0; fields = 0;
for (idx = 0; list[idx].n.len != 0; idx++) { for (idx = 0; list[idx].n.len != 0; idx++) {
if (!list[idx].n.ptr) { if (!list[idx].n.ptr) {
/* this is an indexed pseudo-header */ /* this is an indexed pseudo-header */
phdr = list[idx].n.len; phdr = list[idx].n.len;
} }
else { else {
/* this can be any type of header */ /* this can be any type of header */
/* RFC7540#8.1.2: upper case not allowed in header field names */ /* RFC7540#8.1.2: upper case not allowed in header field names */
skipping to change at line 845 skipping to change at line 861
/* regular header field in (name,value) */ /* regular header field in (name,value) */
if (!(fields & H2_PHDR_FND_NONE)) { if (!(fields & H2_PHDR_FND_NONE)) {
/* no more pseudo-headers, time to build the status line */ /* no more pseudo-headers, time to build the status line */
sl = h2_prepare_htx_stsline(fields, phdr_val, htx, msgf); sl = h2_prepare_htx_stsline(fields, phdr_val, htx, msgf);
if (!sl) if (!sl)
goto fail; goto fail;
fields |= H2_PHDR_FND_NONE; fields |= H2_PHDR_FND_NONE;
} }
if (isteq(list[idx].n, ist("content-length"))) { if (isteq(list[idx].n, ist("content-length"))) {
ret = h2_parse_cont_len_header(msgf, &list[idx].v, &body_ len); ret = h2_parse_cont_len_header(msgf, &list[idx].v, body_l en);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
sl_flags |= HTX_SL_F_CLEN; sl_flags |= HTX_SL_F_CLEN;
if (ret == 0) if (ret == 0)
continue; // skip this duplicate continue; // skip this duplicate
} }
/* these ones are forbidden in responses (RFC7540#8.1.2.2) */ /* these ones are forbidden in responses (RFC7540#8.1.2.2) */
if (isteq(list[idx].n, ist("connection")) || if (isteq(list[idx].n, ist("connection")) ||
 End of changes. 9 change blocks. 
11 lines changed or deleted 37 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)