-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add the ability to pass title case headers to an HTTP server #13968
Conversation
lib/pure/httpcore.nim
Outdated
upper = s[i] == '-' | ||
|
||
|
||
proc newHttpHeaders*(titleCase: bool =false): HttpHeaders = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just write "titleCase = false" here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Changed
lib/pure/httpcore.nim
Outdated
|
||
proc newHttpHeaders*(keyValuePairs: | ||
openArray[tuple[key: string, val: string]]): HttpHeaders = | ||
openArray[tuple[key: string, val: string]],titleCase: bool =false): HttpHeaders = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, also add a space like "openArray[tuple[key: string, val: string]], titleCase"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Changed.
I think like this indeed might be a useful feature, but it needs more thought on how to do it properly |
About your Rust example - see hyperium/hyper#1497, we only need to convert headers to TitleCase when actually sending them, not every time you try to assign keys or something like that. |
I also thought about putting my changes in httpclient.nim. But I decided against it, because in this case the conversion has to be done twice. ( I also decided against simply replacing |
lib/pure/httpcore.nim
Outdated
|
||
proc newHttpHeaders*(keyValuePairs: | ||
openArray[tuple[key: string, val: string]]): HttpHeaders = | ||
openArray[tuple[key: string, val: string]], titleCase =false): HttpHeaders = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit
openArray[tuple[key: string, val: string]], titleCase =false): HttpHeaders = | |
openArray[tuple[key: string, val: string]], titleCase=false): HttpHeaders = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look at other files and it seems that normally a space is used as separator before and after =
. Therefore I added a space after the =
@@ -100,16 +101,30 @@ const | |||
const httpNewLine* = "\c\L" | |||
const headerLimit* = 10_000 | |||
|
|||
proc newHttpHeaders*(): HttpHeaders = | |||
proc toTitleCase(s: string): string = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separate PR to add this into strutils would be nice :)
lib/pure/httpcore.nim
Outdated
@@ -17,6 +17,7 @@ import tables, strutils, parseutils | |||
type | |||
HttpHeaders* = ref object | |||
table*: TableRef[string, seq[string]] | |||
convert: proc (str: string): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we really need this, it just adds extra complexity. Just store isTitleCase
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this accordingly.
Or instead: You write HTTP servers that adhere to the spec and are not case sensitive... |
…im-lang#13968)" This reverts commit 5571d48.
Some older HTTP servers (especially those used in embedded devices) expect title case HTTP headers. Normally HTTP headers should be case insensitive. To also support the communication to these HTTP servers, I added a flag
titleCase
to theHttpHeaders
This was also added as feature to other programming languages (e.g. rust)