Problem with the client provider on windows
remioukrat opened this issue · comments
When we run the service on windows.
If we try to do :
curl -X GET "https://localhost:8443/api/get" --insecure
we have always an internal server error 500.
It happens only on the endpoint where there is a redirection.
Hello @remioukrat ,
Please share your endpoint code and the full error message.
It’s just the sample for the redirection:
ENDPOINT_ASYNC("GET", "/api/get", TestApiGet)
{
ENDPOINT_ASYNC_INIT(TestApiGet)
Action act() override {
return controller->myClient->apiGetAsync().callbackTo(&TestApiGet::onResponse);
}
Action onResponse(const std::shared_ptr<IncomingResponse>&response) {
return response->readBodyToStringAsync().callbackTo(&TestApiGet::returnResult);
}
Action returnResult(const oatpp::String & body) {
return _return(controller->createResponse(Status::CODE_200, body));
}
};
and the error returned
$ curl -X GET "https://localhost:8443/api/get" --insecure
server=oatpp/1.2.0
code=500
description=Internal Server Error
message=[oatpp::network::tcp::client::ConnectionProvider::getConnectionAsync()]: Error. Can't connect.
Hey @remioukrat ,
From your code and from the error message - it's clear that the ApiClient is not able to connect to remote service.
Check that the client connection provider is set up correctly.
Hi @lganzzzo
For the connection provider I have used the code available in the example :
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, sslClientConnectionProvider) ("clientConnectionProvider", [] {
auto config = oatpp::libressl::Config::createShared();
tls_config_insecure_noverifycert(config->getTLSConfig());
tls_config_insecure_noverifyname(config->getTLSConfig());
return oatpp::libressl::client::ConnectionProvider::createShared(config, {"httpbin.org", 443});
}());
OATPP_CREATE_COMPONENT(std::shared_ptr<MyApiClient>, myApiClient)([] {
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, connectionProvider, "clientConnectionProvider");
OATPP_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, objectMapper);
auto requestExecutor = oatpp::web::client::HttpRequestExecutor::createShared(connectionProvider);
return MyApiClient::createShared(requestExecutor, objectMapper);
}());
And for the client it’s the same:
#ifndef MyApiClient_hpp
#define MyApiClient_hpp
#include "oatpp/web/client/ApiClient.hpp"
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include OATPP_CODEGEN_BEGIN(ApiClient)
class MyApiClient : public oatpp::web::client::ApiClient {
API_CLIENT_INIT(MyApiClient)
API_CALL("GET", "/get", apiGet)
API_CALL_ASYNC("GET", "/get", apiGetAsync)
};
#include OATPP_CODEGEN_END(ApiClient)
#endif /* MyApiClient_hpp */
Ok, I see. It might be some kind of LibreSSL config that is missing on Windows.
Questions:
- Are you trying to hit
httpbin.org
or are you using a different service in your code? - Have you tried this example on Linux/Mac, is it working for you?
Apart from that, I would recommend (it's not related to the issue):
- Update to
oatpp 1.2.5
- Using oatpp-openssl
No, I have just tryed to hit httpbin.org. This example works in a linux docker but not on Windows.
For Windows I use vcpkg packages. For the moment I use LibreSSL, but I have to test with OpenSSL too.
That's sounds interesting. I can't check on windows at the moment.
I would suggest making sure that httpbin.org
is accessible from within the widows VM, and that you are hitting the right port 443
.
Also, it's possible that you have to additionally configure the TLS somehow on windows, by calling LibreSSL'stls_config_<...>
.
Example:
tls_config_insecure_noverifycert(config->getTLSConfig());
tls_config_insecure_noverifyname(config->getTLSConfig());