Browse Source

Fix response for HTTP HEAD method

Closes #19288.
adaptive-webui-19844
Chocobo1 1 year ago
parent
commit
e8f5a3b44e
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 20
      src/base/http/connection.cpp
  2. 5
      src/base/http/responsegenerator.cpp

20
src/base/http/connection.cpp

@ -123,14 +123,30 @@ void Connection::read() @@ -123,14 +123,30 @@ void Connection::read()
{
const Environment env {m_socket->localAddress(), m_socket->localPort(), m_socket->peerAddress(), m_socket->peerPort()};
if (result.request.method == HEADER_REQUEST_METHOD_HEAD)
{
Request getRequest = result.request;
getRequest.method = HEADER_REQUEST_METHOD_GET;
Response resp = m_requestHandler->processRequest(getRequest, env);
resp.headers[HEADER_CONNECTION] = u"keep-alive"_s;
resp.headers[HEADER_CONTENT_LENGTH] = QString::number(resp.content.length());
resp.content.clear();
sendResponse(resp);
}
else
{
Response resp = m_requestHandler->processRequest(result.request, env);
if (acceptsGzipEncoding(result.request.headers[u"accept-encoding"_s]))
if (acceptsGzipEncoding(result.request.headers.value(u"accept-encoding"_s)))
resp.headers[HEADER_CONTENT_ENCODING] = u"gzip"_s;
resp.headers[HEADER_CONNECTION] = u"keep-alive"_s;
sendResponse(resp);
}
m_receivedData.remove(0, result.frameSize);
}
break;

5
src/base/http/responsegenerator.cpp

@ -38,8 +38,9 @@ QByteArray Http::toByteArray(Response response) @@ -38,8 +38,9 @@ QByteArray Http::toByteArray(Response response)
{
compressContent(response);
response.headers[HEADER_CONTENT_LENGTH] = QString::number(response.content.length());
response.headers[HEADER_DATE] = httpDate();
if (QString &value = response.headers[HEADER_CONTENT_LENGTH]; value.isEmpty())
value = QString::number(response.content.length());
QByteArray buf;
buf.reserve(1024 + response.content.length());
@ -63,7 +64,7 @@ QByteArray Http::toByteArray(Response response) @@ -63,7 +64,7 @@ QByteArray Http::toByteArray(Response response)
// the first empty line
buf += CRLF;
// message body // TODO: support HEAD request
// message body
buf += response.content;
return buf;

Loading…
Cancel
Save