NSHTTPURLResponse should surface HTTP trailers
| Originator: | jcanizales | ||
| Number: | rdar://26845013 | Date Originated: | 16-Jun-2016 01:17 PM |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | iOS 10.0-beta (14A5261u), and 9.3 |
| Classification: | Feature (new) | Reproducible: | N/A |
Summary:
HTTP trailers (introduced in HTTP/1.1 and present in HTTP/2 too) are an essential feature for protocols on top of HTTP to:
- Signal errors occurred while the response was already being streamed to the client.
- Send metadata whose value can only be known by the server when it's finished streaming a response (e.g. for dynamically-generated responses).
NSHTTPURLResponse has an allHeaderFields property, from which the response headers can be read by an NSURLSession delegate before the response body is received. There is no corresponding property for reading the trailers after the response is completed.
Steps to Reproduce:
Use NSURLSession to connect to an HTTP/2 server that sends trailers. E.g. (in Swift 3 syntax):
import UIKit
let session = URLSession(configuration: URLSessionConfiguration.default())
let url = URL(string: "https://grpc-test.sandbox.googleapis.com/grpc.testing.TestService/EmptyCall")!
var request = URLRequest(url: url)
// That specific server would return a 404 if we didn't set these:
request.httpMethod = "POST"
request.addValue("application/grpc", forHTTPHeaderField: "content-type")
request.addValue("trailers", forHTTPHeaderField: "te")
let requestData = Data(bytes: [0, 0, 0, 0, 0])
session.uploadTask(with: request, from: requestData) { (data, response, error) in
if let httpResponse = response as? NSHTTPURLResponse {
print("Headers:\n\(httpResponse.allHeaderFields)")
// Trailers?
}
}.resume()
(Using a delegate instead of a callback makes it clear why adding both headers and trailers into allHeaderFields might not be a great fit for this: I can read response.allHeaderFields before any trailer has been received).
Expected Results:
NSHTTPURLResponse having an allTrailerFields property, from which trailers can be accessed by the delegate when the response is finished; or anything with equivalent functionality.
Actual Results:
No such property. (If you run the code above, CFNetwork asserts - that's already filed as radar 26843578).
Comments
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!