ProxymanApp / Proxyman

Modern. Native. Delightful Web Debugging Proxy for macOS, iOS, and Android ⚡️
https://proxyman.io
5.35k stars 177 forks source link

Request body shows as empty in Proxyman when using Atlantis #1978

Open mborsten opened 3 months ago

mborsten commented 3 months ago

Description

Some requests, not all, show as having an empty body in Proxyman when using Atlantis framework in an iOS project

Steps to Reproduce

  1. Add Atlantis to an iOS project
  2. Initialise Atlantis: [Atlantis startWithHostName:nil shouldCaptureWebSocketTraffic: NO];
  3. Make requests using NSURLSession;

Current Behavior

Sometimes the request shows an empty body, where there was data in the body. The response do show a body. This is not for all requests. The same request might or might not show a body when repeated/

Expected Behavior

All requests that have body data should show the body data in Proxyman.

Environment

NghiaTranUIT commented 3 months ago

Maybe the response is cached on your client, so there is no body to capture and send to Proxyman.

Can you verify it?

You can test it by using no caching policy from URLSession

mborsten commented 3 months ago

It is the request that has the empty body, not the response.

NghiaTranUIT commented 3 months ago

@mborsten can you share with me the log or any useful information that we can check?

For example:

I'd like to investigate it 👍

mooshee commented 3 months ago

I'm having the same issue. This was working a week or two ago. Not sure what changed.

mooshee commented 3 months ago

I even tried to rollback a caouple versions of Proxyman and Atlantis to no avail. Perhaps it's swizzling issue. Proxyman v4.16.0 from Jan 7 Atlantis v1.22.0

mborsten commented 3 months ago

I think this is failing in atlantis, I've set a berakpoint and I can see that the body in the request of the message is nil. In the backend I do receive the body, so the request is OK:

Scherm­afbeelding 2024-03-21 om 20 12 38
NghiaTranUIT commented 3 months ago

@mborsten I guess the issue is from the Method Swizzling.

If you can set the breakpoint, can you trace back what URLSessionURLTask's method is called? I suppose that it's not URLSession.dataTaskWithURL: or URLSession.dataTaskWithRequest 🤔

May I ask:

mborsten commented 3 months ago

The content-type is 'application/json', I will try to get more information for you

NghiaTranUIT commented 3 months ago

@mborsten it's quite simple: J

  1. Just right-click on this request -> Export -> ProxymanLog and share with me at support@proxyman.io
  2. and If you can set the Breakpoint as your last comment, please trace back to what URLSession's method is called.

I will try to investigate it 👍

mborsten commented 3 months ago

@NghiaTranUIT method being called is URLSession.uploadTaskWithStreamedRequest

NghiaTranUIT commented 3 months ago

Nice. This API hasn't been implemented with the Method Swizzling yet. Let me support it 👍

mooshee commented 2 months ago

@NghiaTranUIT Any update on when this will be added?

NghiaTranUIT commented 2 months ago

Not yet @mborsten I'm working on it now 👍

May I ask that you need to capture traffic from URLSession.uploadTaskWithStreamedRequest too ?

NghiaTranUIT commented 2 months ago

@mooshee @mborsten may I ask:

NghiaTranUIT commented 2 months ago

if you provide the body via: request.httpBody = data I can make it work and send you a Beta build.

If it's from the delegate, I'm still looking for a solution. I tried, but It's hard to inject into its runtime.

mborsten commented 2 months ago

I'm using [request setHTTPBodyStream: stream];

NghiaTranUIT commented 2 months ago

@mborsten I'm not sure how you can use request.httpBodyStream = ... while using URLSession.uploadTaskWithStreamedRequest() ?

because I get this error:

The request of a upload task should not contain a body or a body stream, use `upload(for:fromFile:)`, `upload(for:from:)`, or supply the body stream through the `urlSession(_:needNewBodyStreamForTask:)` delegate method.
Screenshot 2024-04-22 at 9 18 46 AM

The body is ignored and other tools can't capture it.