Explorar el Código

Merge pull request #2 from MikuAuahDark/consistent

Fixing some inconsistencies across different backends.
Alex Szpakowski hace 3 años
padre
commit
4e4de80fab
Se han modificado 3 ficheros con 18 adiciones y 6 borrados
  1. 2 0
      src/CMakeLists.txt
  2. 1 1
      src/common/HTTPRequest.cpp
  3. 15 5
      src/lua/main.cpp

+ 2 - 0
src/CMakeLists.txt

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

+ 1 - 1
src/common/HTTPRequest.cpp

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

+ 15 - 5
src/lua/main.cpp

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