Fix a bug of Http HEAD method

This commit is contained in:
antao 2018-10-20 11:19:16 +08:00
parent 1d4c4ef897
commit d283ba193a
1 changed files with 12 additions and 3 deletions

View File

@ -175,10 +175,19 @@ void HttpServer::onRequest(const TcpConnectionPtr &conn, const HttpRequestPtr &r
return;
response->setCloseConnection(_close);
//if the request method is HEAD,remove the body of response(rfc2616-9.4)
if (_isHeadMethod)
response->setBody(std::string());
auto &sendfileName = std::dynamic_pointer_cast<HttpResponseImpl>(response)->sendfileName();
auto newResp = response;
if (_isHeadMethod)
{
if (newResp->expiredTime() >= 0)
{
//Cached response,make a copy
newResp = std::make_shared<HttpResponseImpl>(*std::dynamic_pointer_cast<HttpResponseImpl>(response));
}
newResp->setBody(std::string());
}
auto &sendfileName = std::dynamic_pointer_cast<HttpResponseImpl>(newResp)->sendfileName();
if (HttpAppFramework::instance().useGzip() &&
sendfileName.empty() &&
req->getHeader("Accept-Encoding").find("gzip") != std::string::npos &&