-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add support for proxying in WebsocketClient
#130
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Could you add DocC comments to all the new public APIs? Thanks!
@@ -67,4 +67,68 @@ extension WebSocket { | |||
onUpgrade: onUpgrade | |||
) | |||
} | |||
|
|||
public static func connect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add DocC comments for the new public APIs? Thanks!
public var minNonFinalFragmentSize: Int | ||
public var maxAccumulatedFrameCount: Int | ||
public var maxAccumulatedFrameSize: Int | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add DocC comments describing what these are for?
|
||
let localWebsocketBin: WebsocketBin | ||
let verifyProxyHead = { (ctx: ChannelHandlerContext, requestHead: HTTPRequestHead) in | ||
XCTAssertEqual(requestHead.uri, "ws://apple.com/:\(ctx.localAddress!.port!)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm this is a simulated proxy and not something we're going out on the network for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we do a somewhat convoluted dance to insert and remove channel handlers to mimic a proxy e.g. intercepting the CONNECT
request.
Thanks for the review @0xTim. I've pushed the changes you requested and also some performance improvements in a separate commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding these! Few more places for DocC comments and then we're good to go!
) | ||
} | ||
|
||
public static func connect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing comments
} | ||
} | ||
|
||
public func send( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing DocC comments
self.connect(scheme: scheme, host: host, port: port, path: path, query: query, headers: headers, proxy: nil, onUpgrade: onUpgrade) | ||
} | ||
|
||
public func connect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing DocC comments
@@ -2,27 +2,72 @@ import NIO | |||
import NIOWebSocket | |||
|
|||
extension WebSocket { | |||
|
|||
public struct Configuration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing DocC comments (and on the public functions in the type)
Added support for TLS and plain text proxying of Websocket traffic. In the TLS case a CONNECT header is first sent establishing the proxied traffic. In the plain text case the modified URI in the initial upgrade request header indicates to the proxy server that the traffic is to be proxied. Use `NIOWebSocketFrameAggregator` to handle aggregating frame fragments. This brings with it more protections e.g. against memory exhaustion. Accompanying config has been added to support this change.
Reduce allocation and copies necessary to send `ByteBuffer` and `ByteBufferView` through `WebSocket.send`. In fact sending `ByteBuffer` or `ByteBufferView` doesn’t require any allocation or copy of the data. Sending a `String` now correctly pre allocates the `ByteBuffer` if multibyte characters are present in the `String`. Remove custom random websocket mask generation which would only generate bytes between `UInt8.min..<UInt8.max`, therefore excluding `UInt8.max` aka `255`.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #130 +/- ##
==========================================
- Coverage 71.15% 67.54% -3.62%
==========================================
Files 5 6 +1
Lines 475 758 +283
==========================================
+ Hits 338 512 +174
- Misses 137 246 +109
|
Sorry about the delay. The missing DocC comments should now be there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
WebsocketClient
These changes are now available in 2.8.0 |
FYI nightly error is being tracked at swiftlang/swift#65064 |
Added support for TLS and plain text proxying of Websocket traffic.
In the TLS case a
CONNECT
header is first sent establishing the proxied traffic.In the plain text case the modified URI in the initial upgrade request header indicates to the proxy server that the traffic is to be proxied.
Use
NIOWebSocketFrameAggregator
to handle aggregating frame fragments. This brings with it more protections e.g. against memory exhaustion.Accompanying config has been added to support this change.
This change also includes some performance gains by reducing the allocation and copies necessary to send
ByteBuffer
andByteBufferView
throughWebSocket.send
.Sending
ByteBuffer
orByteBufferView
doesn’t require any allocation or copy of the data. Sending aString
now correctly pre allocates theByteBuffer
if multibyte characters are present in theString
.Remove custom random websocket mask generation which would only generate bytes between
UInt8.min..<UInt8.max
, therefore excludingUInt8.max
i.e.255
.