You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2018/10/07 14:42:17 UTC
[mesos] 01/03: Added default message bodies to libprocess HTTP
error responses.
This is an automated email from the ASF dual-hosted git repository.
alexr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 85f4f3ef6031d090095e07b7638cf9d80362c27e
Author: Benno Evers <be...@mesosphere.com>
AuthorDate: Sun Oct 7 14:03:01 2018 +0200
Added default message bodies to libprocess HTTP error responses.
By default on error libprocess would only return an HTTP response
with the correct status code and no response body.
However, most browsers do not visually indicate the response status
code, making it hard for the user to figure out what exactly the
problem was.
A rudimentary text-only body is added to the default body of HTTP
error responses, mirroring the approach taken by, e.g., the Go
standard library or Python's http.server module.
Review: https://reviews.apache.org/r/67414/
---
3rdparty/libprocess/include/process/http.hpp | 33 ++++++++++++++++++----------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index fa66b0f..bcaca35 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -697,7 +697,7 @@ struct TemporaryRedirect : Response
struct BadRequest : Response
{
- BadRequest() : Response(Status::BAD_REQUEST) {}
+ BadRequest() : Response("400 Bad Request.", Status::BAD_REQUEST) {}
explicit BadRequest(const std::string& body)
: Response(body, Status::BAD_REQUEST) {}
@@ -707,7 +707,7 @@ struct BadRequest : Response
struct Unauthorized : Response
{
explicit Unauthorized(const std::vector<std::string>& challenges)
- : Response(Status::UNAUTHORIZED)
+ : Response("401 Unauthorized.", Status::UNAUTHORIZED)
{
// TODO(arojas): Many HTTP client implementations do not support
// multiple challenges within a single 'WWW-Authenticate' header.
@@ -732,7 +732,7 @@ struct Unauthorized : Response
struct Forbidden : Response
{
- Forbidden() : Response(Status::FORBIDDEN) {}
+ Forbidden() : Response("403 Forbidden.", Status::FORBIDDEN) {}
explicit Forbidden(const std::string& body)
: Response(body, Status::FORBIDDEN) {}
@@ -741,7 +741,7 @@ struct Forbidden : Response
struct NotFound : Response
{
- NotFound() : Response(Status::NOT_FOUND) {}
+ NotFound() : Response("404 File Not Found.", Status::NOT_FOUND) {}
explicit NotFound(const std::string& body)
: Response(body, Status::NOT_FOUND) {}
@@ -755,7 +755,7 @@ struct MethodNotAllowed : Response
explicit MethodNotAllowed(
const std::initializer_list<std::string>& allowedMethods)
- : Response(Status::METHOD_NOT_ALLOWED)
+ : Response("405 Method Not Allowed.", Status::METHOD_NOT_ALLOWED)
{
headers["Allow"] = strings::join(", ", allowedMethods);
}
@@ -783,7 +783,7 @@ private:
struct NotAcceptable : Response
{
- NotAcceptable() : Response(Status::NOT_ACCEPTABLE) {}
+ NotAcceptable() : Response("406 Not Acceptable.", Status::NOT_ACCEPTABLE) {}
explicit NotAcceptable(const std::string& body)
: Response(body, Status::NOT_ACCEPTABLE) {}
@@ -792,7 +792,7 @@ struct NotAcceptable : Response
struct Conflict : Response
{
- Conflict() : Response(Status::CONFLICT) {}
+ Conflict() : Response("409 Conflict.", Status::CONFLICT) {}
explicit Conflict(const std::string& body)
: Response(body, Status::CONFLICT) {}
@@ -801,7 +801,9 @@ struct Conflict : Response
struct PreconditionFailed : Response
{
- PreconditionFailed() : Response(Status::PRECONDITION_FAILED) {}
+ PreconditionFailed()
+ : Response("412 Precondition Failed.", Status::PRECONDITION_FAILED)
+ {}
explicit PreconditionFailed(const std::string& body)
: Response(body, Status::PRECONDITION_FAILED) {}
@@ -810,7 +812,9 @@ struct PreconditionFailed : Response
struct UnsupportedMediaType : Response
{
- UnsupportedMediaType() : Response(Status::UNSUPPORTED_MEDIA_TYPE) {}
+ UnsupportedMediaType()
+ : Response("415 Unsupported Media Type.", Status::UNSUPPORTED_MEDIA_TYPE)
+ {}
explicit UnsupportedMediaType(const std::string& body)
: Response(body, Status::UNSUPPORTED_MEDIA_TYPE) {}
@@ -819,7 +823,9 @@ struct UnsupportedMediaType : Response
struct InternalServerError : Response
{
- InternalServerError() : Response(Status::INTERNAL_SERVER_ERROR) {}
+ InternalServerError()
+ : Response("500 Internal Server Error.", Status::INTERNAL_SERVER_ERROR)
+ {}
explicit InternalServerError(const std::string& body)
: Response(body, Status::INTERNAL_SERVER_ERROR) {}
@@ -828,7 +834,8 @@ struct InternalServerError : Response
struct NotImplemented : Response
{
- NotImplemented() : Response(Status::NOT_IMPLEMENTED) {}
+ NotImplemented() : Response("501 Not Implemented.", Status::NOT_IMPLEMENTED)
+ {}
explicit NotImplemented(const std::string& body)
: Response(body, Status::NOT_IMPLEMENTED) {}
@@ -837,7 +844,9 @@ struct NotImplemented : Response
struct ServiceUnavailable : Response
{
- ServiceUnavailable() : Response(Status::SERVICE_UNAVAILABLE) {}
+ ServiceUnavailable()
+ : Response("503 Service Unavailable.", Status::SERVICE_UNAVAILABLE)
+ {}
explicit ServiceUnavailable(const std::string& body)
: Response(body, Status::SERVICE_UNAVAILABLE) {}