Skip to content

Commit

Permalink
Send the content-length header even if the body(POST,PUT,OPTIONS,PATC…
Browse files Browse the repository at this point in the history
…H) is empty (drogonframework#825)
  • Loading branch information
an-tao authored Apr 28, 2021
1 parent 88c6b6e commit a33bf2b
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions lib/src/HttpRequestImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,24 +310,32 @@ void HttpRequestImpl::appendToBuffer(trantor::MsgBuffer *output) const
}
}
assert(!(!content.empty() && !content_.empty()));
if (!passThrough_ && (!content.empty() || !content_.empty()))
if (!passThrough_)
{
char buf[64];
auto len =
snprintf(buf,
sizeof(buf),
contentLengthFormatString<decltype(content.length())>(),
content.length() + content_.length());
output->append(buf, len);
if (contentTypeString_.empty())
if (!content.empty() || !content_.empty())
{
auto &type = webContentTypeToString(contentType_);
output->append(type.data(), type.length());
char buf[64];
auto len = snprintf(
buf,
sizeof(buf),
contentLengthFormatString<decltype(content.length())>(),
content.length() + content_.length());
output->append(buf, len);
if (contentTypeString_.empty())
{
auto &type = webContentTypeToString(contentType_);
output->append(type.data(), type.length());
}
}
else if (method_ == Post || method_ == Put || method_ == Options ||
method_ == Patch)
{
output->append("content-length: 0\r\n", 19);
}
if (!contentTypeString_.empty())
{
output->append(contentTypeString_);
}
}
if (!passThrough_ && !contentTypeString_.empty())
{
output->append(contentTypeString_);
}
for (auto it = headers_.begin(); it != headers_.end(); ++it)
{
Expand Down

0 comments on commit a33bf2b

Please sign in to comment.