diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d55d8d1..4499d432d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ SPDX-License-Identifier: GPL-3.0-or-later - irc: fix warning on creation of irc.msgbuffer option when the server name contains upper case letters ([#2281](https://github.com/weechat/weechat/issues/2281)) - irc: display a warning for each unknown or invalid server option in commands /connect and /server - relay/api: fix crash when an invalid HTTP request is received from a client +- relay/api: return HTTP error 404 instead of 400 when the buffer is not found in resources completion and input ## Version 4.7.1 (2025-08-16) diff --git a/src/plugins/relay/api/relay-api-protocol.c b/src/plugins/relay/api/relay-api-protocol.c index 38428f178..4e318a33a 100644 --- a/src/plugins/relay/api/relay-api-protocol.c +++ b/src/plugins/relay/api/relay-api-protocol.c @@ -797,7 +797,7 @@ RELAY_API_PROTOCOL_CALLBACK(input) { relay_api_msg_send_error_json ( client, - RELAY_HTTP_400_BAD_REQUEST, NULL, + RELAY_HTTP_404_NOT_FOUND, NULL, "Buffer \"%s\" not found", ptr_buffer_name); cJSON_Delete (json_body); @@ -819,7 +819,7 @@ RELAY_API_PROTOCOL_CALLBACK(input) { relay_api_msg_send_error_json ( client, - RELAY_HTTP_400_BAD_REQUEST, NULL, + RELAY_HTTP_404_NOT_FOUND, NULL, "Buffer \"%lld\" not found", (long long)cJSON_GetNumberValue (json_buffer_id)); cJSON_Delete (json_body); @@ -924,7 +924,7 @@ RELAY_API_PROTOCOL_CALLBACK(completion) { relay_api_msg_send_error_json ( client, - RELAY_HTTP_400_BAD_REQUEST, NULL, + RELAY_HTTP_404_NOT_FOUND, NULL, "Buffer \"%s\" not found", ptr_buffer_name); cJSON_Delete (json_body); @@ -946,7 +946,7 @@ RELAY_API_PROTOCOL_CALLBACK(completion) { relay_api_msg_send_error_json ( client, - RELAY_HTTP_400_BAD_REQUEST, NULL, + RELAY_HTTP_404_NOT_FOUND, NULL, "Buffer \"%lld\" not found", (long long)cJSON_GetNumberValue (json_buffer_id)); cJSON_Delete (json_body); diff --git a/src/plugins/relay/api/weechat-relay-api.yaml b/src/plugins/relay/api/weechat-relay-api.yaml index 06e61cacf..cb15c671f 100644 --- a/src/plugins/relay/api/weechat-relay-api.yaml +++ b/src/plugins/relay/api/weechat-relay-api.yaml @@ -614,6 +614,12 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' + '404': + description: Buffer not found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' security: - password: [] /completion: @@ -677,6 +683,12 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' + '404': + description: Buffer not found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' security: - password: [] /ping: diff --git a/tests/unit/plugins/relay/api/test-relay-api-protocol.cpp b/tests/unit/plugins/relay/api/test-relay-api-protocol.cpp index 08f55daa9..4430319e9 100644 --- a/tests/unit/plugins/relay/api/test-relay-api-protocol.cpp +++ b/tests/unit/plugins/relay/api/test-relay-api-protocol.cpp @@ -622,7 +622,6 @@ TEST(RelayApiProtocolWithClient, CbCompletion) /* error: no body */ test_client_recv_http ("POST /api/completion", NULL, NULL); - WEE_CHECK_HTTP_CODE(400, "Bad Request"); STRCMP_EQUAL("HTTP/1.1 400 Bad Request\r\n" "Access-Control-Allow-Origin: *\r\n" "Content-Type: application/json; charset=utf-8\r\n" @@ -636,8 +635,7 @@ TEST(RelayApiProtocolWithClient, CbCompletion) NULL, "{\"buffer_name\": \"invalid\", " "\"command\": \"test\"}"); - WEE_CHECK_HTTP_CODE(400, "Bad Request"); - STRCMP_EQUAL("HTTP/1.1 400 Bad Request\r\n" + STRCMP_EQUAL("HTTP/1.1 404 Not Found\r\n" "Access-Control-Allow-Origin: *\r\n" "Content-Type: application/json; charset=utf-8\r\n" "Content-Length: 40\r\n" @@ -717,7 +715,7 @@ TEST(RelayApiProtocolWithClient, CbInput) NULL, "{\"buffer_name\": \"invalid\", " "\"command\": \"/print test\"}"); - STRCMP_EQUAL("HTTP/1.1 400 Bad Request\r\n" + STRCMP_EQUAL("HTTP/1.1 404 Not Found\r\n" "Access-Control-Allow-Origin: *\r\n" "Content-Type: application/json; charset=utf-8\r\n" "Content-Length: 40\r\n"