Skip to content

Commit

Permalink
http: Fix WebSockets with Firefox
Browse files Browse the repository at this point in the history
Firefox (going back a couple of years at least) was unable to open a
WebSocket connection to Unit due to it sending a Connection header of

  Connection: keep-alive, Upgrade

However in Unit we were expecting only a single value in the header.

Fix the 'Connection' parsing in nxt_h1p_connection() to address this.

Closes: #772
Signed-off-by: Andrew Clayton <[email protected]>
  • Loading branch information
ac000 committed Feb 10, 2025
1 parent b286640 commit df62a2a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/nxt_h1proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,24 +759,23 @@ nxt_h1p_header_buffer_test(nxt_task_t *task, nxt_h1proto_t *h1p, nxt_conn_t *c,
static nxt_int_t
nxt_h1p_connection(void *ctx, nxt_http_field_t *field, uintptr_t data)
{
const u_char *end;
nxt_http_request_t *r;

r = ctx;
field->hopbyhop = 1;

if (field->value_length == 5
&& nxt_memcasecmp(field->value, "close", 5) == 0)
{
end = field->value + field->value_length;

if (nxt_memcasestrn(field->value, end, "close", 5) != NULL) {
r->proto.h1->keepalive = 0;
}

} else if (field->value_length == 10
&& nxt_memcasecmp(field->value, "keep-alive", 10) == 0)
{
if (nxt_memcasestrn(field->value, end, "keep-alive", 10) != NULL) {
r->proto.h1->keepalive = 1;
}

} else if (field->value_length == 7
&& nxt_memcasecmp(field->value, "upgrade", 7) == 0)
{
if (nxt_memcasestrn(field->value, end, "upgrade", 7) != NULL) {
r->proto.h1->connection_upgrade = 1;
}

Expand Down

0 comments on commit df62a2a

Please sign in to comment.