Refine the response for bad request.
This commit is contained in:
@@ -75,8 +75,7 @@ void HttpConnection::OnRead(boost::system::error_code ec, std::size_t length) {
|
|||||||
if (!request_parser_.Parse(buffer_.data(), length)) {
|
if (!request_parser_.Parse(buffer_.data(), length)) {
|
||||||
// Bad request.
|
// Bad request.
|
||||||
LOG_ERRO("Failed to parse HTTP request.");
|
LOG_ERRO("Failed to parse HTTP request.");
|
||||||
response_ = HttpResponse::Fault(http::Status::kBadRequest);
|
SendResponse(http::Status::kBadRequest);
|
||||||
DoWrite();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,8 +116,8 @@ void HttpConnection::OnWrite(boost::system::error_code ec, std::size_t length) {
|
|||||||
LOG_INFO("Response has been sent back, length: %u.", length);
|
LOG_INFO("Response has been sent back, length: %u.", length);
|
||||||
|
|
||||||
if (request_->IsConnectionKeepAlive()) {
|
if (request_->IsConnectionKeepAlive()) {
|
||||||
LOG_INFO("The client asked for keep-alive connection.");
|
LOG_INFO("The client asked for a keep-alive connection.");
|
||||||
LOG_INFO("Continue to read next request...");
|
LOG_INFO("Continue to read the next request...");
|
||||||
Start();
|
Start();
|
||||||
} else {
|
} else {
|
||||||
Shutdown();
|
Shutdown();
|
||||||
|
|||||||
@@ -66,17 +66,4 @@ bool HttpResponse::Prepare() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponsePtr HttpResponse::Fault(http::Status status) {
|
|
||||||
assert(status != http::Status::kOK);
|
|
||||||
|
|
||||||
auto response = std::make_shared<HttpResponse>(status);
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
response->SetHeader(http::headers::kConnection, "Close");
|
|
||||||
|
|
||||||
//response->Prepare();
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace webcc
|
} // namespace webcc
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ public:
|
|||||||
// Set start line according to status code.
|
// Set start line according to status code.
|
||||||
bool Prepare() final;
|
bool Prepare() final;
|
||||||
|
|
||||||
// Get a fault response when HTTP status is not OK.
|
|
||||||
static HttpResponsePtr Fault(http::Status status);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int status_;
|
int status_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user