Skip to content

Commit 143c4e0

Browse files
rluboskartben
authored andcommitted
net: http_server: Add support for HTTP2 405 error
HTTP2 should reply with 405 Method Not Allowed error the same way as HTTP1 does. Signed-off-by: Robert Lubos <[email protected]>
1 parent 4063913 commit 143c4e0

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

subsys/net/lib/http/http_server_http2.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,22 @@ static int send_http2_404(struct http_client_ctx *client,
339339
return ret;
340340
}
341341

342+
static int send_http2_405(struct http_client_ctx *client,
343+
struct http2_frame *frame)
344+
{
345+
int ret;
346+
347+
ret = send_headers_frame(client, HTTP_405_METHOD_NOT_ALLOWED,
348+
frame->stream_identifier, NULL,
349+
HTTP2_FLAG_END_STREAM, NULL, 0);
350+
if (ret < 0) {
351+
LOG_DBG("Cannot write to socket (%d)", ret);
352+
return ret;
353+
}
354+
355+
return ret;
356+
}
357+
342358
static int send_http2_409(struct http_client_ctx *client,
343359
struct http2_frame *frame)
344360
{
@@ -361,8 +377,8 @@ static int handle_http2_static_resource(
361377
size_t content_len;
362378
int ret;
363379

364-
if (!(static_detail->common.bitmask_of_supported_http_methods & BIT(HTTP_GET))) {
365-
return -ENOTSUP;
380+
if (client->method != HTTP_GET) {
381+
return send_http2_405(client, frame);
366382
}
367383

368384
if (client->current_stream == NULL) {
@@ -413,8 +429,8 @@ static int handle_http2_static_fs_resource(struct http_resource_detail_static_fs
413429
int remaining;
414430
char tmp[64];
415431

416-
if (!(static_fs_detail->common.bitmask_of_supported_http_methods & BIT(HTTP_GET))) {
417-
return -ENOTSUP;
432+
if (client->method != HTTP_GET) {
433+
return send_http2_405(client, frame);
418434
}
419435

420436
if (client->current_stream == NULL) {
@@ -715,7 +731,7 @@ static int handle_http2_dynamic_resource(
715731
user_method = dynamic_detail->common.bitmask_of_supported_http_methods;
716732

717733
if (!(BIT(client->method) & user_method)) {
718-
return -ENOPROTOOPT;
734+
return send_http2_405(client, frame);
719735
}
720736

721737
if (dynamic_detail->holder != NULL && dynamic_detail->holder != client) {

0 commit comments

Comments
 (0)