HTTP/1.1 conversion host name fix (#466)

Co-authored-by: hadif <hadif@checkpoint.com>
This commit is contained in:
Hadi Frohar 2023-05-31 23:45:24 +03:00 committed by GitHub
parent 8fb7e2c02c
commit cdb206d29f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -61,6 +61,9 @@ struct header_writer_ctx
#define HWC_PSEH_VAL(hwc, ph) ((hwc)->pseh_bufs[ph]) #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 * static void *
h1h_create_header_set (void *ctx, lsquic_stream_t *stream, int is_push_promise) 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; val_len = xhdr->val_len;
if (4 == name_len && 0 == memcmp(name, "host", 4)) 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; hwc->hwc_flags |= HWC_SEEN_HOST;
}
n_upper = 0; n_upper = 0;
for (i = 0; i < name_len; ++i) for (i = 0; i < name_len; ++i)
@ -469,8 +480,9 @@ h1h_finish_hset (struct header_writer_ctx *hwc)
return st; \ return st; \
} while (0) } while (0)
if ((hwc->pseh_mask & BIT(PSEH_AUTHORITY)) && if(0 == (hwc->hwc_flags & HWC_SEEN_HOST) && 0 != (hwc->hwc_flags & HWC_REQUEST_HANDLING_FLAGS))
0 == (hwc->hwc_flags & HWC_SEEN_HOST)) {
if((hwc->pseh_mask & BIT(PSEH_AUTHORITY)))
{ {
LSQ_DEBUG("Setting 'Host: %.*s'", HWC_PSEH_LEN(hwc, PSEH_AUTHORITY), LSQ_DEBUG("Setting 'Host: %.*s'", HWC_PSEH_LEN(hwc, PSEH_AUTHORITY),
HWC_PSEH_VAL(hwc, PSEH_AUTHORITY)); HWC_PSEH_VAL(hwc, PSEH_AUTHORITY));
@ -479,6 +491,12 @@ h1h_finish_hset (struct header_writer_ctx *hwc)
HWC_PSEH_LEN(hwc, PSEH_AUTHORITY)); HWC_PSEH_LEN(hwc, PSEH_AUTHORITY));
HWC_UH_WRITE(hwc, "\r\n", 2); 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) if (hwc->cookie_val)
{ {