-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The date header breaks the server if used with locale #2215
Comments
Regarding header names:
This aligns with HTTP’s general case-insensitivity for header names but enforces a stricter format in HTTP/2 for optimization and consistency. |
This is true that PascalCase isn't required for 1.1, and I can understand prefering to use lowercase for compatibility reasons with HTTP/2, enum class Version
{
kUnknown = 0,
kHttp10,
kHttp11
}; So why force lowercase for even explicitly set PascalCase headers? |
So, the buffer for the date is initialized with nulls-bytes Line 1021 in 1765223
After that, there is constantly defined date length drogon/lib/src/HttpResponseImpl.cc Line 40 in 1765223
As well as some unsafe operations drogon/lib/src/HttpResponseImpl.cc Line 669 in 1765223
I will look further into it, but I can see two problems right now: The second problem is, that whatever the localized date string size is, allowing non-ASCII symbols is not a good idea. Solution: Don't use |
It looks like std::strftime, which is used for date formating, is locale-dependent in all formats that don't use digits for numbering weekdays\months etc. So my solution is to construct stream with set en_US locale and use it to construct the date string. |
Describe the bug
Date header doesn't seem to be in the right format, when the locale is specified somewhere in the program, causing clients not being able to get data.
Both known headers and the headers added with
->addHeader()
are all lowercase.I've a very simple page in Drogon, this is the code
and the respective handler:
My request in Postman:
My result in Postman:
and when I try to open the page in browser I get "ERR_INVALID_HTTP_RESPONSE".
When I try to open it with CURL I get:
Commenting out setlocale instantly fixes the issue with the date on all clients, but I need this locale for other parts of the program.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
First of all, I'm expecting date field not to end up with null-byte and to have standard, non-localized RFC822-string format. In this case it should be
Wed, 27 Nov 24 07:17:26 GMT
. I believe null-byte is a result of a smaller size of a string, that was allocated using null-bytes.Second, I'm expecting well known headers such as
Content-Length
to have the same case as stated in stated in the standard.Third, I'm expecting drogon to respect explicit case in header keys such as "ServerTest", so it won't not to be resolved to the "servertest".
Desktop (please complete the following information):
ru-RU
Additional context
I understand that all the headerkey checks (mostly) MUST be case-insensitive, and making it all lowercase is probably done for optimization reasons, but I've been working with HTTP for the last 3 years, and its the first web-server that is using lowercase headers. Most of documentation is also using Pascal-Train casing.
The text was updated successfully, but these errors were encountered: