Skip to content

add HTTPHeaders.first(name:) #37

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

Merged
merged 5 commits into from
Jul 3, 2023
Merged

Conversation

MahdiBM
Copy link
Contributor

@MahdiBM MahdiBM commented Jun 29, 2023

Adds a new method first(name:) to HTTPHeaders (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's HTTPHeaders.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 of Sequence<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:) (aka Dictionary<String, String>.first(name:)).

@tomerd tomerd enabled auto-merge (squash) June 29, 2023 21:09
@tomerd
Copy link
Contributor

tomerd commented Jun 29, 2023

@swift-server-bot test this please

@tomerd
Copy link
Contributor

tomerd commented Jun 29, 2023

thanks @MahdiBM

auto-merge was automatically disabled June 30, 2023 02:50

Head branch was pushed to by a user without write access

@MahdiBM
Copy link
Contributor Author

MahdiBM commented Jun 30, 2023

@tomerd another try please 🙂

@tomerd
Copy link
Contributor

tomerd commented Jun 30, 2023

@swift-server-bot test this please

@MahdiBM
Copy link
Contributor Author

MahdiBM commented Jun 30, 2023

Hmm correct me if I'm wrong but the failure seems unrelated to the PR. Possibly just needs another retry.

@tomerd
Copy link
Contributor

tomerd commented Jul 3, 2023

@swift-server-bot test this please

@tomerd tomerd enabled auto-merge (squash) July 3, 2023 16:56
Copy link
Contributor

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

thanks @MahdiBM

@tomerd tomerd merged commit 3ac078f into swift-server:main Jul 3, 2023
@MahdiBM MahdiBM deleted the mmbm-http-headers branch July 4, 2023 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants