-
Notifications
You must be signed in to change notification settings - Fork 82
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 a subscript to HPACKHeaders to return the first value with a matc… #178
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.
This LGTM, but I'd like to see if @weissi had an opinion on the subscript spelling.
Sources/NIOHPACK/HPACKHeader.swift
Outdated
/// | ||
/// - Parameter name: The header field name whose first value should be retrieved. | ||
/// - Returns: The first value for the header field name. | ||
public subscript(first name: 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.
@weissi What are your thoughts about the spelling of this API? It sits a bit weirdly with me, but I don't know if it really matters.
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 think we should do something more similar to what the stdlib does for first(where:)
. What about first(name: 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.
That's fine by me: the only risk is that this type already has a first(where:)
so that API may get lost in the autocorrect.
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.
first(name:)
sounds good to me too.
…hing name Motivation: In some cases you only expect (or care about) a single value for a header. However, getting this value without allocating an array or traversing the whole array requres using first(where:) provided by Sequence. This is not very ergonomic as it requires users to do the case-insensitive comparison and then exctact the value from the HPACKHeader. Additionally, users cannot use NIO HTTP/2s case insensitive ASCII comparison. Modifications: - Provide a first(name:) method on HPACKHeaders which returns the value from the first header whose name is a case insentive match of the subscript parameter. Result: It's easier to get the first
c291d9c
to
8012942
Compare
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.
Still happy.
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.
awesome, lgtm
…hing name
Motivation:
In some cases you only expect (or care about) a single value for a
header. However, getting this value without allocating an array or
traversing the whole array requres using first(where:) provided by
Sequence. This is not very ergonomic as it requires users to do the
case-insensitive comparison and then exctact the value from the
HPACKHeader. Additionally, users cannot use NIO HTTP/2s case insensitive
ASCII comparison.
Modifications:
first header whose name is a case insentive match of the subscript
parameter.
Result: