add HTTPHeaders.first(name:)
#37
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a new method
first(name:)
toHTTPHeaders
(aka just[String: String]
).Motivation:
I first noticed absence of such a function when I was trying to get 2 different headers of a Github request.
Using capitalized header names as mentioned in Github docs, or lowercased names, both would fail.
(EDIT: To be clear, i think one header had a capitalized name and the other a lowercased name, which is just an inconsistency by Github in this case.)
That was when I copy-pasted
swift-nio
'sHTTPHeaders.first(name:)
function to the lambda target, which fixed the issue.I think this will be a generally useful function, as it's even available in NIO's implementation of
HTTPHeaders
.Modifications:
Copy-paste NIO's implementation of
HTTPHeaders.first(name:)
.Modify the comments to be correct about this project.
Declare the extension on
String.UTF8View
instead ofSequence<UInt8>
as we don't need the generic extension unlike NIO.Update: Copy-pasted the tests as well.
Result:
Addition of a function to the public API
HTTPHeaders.first(name:)
(akaDictionary<String, String>.first(name:)
).