Kitura / SwiftyRequest

SwiftyRequest is an HTTP networking library built for Swift.
Apache License 2.0
110 stars 19 forks source link

No way to disable shared URLSession #65

Closed TaborKelly closed 5 years ago

TaborKelly commented 5 years ago

There is no way to disable the shared URLSession:

public class RestRequest: NSObject  {
...
    /// A default `URLSession` instance.
    #if swift(>=4.1)
    private var session: URLSession = URLSession.shared
    #else
    private var session: URLSession = URLSession(configuration: URLSessionConfiguration.default)
    #endif
...
    public init(method: HTTPMethod = .get, url: String, containsSelfSignedCert: Bool? = false, clientCertificate: ClientCertificate? = nil) {
...
Andrew-Lees11 commented 5 years ago

Do you require it to not be a shared session? We could allow you to provide your own session so you can set configuration values if you need.

TaborKelly commented 5 years ago

I'm using SwiftyRequest for testing an existing Kitura API that is designed for access by vanilla JavaScript (and C). For some of my test cases I need to be able to reset the cookie store. After further investigation, what I really need to be able to do is reset() the URLSession that I am using as finishTasksAndInvalidate() doesn't seem to be enough.

Which is a long way of saying yes, if I could provide my own URLSession that would be very helpful.

Andrew-Lees11 commented 5 years ago

@TaborKelly Can you just confirm that pr #66 making the URLSession public would fix your issue?

Andrew-Lees11 commented 5 years ago

Closing since the URLSession is now public. This will give you access to the session change it or replace it and has been released in version 2.1.0

TaborKelly commented 5 years ago

Sorry for the late reply. Yes, that looks great!