Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netfox makes iOS go crazy when intercepting URLRequests when httpBodyStream is set #190

Open
srmadden opened this issue Jan 23, 2020 · 1 comment
Labels

Comments

@srmadden
Copy link

We have an app that uploads a file via a POST request by doing something like:

NSInputStream *inputStream = [[NSInputStream alloc] initWithFileAtPath:fileToSend];
[request setHTTPBodyStream:inputStream];

Executing code like this when netfox is active causes several bad things to happen:

  1. The request never completes (times out)
  2. iOS allocates a crazy amount of memory, with hundred of thousands of CTHTTPMessage and HTTP2StreamBridge objects being allocated by CFNetwork (see screenshot from the debug memory graph in Xcode)

(Of course, neither of these things happens when netfox is not active)

I've tracked this issue to the getNFXBody() method in NFXHelper.swift and the readfully() method; specifically, this line:

return httpBodyStream?.readfully() ?? URLProtocol.property(forKey: "NFXBodyData", in: self) as? Data ?? Data()

calls readfully(), which proceeds to read the contents of the httpBodyStream object. Note that calling read() on httpBodyStream is discouraged by Apple's docs on the httpBodyStream object, which say:

The stream is returned for examination only; it’s unsafe for the caller to manipulate the stream in any way.

Modifying readfully() to simply return an empty data object makes this issue go away.

Screen Shot 2020-01-22 at 8 38 38 PM

@dhcdht
Copy link

dhcdht commented Jan 7, 2021

Did you resolve this? @srmadden

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants