Skip to content

Commit 6675151

Browse files
committed
change to HTTPFields
1 parent 5bba6e3 commit 6675151

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

Sources/Realtime/PhoenixTransport.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// THE SOFTWARE.
2020

2121
import Foundation
22+
import HTTPTypes
2223

2324
#if canImport(FoundationNetworking)
2425
import FoundationNetworking
@@ -46,7 +47,7 @@ public protocol PhoenixTransport {
4647
- Parameters:
4748
- headers: Headers to include in the URLRequests when opening the Websocket connection. Can be empty [:]
4849
*/
49-
func connect(with headers: [String: String])
50+
func connect(with headers: HTTPFields)
5051

5152
/**
5253
Disconnect from the server.
@@ -192,19 +193,21 @@ open class URLSessionTransport: NSObject, PhoenixTransport, URLSessionWebSocketD
192193
public var readyState: PhoenixTransportReadyState = .closed
193194
public var delegate: (any PhoenixTransportDelegate)? = nil
194195

195-
public func connect(with headers: [String: String]) {
196+
public func connect(with headers: HTTPFields) {
196197
// Set the transport state as connecting
197198
readyState = .connecting
198199

199200
// Create the session and websocket task
200201
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)
208211

209212
// Start the task
210213
task?.resume()

Sources/Realtime/RealtimeClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public class RealtimeClient: PhoenixTransportDelegate {
344344
// self.connection?.enabledSSLCipherSuites = enabledSSLCipherSuites
345345
// #endif
346346

347-
connection?.connect(with: headers.dictionary)
347+
connection?.connect(with: headers)
348348
}
349349

350350
/// Disconnects the socket

0 commit comments

Comments
 (0)