|
19 | 19 | // THE SOFTWARE.
|
20 | 20 |
|
21 | 21 | import Foundation
|
| 22 | +import HTTPTypes |
22 | 23 |
|
23 | 24 | #if canImport(FoundationNetworking)
|
24 | 25 | import FoundationNetworking
|
@@ -46,7 +47,7 @@ public protocol PhoenixTransport {
|
46 | 47 | - Parameters:
|
47 | 48 | - headers: Headers to include in the URLRequests when opening the Websocket connection. Can be empty [:]
|
48 | 49 | */
|
49 |
| - func connect(with headers: [String: String]) |
| 50 | + func connect(with headers: HTTPFields) |
50 | 51 |
|
51 | 52 | /**
|
52 | 53 | Disconnect from the server.
|
@@ -192,19 +193,21 @@ open class URLSessionTransport: NSObject, PhoenixTransport, URLSessionWebSocketD
|
192 | 193 | public var readyState: PhoenixTransportReadyState = .closed
|
193 | 194 | public var delegate: (any PhoenixTransportDelegate)? = nil
|
194 | 195 |
|
195 |
| - public func connect(with headers: [String: String]) { |
| 196 | + public func connect(with headers: HTTPFields) { |
196 | 197 | // Set the transport state as connecting
|
197 | 198 | readyState = .connecting
|
198 | 199 |
|
199 | 200 | // Create the session and websocket task
|
200 | 201 | session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
|
201 |
| - var request = URLRequest(url: url) |
202 |
| - |
203 |
| - for (key, value) in headers { |
204 |
| - request.addValue(value, forHTTPHeaderField: key) |
205 |
| - } |
206 |
| - |
207 |
| - task = session?.webSocketTask(with: request) |
| 202 | + let request = HTTPRequest( |
| 203 | + method: .get, |
| 204 | + url: url, |
| 205 | + headerFields: headers |
| 206 | + ) |
| 207 | + |
| 208 | + let urlRequest = URLRequest(httpRequest: request)! |
| 209 | + |
| 210 | + task = session?.webSocketTask(with: urlRequest) |
208 | 211 |
|
209 | 212 | // Start the task
|
210 | 213 | task?.resume()
|
|
0 commit comments