Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to fix a problem when using didReceiveData: delegate or dataReceivedBlock callback #319

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Classes/ASIHTTPRequest.h
Expand Up @@ -264,6 +264,9 @@ typedef void (^ASIDataBlock)(NSData *data);
// Description of the HTTP status code // Description of the HTTP status code
NSString *responseStatusMessage; NSString *responseStatusMessage;


// HTTP version of the response
NSString *responseVersion;

// Size of the response // Size of the response
unsigned long long contentLength; unsigned long long contentLength;


Expand Down Expand Up @@ -944,6 +947,7 @@ typedef void (^ASIDataBlock)(NSData *data);
@property (retain) NSDictionary *proxyCredentials; @property (retain) NSDictionary *proxyCredentials;
@property (assign,readonly) int responseStatusCode; @property (assign,readonly) int responseStatusCode;
@property (retain,readonly) NSString *responseStatusMessage; @property (retain,readonly) NSString *responseStatusMessage;
@property (retain,readonly) NSString *responseVersion;
@property (retain) NSMutableData *rawResponseData; @property (retain) NSMutableData *rawResponseData;
@property (assign) NSTimeInterval timeOutSeconds; @property (assign) NSTimeInterval timeOutSeconds;
@property (retain, nonatomic) NSString *requestMethod; @property (retain, nonatomic) NSString *requestMethod;
Expand Down
14 changes: 11 additions & 3 deletions Classes/ASIHTTPRequest.m
Expand Up @@ -225,6 +225,7 @@ - (void)callBlock:(ASIBasicBlock)block;
@property (retain) NSString *authenticationRealm; @property (retain) NSString *authenticationRealm;
@property (retain) NSString *proxyAuthenticationRealm; @property (retain) NSString *proxyAuthenticationRealm;
@property (retain) NSString *responseStatusMessage; @property (retain) NSString *responseStatusMessage;
@property (retain) NSString *responseVersion;
@property (assign) BOOL inProgress; @property (assign) BOOL inProgress;
@property (assign) int retryCount; @property (assign) int retryCount;
@property (assign) BOOL willRetryRequest; @property (assign) BOOL willRetryRequest;
Expand Down Expand Up @@ -389,6 +390,7 @@ - (void)dealloc
[PACurl release]; [PACurl release];
[clientCertificates release]; [clientCertificates release];
[responseStatusMessage release]; [responseStatusMessage release];
[responseVersion release];
[connectionInfo release]; [connectionInfo release];
[requestID release]; [requestID release];
[dataDecompressor release]; [dataDecompressor release];
Expand Down Expand Up @@ -2155,6 +2157,7 @@ - (void)readResponseHeaders
[self setResponseHeaders:[NSMakeCollectable(CFHTTPMessageCopyAllHeaderFields(message)) autorelease]]; [self setResponseHeaders:[NSMakeCollectable(CFHTTPMessageCopyAllHeaderFields(message)) autorelease]];
[self setResponseStatusCode:(int)CFHTTPMessageGetResponseStatusCode(message)]; [self setResponseStatusCode:(int)CFHTTPMessageGetResponseStatusCode(message)];
[self setResponseStatusMessage:[NSMakeCollectable(CFHTTPMessageCopyResponseStatusLine(message)) autorelease]]; [self setResponseStatusMessage:[NSMakeCollectable(CFHTTPMessageCopyResponseStatusLine(message)) autorelease]];
[self setResponseVersion:[NSMakeCollectable(CFHTTPMessageCopyVersion(message)) autorelease]];


if ([self downloadCache] && ([[self downloadCache] canUseCachedDataForRequest:self])) { if ([self downloadCache] && ([[self downloadCache] canUseCachedDataForRequest:self])) {


Expand Down Expand Up @@ -2258,10 +2261,8 @@ - (void)readResponseHeaders


NSString *connectionHeader = [[[self responseHeaders] objectForKey:@"Connection"] lowercaseString]; NSString *connectionHeader = [[[self responseHeaders] objectForKey:@"Connection"] lowercaseString];


NSString *httpVersion = [NSMakeCollectable(CFHTTPMessageCopyVersion(message)) autorelease];

// Don't re-use the connection if the server is HTTP 1.0 and didn't send Connection: Keep-Alive // Don't re-use the connection if the server is HTTP 1.0 and didn't send Connection: Keep-Alive
if (![httpVersion isEqualToString:(NSString *)kCFHTTPVersion1_0] || [connectionHeader isEqualToString:@"keep-alive"]) { if (![self.responseVersion isEqualToString:(NSString *)kCFHTTPVersion1_0] || [connectionHeader isEqualToString:@"keep-alive"]) {


// See if server explicitly told us to close the connection // See if server explicitly told us to close the connection
if (![connectionHeader isEqualToString:@"close"]) { if (![connectionHeader isEqualToString:@"close"]) {
Expand Down Expand Up @@ -3331,6 +3332,12 @@ - (void)handleBytesAvailable
dataWillBeHandledExternally = YES; dataWillBeHandledExternally = YES;
} }
#endif #endif

if ([self authenticationNeeded]) {
// Don't pass the body of a 401/407 response to the callback.
dataWillBeHandledExternally = NO;
}

// Does the delegate want to handle the data manually? // Does the delegate want to handle the data manually?
if (dataWillBeHandledExternally) { if (dataWillBeHandledExternally) {


Expand Down Expand Up @@ -5086,6 +5093,7 @@ - (void)setRequestRedirectedBlock:(ASIBasicBlock)aRedirectBlock
@synthesize shouldPresentProxyAuthenticationDialog; @synthesize shouldPresentProxyAuthenticationDialog;
@synthesize authenticationNeeded; @synthesize authenticationNeeded;
@synthesize responseStatusMessage; @synthesize responseStatusMessage;
@synthesize responseVersion;
@synthesize shouldPresentCredentialsBeforeChallenge; @synthesize shouldPresentCredentialsBeforeChallenge;
@synthesize haveBuiltRequestHeaders; @synthesize haveBuiltRequestHeaders;
@synthesize inProgress; @synthesize inProgress;
Expand Down