c++oat++

Oat++ No mapping for HTTP-method


I am building an endpoint that requires 2 query parameters: email_address and token, the issue I am seeing is that when I make the following call from Postman every other click is an error:

http://localhost:8000/handshake/is_valid_user_token?param=p

The error message:

server=oatpp/1.3.0
code=404
description=Not Found
message=No mapping for HTTP-method: '{', URL: ''

Code:

ENDPOINT("POST", "handshake/is_valid_user_token/*", isValidUserToken,
       REQUEST(std::shared_ptr<IncomingRequest>, request))
{
    auto tail = request->getPathTail();
    auto queryParams = oatpp::network::Url::Parser::parseQueryParams(tail);

    auto emailAddress = queryParams.get("email_address");
    auto userToken = queryParams.get("token");
    if (!emailAddress || !userToken)
    {
        return ApiResponseFactory::createResponse (
                ApiResponseStatus::CODE_401, "Missing email or token");
    }

    return ApiResponseFactory::createResponse (
            ApiResponseStatus::CODE_401, "OK");
}

I am using Oat++ 1.3.0, this issue manifests itself on both a Mac, Linux and Windows (Visual Studio project). Any suggestions would be gratefully accepted as I appear to be doing it as expected. Used this for reference

Could the controller object be going out of scope, thus causing the incomplete error message?

Here is the code related to it:

void AddApiController(
        std::shared_ptr<ApiEndpointController> controller)
{
    provider.router>addController(controller);
}

How it's called:

auto controller = std::make_shared<
            HandshakeApiController> ();
AddApiController(controller);

Solution

  • This is a known issue - https://github.com/oatpp/oatpp/issues/675 oatpp 1.3.0 doesn't drain the body automatically. The result is that remains of a previous request are treated as a new request on a persistent connection.

    To fix it - explicitly tell oatpp that it should read the body of the request by adding BODY_STRING(String, body) to endpoint definition:

    ENDPOINT("POST", "handshake/is_valid_user_token/*", isValidUserToken,
             BODY_STRING(String, body), // <-- read the body
             REQUEST(std::shared_ptr<IncomingRequest>, request))