From cdb206d29f9fe419d46f9ca8a2b29ebae446d080 Mon Sep 17 00:00:00 2001 From: Hadi Frohar <46677591+hadifrohar@users.noreply.github.com> Date: Wed, 31 May 2023 23:45:24 +0300 Subject: [PATCH] HTTP/1.1 conversion host name fix (#466) Co-authored-by: hadif --- src/liblsquic/lsquic_http1x_if.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/liblsquic/lsquic_http1x_if.c b/src/liblsquic/lsquic_http1x_if.c index 77e78b4..ce8e2e6 100644 --- a/src/liblsquic/lsquic_http1x_if.c +++ b/src/liblsquic/lsquic_http1x_if.c @@ -61,6 +61,9 @@ struct header_writer_ctx #define HWC_PSEH_VAL(hwc, ph) ((hwc)->pseh_bufs[ph]) +/* flags for frames with request headers */ +#define HWC_REQUEST_HANDLING_FLAGS (HWC_SERVER|HWC_PUSH_PROMISE) + static void * h1h_create_header_set (void *ctx, lsquic_stream_t *stream, int is_push_promise) { @@ -396,7 +399,15 @@ add_real_header (struct header_writer_ctx *hwc, struct lsxpack_header *xhdr) val_len = xhdr->val_len; if (4 == name_len && 0 == memcmp(name, "host", 4)) + { + if(hwc->pseh_mask & BIT(PSEH_AUTHORITY)) + { + LSQ_INFO("authority header was sent. ignoring host header with value `%.*s'", val_len, val); + return 0; + } + hwc->hwc_flags |= HWC_SEEN_HOST; + } n_upper = 0; for (i = 0; i < name_len; ++i) @@ -469,15 +480,22 @@ h1h_finish_hset (struct header_writer_ctx *hwc) return st; \ } while (0) - if ((hwc->pseh_mask & BIT(PSEH_AUTHORITY)) && - 0 == (hwc->hwc_flags & HWC_SEEN_HOST)) + if(0 == (hwc->hwc_flags & HWC_SEEN_HOST) && 0 != (hwc->hwc_flags & HWC_REQUEST_HANDLING_FLAGS)) { - LSQ_DEBUG("Setting 'Host: %.*s'", HWC_PSEH_LEN(hwc, PSEH_AUTHORITY), + if((hwc->pseh_mask & BIT(PSEH_AUTHORITY))) + { + LSQ_DEBUG("Setting 'Host: %.*s'", HWC_PSEH_LEN(hwc, PSEH_AUTHORITY), HWC_PSEH_VAL(hwc, PSEH_AUTHORITY)); - HWC_UH_WRITE(hwc, "Host: ", 6); - HWC_UH_WRITE(hwc, HWC_PSEH_VAL(hwc, PSEH_AUTHORITY), - HWC_PSEH_LEN(hwc, PSEH_AUTHORITY)); - HWC_UH_WRITE(hwc, "\r\n", 2); + HWC_UH_WRITE(hwc, "Host: ", 6); + HWC_UH_WRITE(hwc, HWC_PSEH_VAL(hwc, PSEH_AUTHORITY), + HWC_PSEH_LEN(hwc, PSEH_AUTHORITY)); + HWC_UH_WRITE(hwc, "\r\n", 2); + } + else + { + LSQ_INFO("both host header and authority pseudo header were not found"); + return 1; + } } if (hwc->cookie_val)