Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Commit

Permalink
Rollbacked ASIHTTPRequest from 1.8 to 1.8.1 because of weird 406 erro…
Browse files Browse the repository at this point in the history
…rs similar to this: http://akos.ma/be8qv
  • Loading branch information
Adrian Kosmaczewski committed Oct 14, 2011
1 parent b914325 commit 351b169
Show file tree
Hide file tree
Showing 14 changed files with 1,262 additions and 1,133 deletions.
20 changes: 8 additions & 12 deletions Externals/ASIHTTPRequest/ASIAuthenticationDialog.m
Expand Up @@ -37,10 +37,6 @@ - (void)showTitle;
- (void)show;
- (NSArray *)requestsRequiringTheseCredentials;
- (void)presentNextDialog;
- (void)keyboardWillShow:(NSNotification *)notification;
- (void)orientationChanged:(NSNotification *)notification;
- (void)cancelAuthenticationFromDialog:(id)sender;
- (void)loginWithCredentialsFromDialog:(id)sender;
@property (retain) UITableView *tableView;
@end

Expand All @@ -55,20 +51,20 @@ + (void)initialize
}
}

+ (void)presentAuthenticationDialogForRequest:(ASIHTTPRequest *)theRequest
+ (void)presentAuthenticationDialogForRequest:(ASIHTTPRequest *)request
{
// No need for a lock here, this will always be called on the main thread
if (!sharedDialog) {
sharedDialog = [[self alloc] init];
[sharedDialog setRequest:theRequest];
if ([theRequest authenticationNeeded] == ASIProxyAuthenticationNeeded) {
[sharedDialog setRequest:request];
if ([request authenticationNeeded] == ASIProxyAuthenticationNeeded) {
[sharedDialog setType:ASIProxyAuthenticationType];
} else {
[sharedDialog setType:ASIStandardAuthenticationType];
}
[sharedDialog show];
} else {
[requestsNeedingAuthentication addObject:theRequest];
[requestsNeedingAuthentication addObject:request];
}
}

Expand Down Expand Up @@ -133,7 +129,7 @@ - (void)orientationChanged:(NSNotification *)notification
{
[self showTitle];

UIInterfaceOrientation o = [[UIApplication sharedApplication] statusBarOrientation];
UIDeviceOrientation o = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
CGFloat angle = 0;
switch (o) {
case UIDeviceOrientationLandscapeLeft: angle = 90; break;
Expand All @@ -153,7 +149,7 @@ - (void)orientationChanged:(NSNotification *)notification
}

CGAffineTransform previousTransform = self.view.layer.affineTransform;
CGAffineTransform newTransform = CGAffineTransformMakeRotation((CGFloat)(angle * M_PI / 180.0));
CGAffineTransform newTransform = CGAffineTransformMakeRotation(angle * M_PI / 180.0);

// Reset the transform so we can set the size
self.view.layer.affineTransform = CGAffineTransformIdentity;
Expand Down Expand Up @@ -224,7 +220,7 @@ - (void)viewDidDisappear:(BOOL)animated
[self retain];
[sharedDialog release];
sharedDialog = nil;
[self performSelector:@selector(presentNextDialog) withObject:nil afterDelay:0];
[self presentNextDialog];
[self release];
}

Expand Down Expand Up @@ -454,7 +450,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return 2;
Expand Down
18 changes: 4 additions & 14 deletions Externals/ASIHTTPRequest/ASICacheDelegate.h
Expand Up @@ -41,7 +41,7 @@ typedef enum _ASICachePolicy {
ASIFallbackToCacheIfLoadFailsCachePolicy = 64
} ASICachePolicy;

// Cache storage policies control whether cached data persists between application launches (ASICachePermanentlyCacheStoragePolicy) or not (ASICacheForSessionDurationCacheStoragePolicy)
// Cache storage policies control whether cached data persists between application launches (ASICachePermanentlyCacheStoragePolicy) or not (ASICachePermanentlyCacheStoragePolicy)
// Calling [ASIHTTPRequest clearSession] will remove any data stored using ASICacheForSessionDurationCacheStoragePolicy
typedef enum _ASICacheStoragePolicy {
ASICacheForSessionDurationCacheStoragePolicy = 0,
Expand All @@ -53,19 +53,12 @@ typedef enum _ASICacheStoragePolicy {

@required

// Should return the cache policy that will be used when requests have their cache policy set to ASIUseDefaultCachePolicy
// Should return the cache policy that will be used when requests have their cache policy set to ASIDefaultCachePolicy
- (ASICachePolicy)defaultCachePolicy;

// Returns the date a cached response should expire on. Pass a non-zero max age to specify a custom date.
- (NSDate *)expiryDateForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge;

// Updates cached response headers with a new expiry date. Pass a non-zero max age to specify a custom date.
- (void)updateExpiryForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge;

// Looks at the request's cache policy and any cached headers to determine if the cache data is still valid
- (BOOL)canUseCachedDataForRequest:(ASIHTTPRequest *)request;

// Removes cached data for a particular request
// Should Remove cached data for a particular request
- (void)removeCachedDataForRequest:(ASIHTTPRequest *)request;

// Should return YES if the cache considers its cached response current for the request
Expand All @@ -76,9 +69,6 @@ typedef enum _ASICacheStoragePolicy {
// When a non-zero maxAge is passed, it should be used as the expiry time for the cached response
- (void)storeResponseForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge;

// Removes cached data for a particular url
- (void)removeCachedDataForURL:(NSURL *)url;

// Should return an NSDictionary of cached headers for the passed URL, if it is stored in the cache
- (NSDictionary *)cachedResponseHeadersForURL:(NSURL *)url;

Expand All @@ -89,7 +79,7 @@ typedef enum _ASICacheStoragePolicy {
- (NSString *)pathToCachedResponseDataForURL:(NSURL *)url;

// Returns a path to the cached response headers, if they url
- (NSString *)pathToCachedResponseHeadersForURL:(NSURL *)url;
- (NSString *)pathToCachedResponseHeadersForURL:(NSURL *)request;

// Returns the location to use to store cached response headers for a particular request
- (NSString *)pathToStoreCachedResponseHeadersForRequest:(ASIHTTPRequest *)request;
Expand Down
3 changes: 1 addition & 2 deletions Externals/ASIHTTPRequest/ASIDataCompressor.h
Expand Up @@ -22,8 +22,7 @@
+ (id)compressor;

// Compress the passed chunk of data
// Passing YES for shouldFinish will finalize the deflated data - you must pass YES when you are on the last chunk of data
- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err shouldFinish:(BOOL)shouldFinish;
- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err;

// Convenience method - pass it some data, and you'll get deflated data back
+ (NSData *)compressData:(NSData*)uncompressedData error:(NSError **)err;
Expand Down
50 changes: 23 additions & 27 deletions Externals/ASIHTTPRequest/ASIDataCompressor.m
Expand Up @@ -66,7 +66,7 @@ - (NSError *)closeStream
return nil;
}

- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err shouldFinish:(BOOL)shouldFinish
- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err
{
if (length == 0) return nil;

Expand All @@ -80,7 +80,8 @@ - (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSErro
zStream.next_in = bytes;
zStream.avail_in = (unsigned int)length;
zStream.avail_out = 0;

NSError *theError = nil;

NSInteger bytesProcessedAlready = zStream.total_out;
while (zStream.avail_out == 0) {

Expand All @@ -90,18 +91,27 @@ - (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSErro

zStream.next_out = [outputData mutableBytes] + zStream.total_out-bytesProcessedAlready;
zStream.avail_out = (unsigned int)([outputData length] - (zStream.total_out-bytesProcessedAlready));
status = deflate(&zStream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);

status = deflate(&zStream, Z_FINISH);

if (status == Z_STREAM_END) {
break;
theError = [self closeStream];
} else if (status != Z_OK) {
if (err) {
*err = [[self class] deflateErrorWithCode:status];
}
[self closeStream];
return NO;
}
}

if (theError) {
if (err) {
*err = theError;
}
return nil;
}

// Set real length
[outputData setLength: zStream.total_out-bytesProcessedAlready];
return outputData;
Expand All @@ -111,7 +121,7 @@ - (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSErro
+ (NSData *)compressData:(NSData*)uncompressedData error:(NSError **)err
{
NSError *theError = nil;
NSData *outputData = [[ASIDataCompressor compressor] compressBytes:(Bytef *)[uncompressedData bytes] length:[uncompressedData length] error:&theError shouldFinish:YES];
NSData *outputData = [[ASIDataCompressor compressor] compressBytes:(Bytef *)[uncompressedData bytes] length:[uncompressedData length] error:&theError];
if (theError) {
if (err) {
*err = theError;
Expand All @@ -125,18 +135,16 @@ + (NSData *)compressData:(NSData*)uncompressedData error:(NSError **)err

+ (BOOL)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err
{
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];

// Create an empty file at the destination path
if (![fileManager createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) {
if (![[NSFileManager defaultManager] createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) {
if (err) {
*err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed because we were to create a file at %@",sourcePath,destinationPath],NSLocalizedDescriptionKey,nil]];
}
return NO;
}

// Ensure the source file exists
if (![fileManager fileExistsAtPath:sourcePath]) {
if (![[NSFileManager defaultManager] fileExistsAtPath:sourcePath]) {
if (err) {
*err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed the file does not exist",sourcePath],NSLocalizedDescriptionKey,nil]];
}
Expand All @@ -159,27 +167,23 @@ + (BOOL)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinati

// Read some data from the file
readLength = [inputStream read:inputData maxLength:DATA_CHUNK_SIZE];


// Make sure nothing went wrong
if ([inputStream streamStatus] == NSStreamEventErrorOccurred) {
[compressor closeStream];
if (err) {
*err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed because we were unable to read from the source data file",sourcePath],NSLocalizedDescriptionKey,[inputStream streamError],NSUnderlyingErrorKey,nil]];
}
[compressor closeStream];
return NO;
}
// Have we reached the end of the input data?
if (!readLength) {
break;
}

// Attempt to deflate the chunk of data
outputData = [compressor compressBytes:inputData length:readLength error:&theError shouldFinish:readLength < DATA_CHUNK_SIZE ];
// Attempt to inflate the chunk of data
outputData = [compressor compressBytes:inputData length:readLength error:&theError];
if (theError) {
if (err) {
*err = theError;
}
[compressor closeStream];
return NO;
}

Expand All @@ -188,25 +192,17 @@ + (BOOL)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinati

// Make sure nothing went wrong
if ([inputStream streamStatus] == NSStreamEventErrorOccurred) {
[compressor closeStream];
if (err) {
*err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed because we were unable to write to the destination data file at &@",sourcePath,destinationPath],NSLocalizedDescriptionKey,[outputStream streamError],NSUnderlyingErrorKey,nil]];
}
[compressor closeStream];
return NO;
}

}

[inputStream close];
[outputStream close];

NSError *error = [compressor closeStream];
if (error) {
if (err) {
*err = error;
}
return NO;
}

return YES;
}

Expand Down
42 changes: 19 additions & 23 deletions Externals/ASIHTTPRequest/ASIDataDecompressor.m
Expand Up @@ -77,9 +77,10 @@ - (NSData *)uncompressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSEr
zStream.next_in = bytes;
zStream.avail_in = (unsigned int)length;
zStream.avail_out = 0;
NSError *theError = nil;

NSInteger bytesProcessedAlready = zStream.total_out;
while (zStream.avail_in != 0) {
while (zStream.avail_out == 0) {

if (zStream.total_out-bytesProcessedAlready >= [outputData length]) {
[outputData increaseLengthBy:halfLength];
Expand All @@ -88,18 +89,29 @@ - (NSData *)uncompressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSEr
zStream.next_out = [outputData mutableBytes] + zStream.total_out-bytesProcessedAlready;
zStream.avail_out = (unsigned int)([outputData length] - (zStream.total_out-bytesProcessedAlready));

status = inflate(&zStream, Z_NO_FLUSH);
status = inflate(&zStream, Z_SYNC_FLUSH);

if (status == Z_STREAM_END) {
break;
theError = [self closeStream];
if (theError) {
break;
}
} else if (status != Z_OK) {
if (err) {
*err = [[self class] inflateErrorWithCode:status];
}
[self closeStream];
return nil;
}
}

if (theError) {
if (err) {
*err = theError;
}
return nil;
}

// Set real length
[outputData setLength: zStream.total_out-bytesProcessedAlready];
return outputData;
Expand All @@ -121,18 +133,16 @@ + (NSData *)uncompressData:(NSData*)compressedData error:(NSError **)err

+ (BOOL)uncompressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err
{
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];

// Create an empty file at the destination path
if (![fileManager createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) {
if (![[NSFileManager defaultManager] createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) {
if (err) {
*err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed because we were to create a file at %@",sourcePath,destinationPath],NSLocalizedDescriptionKey,nil]];
}
return NO;
}

// Ensure the source file exists
if (![fileManager fileExistsAtPath:sourcePath]) {
if (![[NSFileManager defaultManager] fileExistsAtPath:sourcePath]) {
if (err) {
*err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed the file does not exist",sourcePath],NSLocalizedDescriptionKey,nil]];
}
Expand All @@ -159,24 +169,19 @@ + (BOOL)uncompressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destina

// Make sure nothing went wrong
if ([inputStream streamStatus] == NSStreamEventErrorOccurred) {
[decompressor closeStream];
if (err) {
*err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed because we were unable to read from the source data file",sourcePath],NSLocalizedDescriptionKey,[inputStream streamError],NSUnderlyingErrorKey,nil]];
}
[decompressor closeStream];
return NO;
}
// Have we reached the end of the input data?
if (!readLength) {
break;
}

// Attempt to inflate the chunk of data
outputData = [decompressor uncompressBytes:inputData length:readLength error:&theError];
if (theError) {
if (err) {
*err = theError;
}
[decompressor closeStream];
return NO;
}

Expand All @@ -185,26 +190,17 @@ + (BOOL)uncompressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destina

// Make sure nothing went wrong
if ([inputStream streamStatus] == NSStreamEventErrorOccurred) {
[decompressor closeStream];
if (err) {
*err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed because we were unable to write to the destination data file at &@",sourcePath,destinationPath],NSLocalizedDescriptionKey,[outputStream streamError],NSUnderlyingErrorKey,nil]];
}
[decompressor closeStream];
return NO;
}

}

[inputStream close];
[outputStream close];

NSError *error = [decompressor closeStream];
if (error) {
if (err) {
*err = error;
}
return NO;
}

return YES;
}

Expand Down

0 comments on commit 351b169

Please sign in to comment.