mirror of
https://github.com/drogonframework/drogon.git
synced 2025-09-22 00:00:33 -04:00
Lowercase all http headers, add webp and avif types (#718)
This commit is contained in:
parent
3b8b63d17d
commit
12cfdd5916
@ -10,7 +10,7 @@ void TestController::asyncHandleHttpRequest(
|
||||
++(threadIndex_.getThreadData());
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setContentTypeCodeAndCustomString(CT_TEXT_PLAIN,
|
||||
"Content-Type: plaintext\r\n");
|
||||
"content-type: plaintext\r\n");
|
||||
resp->setBody("<p>Hello, world!</p>");
|
||||
resp->setExpiredTime(20);
|
||||
callback(resp);
|
||||
|
@ -306,7 +306,7 @@ int main()
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody("Hello, World!");
|
||||
resp->setContentTypeCodeAndCustomString(
|
||||
CT_TEXT_PLAIN, "Content-Type: text/plain\r\n");
|
||||
CT_TEXT_PLAIN, "content-type: text/plain\r\n");
|
||||
return resp;
|
||||
}
|
||||
return nullResp;
|
||||
|
@ -102,6 +102,8 @@ enum ContentType
|
||||
CT_APPLICATION_PDF,
|
||||
CT_IMAGE_SVG_XML,
|
||||
CT_IMAGE_PNG,
|
||||
CT_IMAGE_WEBP,
|
||||
CT_IMAGE_AVIF,
|
||||
CT_IMAGE_JPG,
|
||||
CT_IMAGE_GIF,
|
||||
CT_IMAGE_XICON,
|
||||
|
@ -419,7 +419,7 @@ class HttpAppFrameworkImpl : public HttpAppFramework
|
||||
{
|
||||
assert(!running_);
|
||||
assert(server.find("\r\n") == std::string::npos);
|
||||
serverHeader_ = "Server: " + server + "\r\n";
|
||||
serverHeader_ = "server: " + server + "\r\n";
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -549,7 +549,7 @@ class HttpAppFrameworkImpl : public HttpAppFramework
|
||||
size_t sessionTimeout_{0};
|
||||
size_t idleConnectionTimeout_{60};
|
||||
bool useSession_{false};
|
||||
std::string serverHeader_{"Server: drogon/" + drogon::getVersion() +
|
||||
std::string serverHeader_{"server: drogon/" + drogon::getVersion() +
|
||||
"\r\n"};
|
||||
|
||||
const std::unique_ptr<StaticFileRouter> staticFileRouterPtr_;
|
||||
|
@ -26,7 +26,7 @@ HttpFileUploadRequest::HttpFileUploadRequest(
|
||||
{
|
||||
setMethod(drogon::Post);
|
||||
setVersion(drogon::Version::kHttp11);
|
||||
setContentType("Content-Type: multipart/form-data; boundary=" + boundary_ +
|
||||
setContentType("content-type: multipart/form-data; boundary=" + boundary_ +
|
||||
"\r\n");
|
||||
contentType_ = CT_MULTIPART_FORM_DATA;
|
||||
}
|
@ -272,7 +272,7 @@ void HttpRequestImpl::appendToBuffer(trantor::MsgBuffer *output) const
|
||||
content.append("--");
|
||||
content.append(mReq->boundary());
|
||||
content.append("\r\n");
|
||||
content.append("Content-Disposition: form-data; name=\"");
|
||||
content.append("content-disposition: form-data; name=\"");
|
||||
content.append(param.first);
|
||||
content.append("\"\r\n\r\n");
|
||||
content.append(param.second);
|
||||
@ -283,7 +283,7 @@ void HttpRequestImpl::appendToBuffer(trantor::MsgBuffer *output) const
|
||||
content.append("--");
|
||||
content.append(mReq->boundary());
|
||||
content.append("\r\n");
|
||||
content.append("Content-Disposition: form-data; name=\"");
|
||||
content.append("content-disposition: form-data; name=\"");
|
||||
content.append(file.itemName());
|
||||
content.append("\"; filename=\"");
|
||||
content.append(file.fileName());
|
||||
@ -339,7 +339,7 @@ void HttpRequestImpl::appendToBuffer(trantor::MsgBuffer *output) const
|
||||
}
|
||||
if (cookies_.size() > 0)
|
||||
{
|
||||
output->append("Cookie: ");
|
||||
output->append("cookie: ");
|
||||
for (auto it = cookies_.begin(); it != cookies_.end(); ++it)
|
||||
{
|
||||
output->append(it->first);
|
||||
|
@ -296,15 +296,15 @@ void HttpResponseImpl::makeHeaderString(trantor::MsgBuffer &buffer)
|
||||
filestat.st_size);
|
||||
}
|
||||
buffer.hasWritten(len);
|
||||
if (headers_.find("Connection") == headers_.end())
|
||||
if (headers_.find("connection") == headers_.end())
|
||||
{
|
||||
if (closeConnection_)
|
||||
{
|
||||
buffer.append("Connection: close\r\n");
|
||||
buffer.append("connection: close\r\n");
|
||||
}
|
||||
else if (version_ == Version::kHttp10)
|
||||
{
|
||||
buffer.append("Connection: Keep-Alive\r\n");
|
||||
buffer.append("connection: Keep-Alive\r\n");
|
||||
}
|
||||
}
|
||||
buffer.append(contentTypeString_.data(), contentTypeString_.length());
|
||||
@ -354,7 +354,7 @@ void HttpResponseImpl::renderToBuffer(trantor::MsgBuffer &buffer)
|
||||
if (!passThrough_ &&
|
||||
drogon::HttpAppFrameworkImpl::instance().sendDateHeader())
|
||||
{
|
||||
buffer.append("Date: ");
|
||||
buffer.append("date: ");
|
||||
buffer.append(utils::getHttpFullDate(trantor::Date::date()),
|
||||
httpFullDateStringLength);
|
||||
buffer.append("\r\n\r\n");
|
||||
@ -426,7 +426,7 @@ std::shared_ptr<trantor::MsgBuffer> HttpResponseImpl::renderToBuffer()
|
||||
if (!passThrough_ &&
|
||||
drogon::HttpAppFrameworkImpl::instance().sendDateHeader())
|
||||
{
|
||||
httpString->append("Date: ");
|
||||
httpString->append("date: ");
|
||||
auto datePos = httpString->readableBytes();
|
||||
httpString->append(utils::getHttpFullDate(trantor::Date::date()),
|
||||
httpFullDateStringLength);
|
||||
@ -475,7 +475,7 @@ std::shared_ptr<trantor::MsgBuffer> HttpResponseImpl::
|
||||
if (!passThrough_ &&
|
||||
drogon::HttpAppFrameworkImpl::instance().sendDateHeader())
|
||||
{
|
||||
httpString->append("Date: ");
|
||||
httpString->append("date: ");
|
||||
httpString->append(utils::getHttpFullDate(trantor::Date::date()),
|
||||
httpFullDateStringLength);
|
||||
httpString->append("\r\n\r\n");
|
||||
|
@ -403,7 +403,7 @@ class HttpResponseImpl : public HttpResponse
|
||||
mutable bool flagForParsingContentType_{false};
|
||||
mutable std::shared_ptr<std::string> jsonParsingErrorPtr_;
|
||||
string_view contentTypeString_{
|
||||
"Content-Type: text/html; charset=utf-8\r\n"};
|
||||
"content-type: text/html; charset=utf-8\r\n"};
|
||||
bool passThrough_{false};
|
||||
void setContentType(const string_view &contentType)
|
||||
{
|
||||
|
@ -26,125 +26,135 @@ const string_view &webContentTypeToString(ContentType contenttype)
|
||||
case CT_TEXT_HTML:
|
||||
{
|
||||
static string_view sv =
|
||||
"Content-Type: text/html; charset=utf-8\r\n";
|
||||
"content-type: text/html; charset=utf-8\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_X_FORM:
|
||||
{
|
||||
static string_view sv =
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n";
|
||||
"content-type: application/x-www-form-urlencoded\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_XML:
|
||||
{
|
||||
static string_view sv =
|
||||
"Content-Type: application/xml; charset=utf-8\r\n";
|
||||
"content-type: application/xml; charset=utf-8\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_JSON:
|
||||
{
|
||||
static string_view sv =
|
||||
"Content-Type: application/json; charset=utf-8\r\n";
|
||||
"content-type: application/json; charset=utf-8\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_X_JAVASCRIPT:
|
||||
{
|
||||
static string_view sv =
|
||||
"Content-Type: application/x-javascript; charset=utf-8\r\n";
|
||||
"content-type: application/x-javascript; charset=utf-8\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_TEXT_CSS:
|
||||
{
|
||||
static string_view sv = "Content-Type: text/css; charset=utf-8\r\n";
|
||||
static string_view sv = "content-type: text/css; charset=utf-8\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_TEXT_XML:
|
||||
{
|
||||
static string_view sv = "Content-Type: text/xml; charset=utf-8\r\n";
|
||||
static string_view sv = "content-type: text/xml; charset=utf-8\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_TEXT_XSL:
|
||||
{
|
||||
static string_view sv = "Content-Type: text/xsl; charset=utf-8\r\n";
|
||||
static string_view sv = "content-type: text/xsl; charset=utf-8\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_OCTET_STREAM:
|
||||
{
|
||||
static string_view sv =
|
||||
"Content-Type: application/octet-stream\r\n";
|
||||
"content-type: application/octet-stream\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_IMAGE_SVG_XML:
|
||||
{
|
||||
static string_view sv = "Content-Type: image/svg+xml\r\n";
|
||||
static string_view sv = "content-type: image/svg+xml\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_X_FONT_TRUETYPE:
|
||||
{
|
||||
static string_view sv =
|
||||
"Content-Type: application/x-font-truetype\r\n";
|
||||
"content-type: application/x-font-truetype\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_X_FONT_OPENTYPE:
|
||||
{
|
||||
static string_view sv =
|
||||
"Content-Type: application/x-font-opentype\r\n";
|
||||
"content-type: application/x-font-opentype\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_FONT_WOFF:
|
||||
{
|
||||
static string_view sv = "Content-Type: application/font-woff\r\n";
|
||||
static string_view sv = "content-type: application/font-woff\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_FONT_WOFF2:
|
||||
{
|
||||
static string_view sv = "Content-Type: application/font-woff2\r\n";
|
||||
static string_view sv = "content-type: application/font-woff2\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_VND_MS_FONTOBJ:
|
||||
{
|
||||
static string_view sv =
|
||||
"Content-Type: application/vnd.ms-fontobject\r\n";
|
||||
"content-type: application/vnd.ms-fontobject\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_PDF:
|
||||
{
|
||||
static string_view sv = "Content-Type: application/pdf\r\n";
|
||||
static string_view sv = "content-type: application/pdf\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_IMAGE_PNG:
|
||||
{
|
||||
static string_view sv = "Content-Type: image/png\r\n";
|
||||
static string_view sv = "content-type: image/png\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_IMAGE_AVIF:
|
||||
{
|
||||
static string_view sv = "content-type: image/avif\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_IMAGE_WEBP:
|
||||
{
|
||||
static string_view sv = "content-type: image/webp\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_IMAGE_JPG:
|
||||
{
|
||||
static string_view sv = "Content-Type: image/jpeg\r\n";
|
||||
static string_view sv = "content-type: image/jpeg\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_IMAGE_GIF:
|
||||
{
|
||||
static string_view sv = "Content-Type: image/gif\r\n";
|
||||
static string_view sv = "content-type: image/gif\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_IMAGE_XICON:
|
||||
{
|
||||
static string_view sv = "Content-Type: image/x-icon\r\n";
|
||||
static string_view sv = "content-type: image/x-icon\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_IMAGE_BMP:
|
||||
{
|
||||
static string_view sv = "Content-Type: image/bmp\r\n";
|
||||
static string_view sv = "content-type: image/bmp\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_IMAGE_ICNS:
|
||||
{
|
||||
static string_view sv = "Content-Type: image/icns\r\n";
|
||||
static string_view sv = "content-type: image/icns\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_APPLICATION_WASM:
|
||||
{
|
||||
static string_view sv = "Content-Type: application/wasm\r\n";
|
||||
static string_view sv = "content-type: application/wasm\r\n";
|
||||
return sv;
|
||||
}
|
||||
case CT_NONE:
|
||||
@ -156,7 +166,7 @@ const string_view &webContentTypeToString(ContentType contenttype)
|
||||
case CT_TEXT_PLAIN:
|
||||
{
|
||||
static string_view sv =
|
||||
"Content-Type: text/plain; charset=utf-8\r\n";
|
||||
"content-type: text/plain; charset=utf-8\r\n";
|
||||
return sv;
|
||||
}
|
||||
}
|
||||
@ -530,12 +540,16 @@ ContentType getContentType(const std::string &fileName)
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
if (extName == "html")
|
||||
if (extName == "avif")
|
||||
return CT_IMAGE_AVIF;
|
||||
else if (extName == "html")
|
||||
return CT_TEXT_HTML;
|
||||
else if (extName == "jpeg")
|
||||
return CT_IMAGE_JPG;
|
||||
else if (extName == "icns")
|
||||
return CT_IMAGE_ICNS;
|
||||
else if (extName == "webp")
|
||||
return CT_IMAGE_WEBP;
|
||||
else if (extName == "wasm")
|
||||
return CT_APPLICATION_WASM;
|
||||
else if (extName == "woff")
|
||||
@ -573,6 +587,8 @@ ContentType parseContentType(const string_view &contentType)
|
||||
{"application/vnd.ms-fontobject", CT_APPLICATION_VND_MS_FONTOBJ},
|
||||
{"application/pdf", CT_APPLICATION_PDF},
|
||||
{"image/png", CT_IMAGE_PNG},
|
||||
{"image/webp", CT_IMAGE_WEBP},
|
||||
{"image/avif", CT_IMAGE_AVIF},
|
||||
{"image/jpeg", CT_IMAGE_JPG},
|
||||
{"image/gif", CT_IMAGE_GIF},
|
||||
{"image/x-icon", CT_IMAGE_XICON},
|
||||
|
@ -28,31 +28,31 @@ ContentType getContentType(const std::string &fileName);
|
||||
template <typename T>
|
||||
inline constexpr const char *contentLengthFormatString()
|
||||
{
|
||||
return "Content-Length: %d\r\n";
|
||||
return "content-length: %d\r\n";
|
||||
}
|
||||
template <>
|
||||
inline constexpr const char *contentLengthFormatString<unsigned int>()
|
||||
{
|
||||
return "Content-Length: %u\r\n";
|
||||
return "content-length: %u\r\n";
|
||||
}
|
||||
template <>
|
||||
inline constexpr const char *contentLengthFormatString<long>()
|
||||
{
|
||||
return "Content-Length: %ld\r\n";
|
||||
return "content-length: %ld\r\n";
|
||||
}
|
||||
template <>
|
||||
inline constexpr const char *contentLengthFormatString<unsigned long>()
|
||||
{
|
||||
return "Content-Length: %lu\r\n";
|
||||
return "content-length: %lu\r\n";
|
||||
}
|
||||
template <>
|
||||
inline constexpr const char *contentLengthFormatString<long long>()
|
||||
{
|
||||
return "Content-Length: %lld\r\n";
|
||||
return "content-length: %lld\r\n";
|
||||
}
|
||||
template <>
|
||||
inline constexpr const char *contentLengthFormatString<unsigned long long>()
|
||||
{
|
||||
return "Content-Length: %llu\r\n";
|
||||
return "content-length: %llu\r\n";
|
||||
}
|
||||
} // namespace drogon
|
||||
|
@ -155,7 +155,7 @@ class StaticFileRouter
|
||||
if (!defaultContentType.empty())
|
||||
{
|
||||
defaultContentType_ =
|
||||
std::string{"Content-Type: "} + defaultContentType + "\r\n";
|
||||
std::string{"content-type: "} + defaultContentType + "\r\n";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user