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

Conditional stub responses #64

Closed
enrigalmig opened this issue Jun 10, 2014 · 4 comments
Closed

Conditional stub responses #64

enrigalmig opened this issue Jun 10, 2014 · 4 comments

Comments

@enrigalmig
Copy link

Hey Olivier

I'm trying to use the request in the responseRequests: method to do some conditional stubs in order to create the OHHTTPStubsResponse, I'm trying to get the parameters from a POST request that is generated with AFNetworking 2 but the httpbody is nil...

This is the right way to create conditional responses?

@AliSoftware
Copy link
Owner

Hello,

This is probably a duplicate of #52. The HTTPBody of requests passed to NSURLProtocols are known to be inaccessible (probably already turned into HTTPBodyStream objects by Apple internally).

So I believe the issue you are experimenting is not related to OHHTTPStubs but to how Apple's NSURLProtocol and NSURLSession works. This leads to NSURLProtocol's +canInitWithRequest: method to be called with a request with an empty HTTPBody, because HTTPBody and HTTPBodyStream properties are handled internally and specifically by Apple for the HTTP protocol (for the specific internal NSURLProtocol originally managing the "http://" scheme by Apple). This seems to be supported by various StackOverflow answers like url=http://stackoverflow.com/questions/9301611/using-a-custom-nsurlprotocol-with-uiwebview-and-post-requests.

@AliSoftware
Copy link
Owner

PS : As suggested by @lukabernardi in the other post, I encourage you fill a bugreport to Apple by duplicating the radar issue http://openradar.appspot.com/15993891

@enrigalmig
Copy link
Author

Thanks @AliSoftware

@AliSoftware
Copy link
Owner

FYI, I just wrote a short wiki article to suggest a nice workaround — using [NSURLProtocol setProperty:forKey:inRequest:] and [NSURLProtocol propertyForKey:inRequest:] and how to implement it for use with AFNetworking 2.0.

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

No branches or pull requests

2 participants