atlantis icon indicating copy to clipboard operation
atlantis copied to clipboard

Consider Separating API from Use Case

Open Sherlouk opened this issue 4 years ago • 8 comments

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 😄

Sherlouk avatar Jan 19 '21 21:01 Sherlouk

Hi, Glad to know that you love Proxyman 😄

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

  • One for only Method Swizzling to automatically capture all traffic and notify the observer
  • One that is a Transport layer (Use Bonjour)

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:

  • Add a Flag to disable the Bonjour Service
  • Add simple Observer class to Atlantis that you can register.

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

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

NghiaTranUIT avatar Jan 20 '21 02:01 NghiaTranUIT

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

Sherlouk avatar Jan 20 '21 09:01 Sherlouk

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

NghiaTranUIT avatar Jan 21 '21 03:01 NghiaTranUIT

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

Sherlouk avatar Jan 21 '21 13:01 Sherlouk

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 👍

NghiaTranUIT avatar Jan 21 '21 15:01 NghiaTranUIT

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

Sherlouk avatar Jan 21 '21 16:01 Sherlouk

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

NghiaTranUIT avatar Jan 22 '21 03:01 NghiaTranUIT

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

NghiaTranUIT avatar Jan 22 '21 03:01 NghiaTranUIT