New: -CPHTTPURLResponse allHeaderFields.

When a CPURLConnection response is of the CPHTTPURLResponse type, the raw HTTP headers can now be retrieved through the allHeaderFields message.
This commit is contained in:
Alexander Ljungberg committed 2013-01-11 10:53:42 +00:00
1 parent 1a54aadff0
commit 7485c4eb7a
2 files changed
+42 -1

No files matched your search

+1
View File
@@ -250,6 +250,7 @@ var CPURLConnectionDelegate = nil;
{
var response = [[CPHTTPURLResponse alloc] initWithURL:URL];
[response _setStatusCode:statusCode];
[response _setAllResponseHeaders:_HTTPRequest.getAllResponseHeaders()];
[_delegate connection:self didReceiveResponse:response];
}
}
+41 -1
View File
@@ -72,7 +72,30 @@ URL
*/
@implementation CPHTTPURLResponse : CPURLResponse
{
int _statusCode;
int _statusCode;
CPString _allResponseHeaders;
CPDictionary _responseHeaders;
}
+ (CPDictionary)parseHTTPHeaders:(CPString)headersString
{
var r = [CPMutableDictionary dictionary];
if (headersString)
{
var headerLines = headersString.split('\r\n'),
count = headerLines.length;
while (count--)
{
var headerLine = headerLines[count],
index = headerLine.indexOf(': ');
if (index !== CPNotFound)
[r setValue:headerLine.substring(index + 2) forKey:headerLine.substring(0, index)];
}
}
return r;
}
/* @ignore */
@@ -89,4 +112,21 @@ URL
return _statusCode;
}
- (void)_setAllResponseHeaders:(CPString)responseHeadersString
{
_allResponseHeaders = responseHeadersString;
}
/*!
Return the HTTP response headers.
*/
- (CPDictionary)allHeaderFields
{
// Lazily parse the headers.
if (!_responseHeaders)
_responseHeaders = [[self class] parseHTTPHeaders:_allResponseHeaders];
return _responseHeaders;
}
@end