Proxyman icon indicating copy to clipboard operation
Proxyman copied to clipboard

Request body shows as empty in Proxyman when using Atlantis

Open mborsten opened this issue 1 year ago • 17 comments

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

  • App version: e.g Proxyman 5.1.1
  • macOS version: e.g macOS Sonoma 14.4
  • Atlantis 1.24.0

mborsten avatar Mar 20 '24 09:03 mborsten

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

NghiaTranUIT avatar Mar 20 '24 10:03 NghiaTranUIT

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

mborsten avatar Mar 20 '24 10:03 mborsten

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

For example:

  • What Method, URL, and the Body Type (JSON, Data, Image, PDF, multipart, or Streaming Body?)
  • Websocket or normal HTTPS ?
  • The Content-Type Header of the Request If you don't mind, please export this request as a ProxymanLog and share it with me at [email protected]

I'd like to investigate it 👍

NghiaTranUIT avatar Mar 21 '24 01:03 NghiaTranUIT

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

mooshee avatar Mar 21 '24 18:03 mooshee

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

mooshee avatar Mar 21 '24 18:03 mooshee

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

mborsten avatar Mar 21 '24 19:03 mborsten

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

  • What is the Content-Type of the Request?

NghiaTranUIT avatar Mar 22 '24 01:03 NghiaTranUIT

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

mborsten avatar Mar 22 '24 13:03 mborsten

@mborsten it's quite simple: J

  1. Just right-click on this request -> Export -> ProxymanLog and share with me at [email protected]
  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 👍

NghiaTranUIT avatar Mar 23 '24 00:03 NghiaTranUIT

@NghiaTranUIT method being called is URLSession.uploadTaskWithStreamedRequest

mborsten avatar Apr 02 '24 07:04 mborsten

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

NghiaTranUIT avatar Apr 02 '24 07:04 NghiaTranUIT

@NghiaTranUIT Any update on when this will be added?

mooshee avatar Apr 15 '24 20:04 mooshee

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

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

NghiaTranUIT avatar Apr 16 '24 01:04 NghiaTranUIT

@mooshee @mborsten may I ask:

  • When using URLSession.uploadTaskWithStreamedRequest . Do you provide the Request Body via this delegate method: https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1410001-urlsession ?
  • Or from request.httpBody = data 🤔

NghiaTranUIT avatar Apr 16 '24 03:04 NghiaTranUIT

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.

NghiaTranUIT avatar Apr 16 '24 04:04 NghiaTranUIT

I'm using [request setHTTPBodyStream: stream];

mborsten avatar Apr 17 '24 13:04 mborsten

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

NghiaTranUIT avatar Apr 22 '24 02:04 NghiaTranUIT