Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
endif ()
option (DEBUG_SCHANNEL "Enable debug output in schannel backend" OFF)

set_target_properties(https PROPERTIES PREFIX "")

### Dependencies
target_link_libraries (https https-common)

Expand Down
2 changes: 1 addition & 1 deletion src/common/HTTPRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ HTTPRequest::HTTPRequest(ConnectionFactory factory)
HTTPSClient::Reply HTTPRequest::request(const HTTPSClient::Request &req)
{
HTTPSClient::Reply reply;
reply.responseCode = 400;
reply.responseCode = 0;

auto info = parseUrl(req.url);
if (!info.valid)
Expand Down
20 changes: 15 additions & 5 deletions src/lua/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static int w_request(lua_State *L)
auto url = w_checkstring(L, 1);
HTTPSClient::Request req(url);

std::string errorMessage("No applicable implementation found");
bool foundClient = false;
bool advanced = false;

Expand Down Expand Up @@ -124,10 +125,21 @@ static int w_request(lua_State *L)
for (size_t i = 0; clients[i]; ++i)
{
HTTPSClient &client = *clients[i];
HTTPSClient::Reply reply;

if (!client.valid())
continue;

auto reply = client.request(req);
try
{
reply = client.request(req);
}
catch(const std::exception& e)
{
errorMessage = e.what();
break;
}

lua_pushinteger(L, reply.responseCode);
w_pushstring(L, reply.body);

Expand All @@ -149,12 +161,10 @@ static int w_request(lua_State *L)
if (!foundClient)
{
lua_pushnil(L);
lua_pushstring(L, "No applicable implementation found");
if (advanced)
lua_pushnil(L);
lua_pushstring(L, errorMessage.c_str());
}

return advanced ? 3 : 2;
return (advanced && foundClient) ? 3 : 2;
}

extern "C" int DLLEXPORT luaopen_https(lua_State *L)
Expand Down