atlantis icon indicating copy to clipboard operation
atlantis copied to clipboard

Support WebSocket

Open NghiaTranUIT opened this issue 4 years ago • 11 comments

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.

NghiaTranUIT avatar Nov 03 '20 04:11 NghiaTranUIT

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

bastianh avatar Jan 09 '21 18:01 bastianh

@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 👍

NghiaTranUIT avatar Jan 10 '21 02:01 NghiaTranUIT

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.

bastianh avatar Jan 10 '21 08:01 bastianh

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 👍

NghiaTranUIT avatar Jan 10 '21 12:01 NghiaTranUIT

great... thank you

bastianh avatar Jan 10 '21 14:01 bastianh

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)

NghiaTranUIT avatar Apr 09 '21 14:04 NghiaTranUIT

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)

youjinp avatar Apr 17 '21 06:04 youjinp

@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)

NghiaTranUIT avatar Apr 17 '21 07:04 NghiaTranUIT

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

NghiaTranUIT avatar Apr 17 '21 07:04 NghiaTranUIT

Yep. Thought so 👍

youjinp avatar Apr 17 '21 07:04 youjinp

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

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

NghiaTranUIT avatar May 27 '21 02:05 NghiaTranUIT