Skip to content

Commit

Permalink
HTTP/1.1 conversion host name fix (#466)
Browse files Browse the repository at this point in the history
Co-authored-by: hadif <[email protected]>
  • Loading branch information
hadifrohar and chkp-hadif authored May 31, 2023
1 parent 8fb7e2c commit cdb206d
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/liblsquic/lsquic_http1x_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cdb206d

Please sign in to comment.