diff --git a/lib/remote/actionshandler.cpp b/lib/remote/actionshandler.cpp index d7ac3b353..df879d12c 100644 --- a/lib/remote/actionshandler.cpp +++ b/lib/remote/actionshandler.cpp @@ -66,7 +66,7 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques } catch (const std::exception& ex) { HttpUtility::SendJsonError(response, 400, "Type/Filter was required but not provided or was invalid.", - request.GetVerboseErrors() ? DiagnosticInformation(ex) : ""); + HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : ""); return true; } } else { @@ -86,7 +86,7 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques Dictionary::Ptr fail = new Dictionary(); fail->Set("code", 500); fail->Set("status", "Action execution failed."); - if (request.GetVerboseErrors()) + if (HttpUtility::GetLastParameter(params, "verboseErrors")) fail->Set("diagnostic information", DiagnosticInformation(ex)); results->Add(fail); } diff --git a/lib/remote/configfileshandler.cpp b/lib/remote/configfileshandler.cpp index 5969e39fc..5e586a940 100644 --- a/lib/remote/configfileshandler.cpp +++ b/lib/remote/configfileshandler.cpp @@ -88,7 +88,7 @@ bool ConfigFilesHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re response.WriteBody(content.CStr(), content.GetLength()); } catch (const std::exception& ex) { HttpUtility::SendJsonError(response, 500, "Could not read file.", - request.GetVerboseErrors() ? DiagnosticInformation(ex) : ""); + HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : ""); } return true; diff --git a/lib/remote/configpackageshandler.cpp b/lib/remote/configpackageshandler.cpp index d6906f639..dbbc37912 100644 --- a/lib/remote/configpackageshandler.cpp +++ b/lib/remote/configpackageshandler.cpp @@ -90,7 +90,7 @@ void ConfigPackagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& re ConfigPackageUtility::CreatePackage(packageName); } catch (const std::exception& ex) { HttpUtility::SendJsonError(response, 500, "Could not create package.", - request.GetVerboseErrors() ? DiagnosticInformation(ex) : ""); + HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : ""); } result1->Set("code", 200); @@ -131,7 +131,7 @@ void ConfigPackagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& } catch (const std::exception& ex) { code = 500; status = "Failed to delete package."; - if (request.GetVerboseErrors()) + if (HttpUtility::GetLastParameter(params, "verboseErrors")) result1->Set("diagnostic information", DiagnosticInformation(ex)); } diff --git a/lib/remote/configstageshandler.cpp b/lib/remote/configstageshandler.cpp index 5c241aedc..9ec205647 100644 --- a/lib/remote/configstageshandler.cpp +++ b/lib/remote/configstageshandler.cpp @@ -118,7 +118,7 @@ void ConfigStagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& requ } catch (const std::exception& ex) { return HttpUtility::SendJsonError(response, 500, "Stage creation failed.", - request.GetVerboseErrors() ? DiagnosticInformation(ex) : ""); + HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : ""); } Dictionary::Ptr result1 = new Dictionary(); @@ -164,7 +164,7 @@ void ConfigStagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& re } catch (const std::exception& ex) { return HttpUtility::SendJsonError(response, 500, "Failed to delete stage.", - request.GetVerboseErrors() ? DiagnosticInformation(ex) : ""); + HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : ""); } Dictionary::Ptr result1 = new Dictionary(); diff --git a/lib/remote/httprequest.cpp b/lib/remote/httprequest.cpp index d9eacb781..5c5f5634b 100644 --- a/lib/remote/httprequest.cpp +++ b/lib/remote/httprequest.cpp @@ -34,8 +34,7 @@ HttpRequest::HttpRequest(const Stream::Ptr& stream) ProtocolVersion(HttpVersion11), Headers(new Dictionary()), m_Stream(stream), - m_State(HttpRequestStart), - verboseErrors(false) + m_State(HttpRequestStart) { } bool HttpRequest::Parse(StreamReadContext& src, bool may_wait) @@ -61,7 +60,6 @@ bool HttpRequest::Parse(StreamReadContext& src, bool may_wait) RequestMethod = tokens[0]; RequestUrl = new class Url(tokens[1]); - verboseErrors = (RequestUrl->GetQueryElement("verboseErrors") == "true"); if (tokens[2] == "HTTP/1.0") ProtocolVersion = HttpVersion10; diff --git a/lib/remote/httprequest.hpp b/lib/remote/httprequest.hpp index 6542a7028..9eb1a0b21 100644 --- a/lib/remote/httprequest.hpp +++ b/lib/remote/httprequest.hpp @@ -69,15 +69,11 @@ public: void WriteBody(const char *data, size_t count); void Finish(void); - inline bool GetVerboseErrors(void) - { return verboseErrors; } - private: Stream::Ptr m_Stream; boost::shared_ptr m_ChunkContext; HttpRequestState m_State; FIFO::Ptr m_Body; - bool verboseErrors; void FinishHeaders(void); }; diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp index d75b50807..5160ef1dd 100644 --- a/lib/remote/httpserverconnection.cpp +++ b/lib/remote/httpserverconnection.cpp @@ -86,6 +86,15 @@ bool HttpServerConnection::ProcessMessage(void) try { res = m_CurrentRequest.Parse(m_Context, false); + } catch (const std::invalid_argument& ex) { + HttpResponse response(m_Stream, m_CurrentRequest); + response.SetStatus(400, "Bad request"); + String msg = String("

Bad request

") + ex.what() + "

"; + response.WriteBody(msg.CStr(), msg.GetLength()); + response.Finish(); + + m_Stream->Shutdown(); + return false; } catch (const std::exception& ex) { HttpResponse response(m_Stream, m_CurrentRequest); response.SetStatus(400, "Bad request");