From 9f42f170886cc04af490202418e77240fef1f605 Mon Sep 17 00:00:00 2001 From: Badlop Date: Thu, 30 Nov 2023 12:38:46 +0100 Subject: [PATCH] mod_http_api: Fix to allow the client override the API version When configured like: listen: - request_handlers: /api: mod_http_api /apizero/v0: mod_http_api What API version will be used depending on the URL: - api/commandname use the latest available version - api/commandname/v0 use version 0 - apizero/v0/commandname use version 0 - apizero/v0/commandname/v2 use version 2 --- src/mod_http_api.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod_http_api.erl b/src/mod_http_api.erl index 801286000..c6a969091 100644 --- a/src/mod_http_api.erl +++ b/src/mod_http_api.erl @@ -135,7 +135,7 @@ extract_auth(#request{auth = HTTPAuth, ip = {IP, _}, opts = Opts}) -> process(_, #request{method = 'POST', data = <<>>}) -> ?DEBUG("Bad Request: no data", []), badrequest_response(<<"Missing POST data">>); -process([Call], #request{method = 'POST', data = Data, ip = IPPort} = Req) -> +process([Call | _], #request{method = 'POST', data = Data, ip = IPPort} = Req) -> Version = get_api_version(Req), try Args = extract_args(Data), @@ -153,7 +153,7 @@ process([Call], #request{method = 'POST', data = Data, ip = IPPort} = Req) -> ?DEBUG("Bad Request: ~p ~p", [_Error, StackTrace]), badrequest_response() end; -process([Call], #request{method = 'GET', q = Data, ip = {IP, _}} = Req) -> +process([Call | _], #request{method = 'GET', q = Data, ip = {IP, _}} = Req) -> Version = get_api_version(Req), try Args = case Data of