[GH-ISSUE #26] Support WebSocket #23

Open
opened 2026-03-03 19:11:01 +03:00 by kerem · 11 comments
Owner

Originally created by @NghiaTranUIT on GitHub (Nov 3, 2020).
Original GitHub issue: https://github.com/ProxymanApp/atlantis/issues/26

Originally assigned to: @NghiaTranUIT on GitHub.

Description

We can do "Method Swizzling" for send(_:completionHandler:) and receive(completionHandler:) from URLSessionWebSocketTask to capture the WS/WSS messages.

We should support this feature 👍

Acceptance Criteria

  • Do "Method Swizzling" to URLSessionWebSocketTask
  • Able to send the message to Proxyman for the inspector

If you have the same feature request, please add 👍 on this ticket.

Originally created by @NghiaTranUIT on GitHub (Nov 3, 2020). Original GitHub issue: https://github.com/ProxymanApp/atlantis/issues/26 Originally assigned to: @NghiaTranUIT on GitHub. ### Description We can do "Method Swizzling" for `send(_:completionHandler:)` and `receive(completionHandler:)` from `URLSessionWebSocketTask` to capture the WS/WSS messages. We should support this feature 👍 ### Acceptance Criteria - Do "Method Swizzling" to URLSessionWebSocketTask - Able to send the message to Proxyman for the inspector ------------- If you have the same feature request, please add 👍 on this ticket.
Author
Owner

@bastianh commented on GitHub (Jan 9, 2021):

this would be really helpful .. is there a easy way to add sending the data manually over the library ?

<!-- gh-comment-id:757346982 --> @bastianh commented on GitHub (Jan 9, 2021): this would be really helpful .. is there a easy way to add sending the data manually over the library ?
Author
Owner

@NghiaTranUIT commented on GitHub (Jan 10, 2021):

@bastianh It's possible to manually send the request/response to Proxyman by Atlantis. Please check out https://github.com/ProxymanApp/atlantis#advanced-usage

It's useful for apps that are using GRPC, C++ libraries, or other formats that haven't supported yet 👍

<!-- gh-comment-id:757400936 --> @NghiaTranUIT commented on GitHub (Jan 10, 2021): @bastianh It's possible to manually send the request/response to Proxyman by Atlantis. Please check out https://github.com/ProxymanApp/atlantis#advanced-usage It's useful for apps that are using GRPC, C++ libraries, or other formats that haven't supported yet 👍
Author
Owner

@bastianh commented on GitHub (Jan 10, 2021):

Yes.. I saw that .. but I have no idea how to do that for a websocket connection..

I'm starting it with this snippet:

let webSocketTask = URLSession.shared.webSocketTask(with: url)

and then get only callbacks for message that I receive.

<!-- gh-comment-id:757440023 --> @bastianh commented on GitHub (Jan 10, 2021): Yes.. I saw that .. but I have no idea how to do that for a websocket connection.. I'm starting it with this snippet: ``` let webSocketTask = URLSession.shared.webSocketTask(with: url) ``` and then get only callbacks for message that I receive.
Author
Owner

@NghiaTranUIT commented on GitHub (Jan 10, 2021):

Sorry for this. The code I show you only work with HTTP/HTTPS request/response, not WS/WSS for now :/

I will add this feature to the next release 👍

<!-- gh-comment-id:757471151 --> @NghiaTranUIT commented on GitHub (Jan 10, 2021): Sorry for this. The code I show you only work with HTTP/HTTPS request/response, not WS/WSS for now :/ I will add this feature to the next release 👍
Author
Owner

@bastianh commented on GitHub (Jan 10, 2021):

great... thank you

<!-- gh-comment-id:757486356 --> @bastianh commented on GitHub (Jan 10, 2021): great... thank you
Author
Owner

@NghiaTranUIT commented on GitHub (Apr 9, 2021):

The good news here 🎉

I'm working on this ticket, so we can capture the WS/WSS from your iOS with ease.

This feature might be a reasonable solution to fix the bug that Proxyman app couldn't capture WS/WSS from URLSessionWebsocketTask (https://github.com/ProxymanApp/Proxyman/issues/586#issuecomment-720197948)

<!-- gh-comment-id:816726048 --> @NghiaTranUIT commented on GitHub (Apr 9, 2021): The good news here 🎉 I'm working on this ticket, so we can capture the WS/WSS from your iOS with ease. This feature might be a reasonable solution to fix the bug that Proxyman app couldn't capture WS/WSS from URLSessionWebsocketTask (https://github.com/ProxymanApp/Proxyman/issues/586#issuecomment-720197948)
Author
Owner

@youjinp commented on GitHub (Apr 17, 2021):

I've just tried this new update, and it's working with WSS from URLSessionWebsocketTask 😀! Thanks for the update!

However I also tried it on Starscream and it didn't work 😕. I've read their source code and it seems like they're not using __NSURLSessionWebSocketTask but instead some low level CoreFoundation API CFStreamCreatePairWithSocketToHost?

Do you have any idea how to approach that? It doesn't seem like a method that can be swizzled? Seems to me like a function.. (I'm not super fluent with Objective-C)

<!-- gh-comment-id:821773688 --> @youjinp commented on GitHub (Apr 17, 2021): I've just tried this new update, and it's working with WSS from URLSessionWebsocketTask 😀! Thanks for the update! However I also tried it on [Starscream](https://github.com/daltoniam/Starscream) and it didn't work 😕. I've read their [source code](https://github.com/daltoniam/Starscream/blob/master/Sources/Transport/FoundationTransport.swift) and it seems like they're not using `__NSURLSessionWebSocketTask` but instead some low level CoreFoundation API `CFStreamCreatePairWithSocketToHost`? Do you have any idea how to approach that? It doesn't seem like a method that can be swizzled? Seems to me like a function.. (I'm not super fluent with Objective-C)
Author
Owner

@NghiaTranUIT commented on GitHub (Apr 17, 2021):

@youjinp let set useCustomEngine: false, so Starscream can use Native Engine (URLSessionWebsocket).

let socket = WebSocket(request: URLRequest(url: URL(string: "wss://echo.websocket.org")!), useCustomEngine: false)
<!-- gh-comment-id:821783762 --> @NghiaTranUIT commented on GitHub (Apr 17, 2021): @youjinp let set `useCustomEngine: false`, so Starscream can use Native Engine (URLSessionWebsocket). ```swift let socket = WebSocket(request: URLRequest(url: URL(string: "wss://echo.websocket.org")!), useCustomEngine: false) ```
Author
Owner

@NghiaTranUIT commented on GitHub (Apr 17, 2021):

For low-level CoreFoundation API CFStreamCreatePairWithSocketToHost, I suppose that it's impossible to do Method Swizzling because it's a C func, not Objective-C

<!-- gh-comment-id:821783931 --> @NghiaTranUIT commented on GitHub (Apr 17, 2021): For low-level CoreFoundation API CFStreamCreatePairWithSocketToHost, I suppose that it's impossible to do Method Swizzling because it's a C func, not Objective-C
Author
Owner

@youjinp commented on GitHub (Apr 17, 2021):

Yep. Thought so 👍

<!-- gh-comment-id:821784457 --> @youjinp commented on GitHub (Apr 17, 2021): Yep. Thought so 👍
Author
Owner

@NghiaTranUIT commented on GitHub (May 27, 2021):

@youjinp Just a friendly reminder that Atlantis has supported WS/WSS from URLSessionWebSocketTask 👍

Release: https://github.com/ProxymanApp/atlantis/releases/tag/1.9.0

<!-- gh-comment-id:849273657 --> @NghiaTranUIT commented on GitHub (May 27, 2021): @youjinp Just a friendly reminder that Atlantis has supported WS/WSS from URLSessionWebSocketTask 👍 Release: https://github.com/ProxymanApp/atlantis/releases/tag/1.9.0
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/atlantis#23
No description provided.