ProxymanApp / atlantis

Capture HTTP/HTTPS, and Websocket from iOS app without proxy.
https://proxyman.io
Apache License 2.0
1.27k stars 95 forks source link

Consider Separating API from Use Case #52

Open Sherlouk opened 3 years ago

Sherlouk commented 3 years ago

Hey @NghiaTranUIT 👋

First off just wanted to say I love Proxyman - I use it personally and it's a breath of fresh air from what feels like an ancient Charles Proxy! 🙌

I just wondered how you felt about the idea of separating Atlantis down into two distinct 'targets' (to use SPM terminology) or 'subspecs' (CocoaPods).

In essence, I have a use case where I want to monitor network traffic as part of a debug monitoring package.

In its simplest form I'd want to register an observer/listener which receives a call with the request/response every time a request is completed. It should work automatically (method swizzling) or through the manual API as per your implementation documentation.

The reason I mention specifically breaking it down into two distinct frameworks is that it'd be nice to not have to include the transporter or bonjour/local network components which would generally improve the amount of use cases?

Thanks 😄

NghiaTranUIT commented 3 years ago

Hi, Glad to know that you love Proxyman 😄

It's possible to support two targets (SMP):

But it's quite complicated to implement it at the moment (since I have a plan to support WS/WSS too).


However, I can quick support:

It doesn't change the structure of the project and it can be implemented easily.

What do you think? Is it fit your case? 🤔

Sherlouk commented 3 years ago

Thanks for the quick response! That'd certainly help support my use case 🙌

We can of course still keep an issue around for a longer-term improvement to break the project down, but it won't be as time critical if we can still carry out our pieces

NghiaTranUIT commented 3 years ago

@Sherlouk If you don't mind, please check out this branch (https://github.com/ProxymanApp/atlantis/pull/53)

pod 'atlantis-proxyman', :git => 'https://github.com/ProxymanApp/atlantis.git', :branch => 'feat/better-interface'

From now, you can disable the Bonjour and observe the traffic from its delegate:

// Set from didFinishLaunchingWithOptions
Atlantis.setDelegate(self)
Atlantis.setEnableTransportLayer(false)
Atlantis.start()

extension AppDelegate: AtlantisDelegate {

    func atlantisDidHaveNewPackage(_ package: TrafficPackage) {
        print("New package id=\(package.id)")
        print("Request URL = \(package.request.url), bodyCount=\(package.request.body?.count ?? 0)")
        print("Response code=\(package.response?.statusCode)")
    }
}

Please let me know if it works for you 👍

Sherlouk commented 3 years ago

Hey @NghiaTranUIT 👋

Thanks for the quick work! The PR looks perfect for what we need.

Analyzing dependencies
Pre-downloading: `atlantis-proxyman` from `https://github.com/ProxymanApp/atlantis.git`, branch `feat/better-interface`
[!] Failed to load 'atlantis-proxyman' podspec: 
[!] Invalid `atlantis-proxyman.podspec` file: undefined method `swift_versions=' for #<Pod::Specification name="atlantis-proxyman">
Did you mean?  swift_version=
               swift_version.

 #  from /var/folders/3q/2m5qbcmn66lc55t3st59p5_4fw_hpx/T/d20210121-45534-borzj0/atlantis-proxyman.podspec:27
 #  -------------------------------------------
 #    spec.source_files  = 'Sources/*.swift'
 >    spec.swift_versions = ['5.0', '5.1', '5.2', '5.3']
 #  end
 #  -------------------------------------------

Unfortunately I'm getting an unrelated issue when installing the CocoaPod - and we've not yet upgraded to Xcode 12 for the SPM version (in the main project).

I'll download it into a sample project this evening to triple check behaviour and confirm 👍 Sorry for the delay

NghiaTranUIT commented 3 years ago

Thanks for letting me know. I will upload a better sample project for the Atlantis project in this week. It's easier for other users who would try the Atlantis 👍

Sherlouk commented 3 years ago

I have also just got it working on an experimental Xcode 12 branch using the SPM integration and it's working beautifully. Huge appreciation for getting that done

NghiaTranUIT commented 3 years ago

Glad to know it works for you. I will finalize the PR and bump a version today 😄

NghiaTranUIT commented 3 years ago

Just let you know that the PR, which includes a new Example Code as I promise is closed due to a few limitations of SMP #54