Does anybody know where an iOS app can see the default headers that NSUrlRequest
sets for an HTTP request?
Just creating NSUrlRequest
with "http://.." NSURL
and then asking: [request allHTTPHeaderFields]
returns an empty dictionary. But I know that for example "Accept-Encoding" is set to "gzip". So I want to get all that fields and show them in a HTTP request demo.
I've also tried to swizzle [NSMutableURLRequest setValue:forHTTPHeaderField:]
, but it seems that it is not used by underlying API (NSURLRequest or NSURLConnection) to set those default fields I'm hunting for.
I'm making just a simple iOS demo which shows HTTP request and response information, so it doesn't really matters if it will be a public or private API used for that.
Your app cannot. It's done all down in CFNetwork - Communicating with HTTP Servers. I believe it just adds missing header values not supplied by NSURLRequest.
The defaults are: