Skip to content

Commit 2380f02

Browse files
authored
Add ability to specify the URLSessionWebSocketTask maximumMessageSize (#291)
* add ability to specify the URLSessionWebSocketTask maximumMessageSize
1 parent b727ad8 commit 2380f02

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Sources/SignalRClient/HttpConnectionOptions.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ public class HttpConnectionOptions {
4747
The timeout value for individual requests, in seconds.
4848
*/
4949
public var requestTimeout: TimeInterval = 120
50-
50+
51+
/**
52+
The maximum number of bytes to buffer before the receive call fails with an error.
53+
54+
This value includes the sum of all bytes from continuation frames. Receive calls will fail once the task reaches this limit. (URLSessionWebSocketTask)
55+
*/
56+
public var maximumWebsocketMessageSize: Int?
57+
5158
public var authenticationChallengeHandler: ((_ session: URLSession, _ challenge: URLAuthenticationChallenge, _ completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void)?
5259

5360
/**

Sources/SignalRClient/HubConnectionBuilder.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public class HubConnectionBuilder {
171171
httpConnectionOptionsCopy.skipNegotiation = httpConnectionOptions.skipNegotiation
172172
}
173173
httpConnectionOptionsCopy.requestTimeout = httpConnectionOptions.requestTimeout
174+
httpConnectionOptionsCopy.maximumWebsocketMessageSize = httpConnectionOptions.maximumWebsocketMessageSize
174175
httpConnectionOptionsCopy.callbackQueue = httpConnectionOptions.callbackQueue
175176
httpConnectionOptionsCopy.authenticationChallengeHandler = httpConnectionOptions.authenticationChallengeHandler
176177
return HttpConnection(url: url, options: httpConnectionOptionsCopy, transportFactory: transportFactory, logger: logger)

Sources/SignalRClient/WebsocketsTransport.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public class WebsocketsTransport: NSObject, Transport, URLSessionWebSocketDelega
3535
setAccessToken(accessTokenProvider: options.accessTokenProvider, request: &request)
3636
urlSession = URLSession(configuration: .default, delegate: self, delegateQueue: OperationQueue())
3737
webSocketTask = urlSession!.webSocketTask(with: request)
38-
38+
if let maximumWebsocketMessageSize = options.maximumWebsocketMessageSize {
39+
webSocketTask?.maximumMessageSize = maximumWebsocketMessageSize
40+
}
41+
3942
webSocketTask!.resume()
4043
}
4144

0 commit comments

Comments
 (0)