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
This commit is contained in:
Badlop 2023-11-30 12:38:46 +01:00
parent d570870be5
commit 9f42f17088
1 changed files with 2 additions and 2 deletions

View File

@ -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