Skip to content

Commit

Permalink
Merge pull request facebookarchive#273 from airportyh/master
Browse files Browse the repository at this point in the history
Conflicts:
	src/Three20Network/Sources/TTRequestLoader.m
  • Loading branch information
tonklon committed Jan 7, 2012
2 parents e26c500 + 4aaf206 commit d0224f4
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/Three20Network/Sources/TTRequestLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,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];

for (TTURLRequest* request in [[_requests copy] autorelease]) {
request.totalContentLength = contentLength;
Expand Down Expand Up @@ -396,8 +401,9 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
TTNetworkRequestStopped();

TTDCONDITIONLOG(TTDFLAG_ETAGS, @"Response status code: %d", _response.statusCode);

if (_response.statusCode == 304) {
if (![_response respondsToSelector:@selector(statusCode)]){
[_queue loader:self didLoadResponse:_response data:_responseData];
} else if (_response.statusCode == 304) {
[_queue loader:self didLoadUnmodifiedResponse:_response];
} else {
[_queue loader:self didLoadResponse:_response data:_responseData];
Expand Down

0 comments on commit d0224f4

Please sign in to comment.