Skip to content
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

Merged
merged 3 commits into from
Dec 4, 2019

Conversation

glbrntt
Copy link
Contributor

@glbrntt glbrntt commented Dec 2, 2019

…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 subscript 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 only the first header matching a given name

@glbrntt glbrntt requested a review from Lukasa December 2, 2019 16:45
@Lukasa Lukasa added the semver/minor Adds new public API. label Dec 2, 2019
@Lukasa Lukasa added this to the 1.8.0 milestone Dec 2, 2019
Copy link
Contributor

@Lukasa Lukasa left a 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.

///
/// - 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? {
Copy link
Contributor

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.

Copy link
Member

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)?

Copy link
Contributor

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.

Copy link
Contributor Author

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
@glbrntt glbrntt requested a review from weissi December 3, 2019 17:07
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still happy.

Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, lgtm

@weissi weissi merged commit a8f89aa into apple:master Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants