Skip to content

Commit 9a00bc6

Browse files
rluboskartben
authored andcommitted
net: http_client: Ignore message body on 101 Switching Protocols reply
When HTTP 101 Switching Protocols response is received, force the HTTP parser to ignore any potential message body payload (which should already belong to the new protocol). This is usually not an issue, as Switching Protocols reply should contain headers only, however it's been observed that some servers specify chunked transfer-encoding header which tricks the parser to wait for payload event though it never arrives. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent 037cb87 commit 9a00bc6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

subsys/net/lib/http/http_client.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ LOG_MODULE_REGISTER(net_http_client, CONFIG_NET_HTTP_LOG_LEVEL);
2323
#include <zephyr/net/net_ip.h>
2424
#include <zephyr/net/socket.h>
2525
#include <zephyr/net/http/client.h>
26+
#include <zephyr/net/http/status.h>
2627

2728
#include "net_private.h"
2829

@@ -327,6 +328,11 @@ static int on_headers_complete(struct http_parser *parser)
327328
req->internal.response.http_cb->on_headers_complete(parser);
328329
}
329330

331+
if (parser->status_code == HTTP_101_SWITCHING_PROTOCOLS) {
332+
NET_DBG("Switching protocols, skipping body");
333+
return 1;
334+
}
335+
330336
if (parser->status_code >= 500 && parser->status_code < 600) {
331337
NET_DBG("Status %d, skipping body", parser->status_code);
332338
return 1;

0 commit comments

Comments
 (0)