mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-25 16:05:52 +00:00
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:
1 parent
1a54aadff0
commit
7485c4eb7a
2 files changed
+42
-1
No files matched your search
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user