If an NSURLProtocol subclass is used with NSURLSession the request body is nil

Number:rdar://15993891 Date Originated:05/02/2012
Status:Open Resolved:
Product:iOS SDK Product Version:7.0.x
Classification:Other Bug Reproducible:Always
If a custom NSURLProtocol is provided to NSURLSession, even if the NSURLRequest has an HTTPBody non-nil when the request is passed to the NRURLProtocol (such as canInitWithRequest: or canonicalRequestForRequest:) has an empty body

Steps to Reproduce:
1. Create a subclass NSURLProtocol
2. Create an NSURLSessionConfiguration and set as protocolClasses an array containing the previously created NSURLProtocol
3. Create an NSURLRequest with HTTPMethod = @"POST" and with non-nil HTTPBody 
4. Create a NSURLSession and an NSURLSessionDataTask with the given NSURLRequest
5. resume the NSURLSessionDataTask

Expected Results:
When the method of the NSURLProtocol subclass are called the provided request should contains the previously set body

Actual Results:
The NSURLProtocol subclass method are called with a request with a nil body

iOS 7.0.x

An example project is provided. The project demonstrate that with NSURLConnection the behavior is as expected, with NSURLSession the request has nil body


Worth nothing that Apple have demonstrated this field should be available in their example project:


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!