-
Notifications
You must be signed in to change notification settings - Fork 75
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
Fixes a CFNetwork runtime warning #191
Conversation
- (NSData *)swz_HTTPBody | ||
{ | ||
// upload tasks will trigger a runtime warning if their body is non-nil, see note above | ||
if ([self sbt_isUploadTaskRequest]) { | ||
return nil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the actual warning is avoided
if (![matcher matches:requestBody]) { | ||
|
||
// an upload task previously stored its body contents in NSURLProtocol to avoid a CFNetwork runtime warning | ||
NSData *body = ([request sbt_isUploadTaskRequest]) ? [request sbt_uploadHTTPBody] : request.HTTPBody; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where we fetch the original body differently for upload tasks
|
||
NSString * const SBTUITunneledNSURLProtocolIsUploadTaskKey = @"SBTUITunneledNSURLProtocolIsUploadTaskKey"; | ||
|
||
- (NSData *)sbt_uploadHTTPBody |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test that covers these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests
…ontains an HTTP body.
10f0835
to
c191099
Compare
Work towards #186.
In Xcode 15+ CFNetwork emits a runtime warning when an upload task contains a body:
To work around this, we keep track of requests originating from upload tasks with the existing swizzling in
NSURLSession+HTTPBodyFix
. For those tasks, we save the original body via NSURLProtocol and remove it from the request to avoid the warning.When using a request body (e.g., when matching stubs), previously marked upload requests must exclusively reference the copy from NSURLProtocol because the request's
HTTPBody
was cleared.