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

[SR-3463] [URLSession] config.httpAdditionalHeaders isn't picked up #3903

Closed
pushkarnk opened this issue Dec 20, 2016 · 3 comments
Closed

[SR-3463] [URLSession] config.httpAdditionalHeaders isn't picked up #3903

pushkarnk opened this issue Dec 20, 2016 · 3 comments

Comments

@pushkarnk
Copy link
Collaborator

Previous ID SR-3463
Radar None
Original Reporter @pushkarnk
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 2
Component/s Foundation
Labels Bug
Assignee enasser (JIRA)
Priority Medium

md5: 276b8e47a028742e30a0858d5ea53906

Issue Description:

Creating a URLSession configuration and then using configuration.httpAdditionalHeaders to set additional header flags doesn't work.

This problem has also been reported on StackOverflow here:
http://stackoverflow.com/questions/41229814/httpadditionalheaders-not-working-on-linux

@swift-ci
Copy link
Contributor

Comment by Niklas Saers (JIRA)

I am seeing almost the same http://stackoverflow.com/questions/41601863/urlsession-on-linux-giving-different-result-than-on-ios:

  • setting httpAdditionalHeaders works about half the time

  • setting headers via httpRequest.setValue(_, forHTTPHeaderField🙂 works most of the time
    but either way, by testing again and again, some requests are sent without headers for what should be identical runs.

All source and tcp packet captures are here: https://github.com/niklassaers/SO_UrlsessionTest

@swift-ci
Copy link
Contributor

Comment by Nasser Ebrahim (JIRA)

Analyzed the issue further. I could see that httpAddionalHeaders are set properly to the URLSession configuration however it is not getting added to the URLRequest. As per the documentation, the httpAddionalHeaders from the session configuration should be inherited to the URLRequest.

The URLRequest can be used with any URLSession and hence cannot be added while creating the request. Also, there is no direct link between URLSession and URLRequest till a dataTask is created. Hence, dataTask is the first opportunity to update the Request with httpAddionalHeaders from the corresponding URLSession configuration.

In NSURLSessionTask, the request can be updated while configuring the connection handle in configureEasyHandle.

In configurEasyHandle, the headers for Request is set by calling curHeaders with request which extract the header information from allHTTPHeaderFields of the request.

The httpAddionalHeaders needs to be overridden if the same header element is updated in the request. This can be achieved if httpAddionalHeaders from the session configuration is added first and then append/update with allHTTPHeaderFields of the request.

@swift-ci
Copy link
Contributor

Comment by Nasser Ebrahim (JIRA)

Have created the pull request : #927

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants