mirror of https://github.com/Icinga/icinga2.git
parent
a3d5d2488e
commit
7e5f5544fc
|
@ -51,6 +51,7 @@ void ApiClient::GetTypes(const TypesCompletionCallback& callback) const
|
|||
req->RequestMethod = "GET";
|
||||
req->RequestUrl = url;
|
||||
req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password));
|
||||
req->AddHeader("Accept", "application/json");
|
||||
m_Connection->SubmitRequest(req, boost::bind(TypesHttpCompletionCallback, _1, _2, callback));
|
||||
} catch (const std::exception& ex) {
|
||||
callback(boost::current_exception(), std::vector<ApiType::Ptr>());
|
||||
|
@ -134,6 +135,7 @@ void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCall
|
|||
req->RequestMethod = "GET";
|
||||
req->RequestUrl = url;
|
||||
req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password));
|
||||
req->AddHeader("Accept", "application/json");
|
||||
m_Connection->SubmitRequest(req, boost::bind(ObjectsHttpCompletionCallback, _1, _2, callback));
|
||||
} catch (const std::exception& ex) {
|
||||
callback(boost::current_exception(), std::vector<ApiObject::Ptr>());
|
||||
|
@ -231,6 +233,7 @@ void ApiClient::ExecuteScript(const String& session, const String& command, bool
|
|||
req->RequestMethod = "POST";
|
||||
req->RequestUrl = url;
|
||||
req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password));
|
||||
req->AddHeader("Accept", "application/json");
|
||||
m_Connection->SubmitRequest(req, boost::bind(ExecuteScriptHttpCompletionCallback, _1, _2, callback));
|
||||
} catch (const std::exception& ex) {
|
||||
callback(boost::current_exception(), Empty);
|
||||
|
@ -315,6 +318,7 @@ void ApiClient::AutocompleteScript(const String& session, const String& command,
|
|||
req->RequestMethod = "POST";
|
||||
req->RequestUrl = url;
|
||||
req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password));
|
||||
req->AddHeader("Accept", "application/json");
|
||||
m_Connection->SubmitRequest(req, boost::bind(AutocompleteScriptHttpCompletionCallback, _1, _2, callback));
|
||||
} catch (const std::exception& ex) {
|
||||
callback(boost::current_exception(), Array::Ptr());
|
||||
|
|
|
@ -49,6 +49,11 @@ bool ConfigFilesHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
|
|||
params->Set("path", boost::algorithm::join(tmpPath, "/"));
|
||||
}
|
||||
|
||||
if (request.Headers->Get("accept") == "application/json") {
|
||||
HttpUtility::SendJsonError(response, 400, "Invalid Accept header. Either remove the Accept header or set it to 'application/octet-stream'.");
|
||||
return true;
|
||||
}
|
||||
|
||||
FilterUtility::CheckPermission(user, "config/query");
|
||||
|
||||
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||
|
|
|
@ -161,7 +161,14 @@ void HttpServerConnection::ProcessMessageAsync(HttpRequest& request)
|
|||
|
||||
HttpResponse response(m_Stream, request);
|
||||
|
||||
if (!user) {
|
||||
String accept_header = request.Headers->Get("accept");
|
||||
|
||||
if (request.RequestMethod != "GET" && accept_header != "application/json") {
|
||||
response.SetStatus(400, "Wrong Accept header");
|
||||
response.AddHeader("Content-Type", "text/html");
|
||||
String msg = "<h1>Accept header is missing or not set to 'application/json'.</h1>";
|
||||
response.WriteBody(msg.CStr(), msg.GetLength());
|
||||
} else if (!user) {
|
||||
Log(LogWarning, "HttpServerConnection")
|
||||
<< "Unauthorized request: " << request.RequestMethod << " " << requestUrl;
|
||||
response.SetStatus(401, "Unauthorized");
|
||||
|
|
Loading…
Reference in New Issue