-
-
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
Provide non-splitting parseHeaderField in httpcore #15478
Conversation
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 this is the way to go, we just need to follow the RFC here and parse things properly. Do other languages provide this option as well? if so you might be able to convince me, otherwise I don't think we should add this.
While I agree that following specification is always better the goal of Currently people are running into issues with this around headers such as the Since we'll be discussing spec/not-spec, I'll quote the relevant section here for ease-of-discussion:
|
hmmm, looking at the spec it appears that this function should never split on a comma and indeed it should be up to the caller to decide what to do with the field values. My proposal is to do the following:
The reason is that we should be discouraging the use of the splitting variant. |
Sure we can argue about name (I'd go for |
This |
Perfect, I'll get to it somewhere this week then 👍 |
a0d2d4e
to
c4f6256
Compare
@dom96 I've updated this to create a non-splitting version of parseHeader called parseHeaderField. How do I deprecate the old one and is this what you had in mind? |
I've deprecated the old Shall I special case the cookie header in asynchttpserver and write a test for it @dom96 ? |
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.
Sure, more tests are always nice.
func parseHeaderField*(line: string): tuple[key: string, value: seq[string]] = | ||
## Parses a single raw header HTTP line into key value pairs. | ||
result.value = @[] | ||
var i = 0 | ||
i = line.parseUntil(result.key, ':') | ||
inc(i) # skip : | ||
if i < len(line): | ||
i += line.skipWhitespace(i) | ||
result.value.add line.substr(i) | ||
elif result.key.len > 0: | ||
result.value = @[""] | ||
else: | ||
result.value = @[] | ||
|
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.
Am I missing something? This won't ever return more than one value.
This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions. |
Several issues are related to header splitting, one of them being #11757. This PR provides a
noSplit
option to httpcore'sparseHeader
to allow for several other issues to be worked on.