Skip to content

Commit

Permalink
Don't generate extra data after the first empty line if message
Browse files Browse the repository at this point in the history
body is empty.

Fixes vinipsmaker#41.
  • Loading branch information
vinipsmaker committed Apr 13, 2014
1 parent f4d62b3 commit f4cca3f
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions src/httpserverresponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,40 +325,34 @@ bool HttpServerResponse::end(const QByteArray &chunk)
return false;
case Priv::HEADERS:
{
bool continue_to_message_body
= chunk.size() || priv->http10Buffer.size();

if (priv->options.testFlag(HttpServerResponse::HTTP_1_1)) {
{
static const char key[] = "Connection";
if (priv->options.testFlag(HttpServerResponse::KEEP_ALIVE)) {
static const char value[] = "keep-alive";
priv->headers
.replace(QByteArray::fromRawData(key,
sizeof(key) - 1),
QByteArray::fromRawData(value,
sizeof(value)
- 1));
} else {
static const char value[] = "close";
priv->headers
.replace(QByteArray::fromRawData(key,
sizeof(key) - 1),
QByteArray::fromRawData(value,
sizeof(value)
- 1));
}
}
{
static const char key[] = "Transfer-Encoding",
value[] = "chunked";
priv->headers.insert(QByteArray::fromRawData(key,
sizeof(key) - 1),
QByteArray::fromRawData(value,
sizeof(value)
- 1));
static const char key[] = "Connection";
if (priv->options.testFlag(HttpServerResponse::KEEP_ALIVE)) {
static const char value[] = "keep-alive";
priv->headers
.replace(QByteArray::fromRawData(key, sizeof(key) - 1),
QByteArray::fromRawData(value, sizeof(value) - 1));
} else {
static const char value[] = "close";
priv->headers
.replace(QByteArray::fromRawData(key, sizeof(key) - 1),
QByteArray::fromRawData(value, sizeof(value) - 1));
}
}

if (priv->options.testFlag(HttpServerResponse::HTTP_1_1)
&& continue_to_message_body) {
static const char key[] = "Transfer-Encoding", value[] = "chunked";
priv->headers
.insert(QByteArray::fromRawData(key, sizeof(key) - 1),
QByteArray::fromRawData(value, sizeof(value) - 1));
} else {
static const char key[] = "Content-Length";
priv->headers.replace(QByteArray::fromRawData(key,
sizeof(key) - 1),
priv->headers.replace(QByteArray
::fromRawData(key, sizeof(key) - 1),
QByteArray::number(priv->http10Buffer.size()
+ chunk.size()));
}
Expand All @@ -372,7 +366,18 @@ bool HttpServerResponse::end(const QByteArray &chunk)
}
priv->device.write(CRLF);

priv->formattingState = Priv::MESSAGE_BODY;
if (continue_to_message_body) {
priv->formattingState = Priv::MESSAGE_BODY;
} else {
if (priv->options.testFlag(HttpServerResponse::HTTP_1_0)
|| !priv->options.testFlag(HttpServerResponse::KEEP_ALIVE)) {
priv->device.close();
}

priv->formattingState = Priv::END;
emit finished();
return true;
}
}
case Priv::MESSAGE_BODY:
{
Expand Down

0 comments on commit f4cca3f

Please sign in to comment.