Open treeform opened 5 years ago
Well, seems like parseHeader
from httpcore calls parseList
which does split the line by ,
(because that seems to be the right way for most headers), maybe we can introduce a special case by checking for user-agent
in asynchttpserver request parsing code and add a special noSplit
bool argument (of course it would be false
by default) to parseHeader
in httpcore?
Or otherwise we can just do join
ourselves after parsing header line by parseHeader (although IMO that's a bit more hacky)
The above PR provides the mechanics for turning the splitting off in asynchttpserver
later :)
I have written a HTTP library to solve this problem: https://github.com/treeform/puppy
date
header also spitted:
❯ inim
👑 INim 0.6.1
Nim Compiler Version 1.6.4 [Linux: amd64] at /home/unikum/.nimble/bin/nim
nim> import httpcore
nim> echo parseHeader("date: Mon, 04 Apr 2022 10:08:54 GMT")
(key: "date", value: @["Mon", "04 Apr 2022 10:08:54 GMT"])
I prefer if the default behavior was not to split, and let user split on "," in any header they desire themselves.
Less magic is simpler.
req.headers["user-agent"] returns:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML
But I expected it to return:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
It splits on "," which it should not.
req.headers.table["user-agent"] returns:
@["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML", "like Gecko) Chrome/75.0.3770.100 Safari/537.36"]
I found this error while updating my user agent parsing library: https://github.com/treeform/useragents
Work around:
Example code: