Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed TTRequestLoader for local urls

  • Loading branch information...
commit 4aaf206eb80bf39847587203a60b95f0173fd403 1 parent 8459aca
@airportyh airportyh authored
Showing with 24 additions and 17 deletions.
  1. +24 −17 src/Three20Network/Sources/TTRequestLoader.m
View
41 src/Three20Network/Sources/TTRequestLoader.m
@@ -277,23 +277,28 @@ - (void)cancel {
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSHTTPURLResponse*)response {
_response = [response retain];
- NSDictionary* headers = [response allHeaderFields];
- int contentLength = [[headers objectForKey:@"Content-Length"] intValue];
-
- // If you hit this assertion it's because a massive file is about to be downloaded.
- // If you're sure you want to do this, add the following line to your app delegate startup
- // method. Setting the max content length to zero allows anything to go through. If you just
- // want to raise the limit, set it to any positive byte size.
- // [[TTURLRequestQueue mainQueue] setMaxContentLength:0]
- TTDASSERT(0 == _queue.maxContentLength || contentLength <=_queue.maxContentLength);
-
- if (contentLength > _queue.maxContentLength && _queue.maxContentLength) {
- TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"MAX CONTENT LENGTH EXCEEDED (%d) %@",
- contentLength, _urlPath);
- [self cancel];
+ if ([response respondsToSelector:@selector(allHeaderFields)]){
+ NSDictionary* headers = [response allHeaderFields];
+ int contentLength = [[headers objectForKey:@"Content-Length"] intValue];
+
+ // If you hit this assertion it's because a massive file is about to be downloaded.
+ // If you're sure you want to do this, add the following line to your app delegate startup
+ // method. Setting the max content length to zero allows anything to go through. If you just
+ // want to raise the limit, set it to any positive byte size.
+ // [[TTURLRequestQueue mainQueue] setMaxContentLength:0]
+ TTDASSERT(0 == _queue.maxContentLength || contentLength <=_queue.maxContentLength);
+
+ if (contentLength > _queue.maxContentLength && _queue.maxContentLength) {
+ TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"MAX CONTENT LENGTH EXCEEDED (%d) %@",
+ contentLength, _urlPath);
+ [self cancel];
+ }
+
+ _responseData = [[NSMutableData alloc] initWithCapacity:contentLength];
+ }else {
+ _responseData = [[NSMutableData alloc] initWithCapacity:1000];
}
- _responseData = [[NSMutableData alloc] initWithCapacity:contentLength];
}
@@ -324,9 +329,11 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
TTNetworkRequestStopped();
TTDCONDITIONLOG(TTDFLAG_ETAGS, @"Response status code: %d", _response.statusCode);
-
+ if (![_response respondsToSelector:@selector(statusCode)]){
+ [_queue loader:self didLoadResponse:_response data:_responseData];
+ }
// We need to accept valid HTTP status codes, not only 200.
- if (_response.statusCode >= 200 && _response.statusCode < 300) {
+ else if (_response.statusCode >= 200 && _response.statusCode < 300) {
[_queue loader:self didLoadResponse:_response data:_responseData];
} else if (_response.statusCode == 304) {
Please sign in to comment.
Something went wrong with that request. Please try again.