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

Allow session to be passed in #237

Merged
merged 2 commits into from Feb 22, 2018

Conversation

@steffendsommer
Copy link
Member

steffendsommer commented Feb 22, 2018

In my current project I ran into an issue where I needed to proxy using https. I wasn't able to do this and after speaking with @tanner0101 he suggested the I looked into URLSession. Using the proxy configuration for URLSession allowed me to do what I wanted to do.

This PR would make the FoundationClient more flexible since one could pass in their own configured URLSession. AFAIK this PR shouldn't break any public API's.

@steffendsommer steffendsommer requested review from tanner0101 and Joannis Feb 22, 2018

@@ -15,12 +15,13 @@ public final class FoundationClient: Client {
public init(
scheme: String,
hostname: String,
port: Transport.Port
port: Transport.Port,
session: URLSession

This comment has been minimized.

@calebkleveter

calebkleveter Feb 22, 2018

Member

You can remove the second init by adding a default parameter here:

session: URLSession = URLSession(configuration: .default)

This comment has been minimized.

@Joannis

Joannis Feb 22, 2018

Member

agreed 👍

This comment has been minimized.

@BrettRToomey

BrettRToomey Feb 22, 2018

Contributor

We explicitly avoided a default parameter here

This comment has been minimized.

@calebkleveter
@steffendsommer

This comment has been minimized.

Copy link
Member Author

steffendsommer commented Feb 22, 2018

Updated to use default parameter over the convenience init @Joannis @calebkleveter

@Joannis
Copy link
Member

Joannis left a comment

LGTM

@tanner0101 tanner0101 added this to the 2.2.3 milestone Feb 22, 2018

@tanner0101 tanner0101 self-assigned this Feb 22, 2018

@tanner0101

This comment has been minimized.

Copy link
Member

tanner0101 commented Feb 22, 2018

Thanks @steffendsommer, I'm glad that worked out.

For the record, the problem here was that Vapor's proxy configuration only supports requesting plaintext HTTP (non-TLS). The implementation behind this is pretty simple: we just send the request to the proxy instead, and the proxy is responsible for giving us the correct response.

However, for TLS, the problem is more involved. The whole point of TLS obviously is to prevent eavesdropping. To create a secure TLS connection, the proxy must not know the contents of the request or response. To achieve this, you need to send a special CONNECT (http method) request to the proxy first. This allows you to use the proxy as a simple TCP stream to the destination server. On top of this, you can implement your TLS protected HTTP request normally.

This is something we can consider adding native stream support for in Vapor 3. However, given that URLSession works quite well we may just want to rely on that.

@tanner0101 tanner0101 merged commit c8072bc into master Feb 22, 2018

3 checks passed

ci/circleci: linux Your tests passed on CircleCI!
Details
ci/circleci: linux-3 Your tests passed on CircleCI!
Details
ci/circleci: macos Your tests passed on CircleCI!
Details

@tanner0101 tanner0101 deleted the feature/make-urlsession-configurable branch Feb 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment