Ben Copsey

Start work on moving delegate stuff to protocol

Add request:didReceiveData: delegate method
... ... @@ -16,6 +16,8 @@
#endif
#import <stdio.h>
#import "ASIHTTPRequestConfig.h"
#import "ASIHTTPRequestDelegate.h"
#import "ASIProgressDelegate.h"
extern NSString *ASIHTTPRequestVersion;
... ... @@ -62,10 +64,11 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
NSURL *originalURL;
// The delegate, you need to manage setting and talking to your delegate in your subclasses
id delegate;
id <ASIHTTPRequestDelegate> delegate;
// A queue delegate that should *ALSO* be notified of delegate message (used by ASINetworkQueue)
id queue;
// Another delegate that is also notified of request status changes and progress updates
// Generally, you won't use this directly, but ASINetworkQueue sets itself as the queue so it can proxy updates to its own delegates
id <ASIHTTPRequestDelegate, ASIProgressDelegate> queue;
// HTTP method to use (GET / POST / PUT / DELETE / HEAD). Defaults to GET
NSString *requestMethod;
... ... @@ -159,10 +162,10 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
NSString *proxyDomain;
// Delegate for displaying upload progress (usually an NSProgressIndicator, but you can supply a different object and handle this yourself)
id uploadProgressDelegate;
id <ASIProgressDelegate> uploadProgressDelegate;
// Delegate for displaying download progress (usually an NSProgressIndicator, but you can supply a different object and handle this yourself)
id downloadProgressDelegate;
id <ASIProgressDelegate> downloadProgressDelegate;
// Whether we've seen the headers of the response yet
BOOL haveExaminedHeaders;
... ...
... ... @@ -23,7 +23,7 @@
// Automatically set on build
NSString *ASIHTTPRequestVersion = @"v1.6.1-10 2010-04-13";
NSString *ASIHTTPRequestVersion = @"v1.6.1-11 2010-04-13";
NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
... ... @@ -2451,8 +2451,20 @@ static BOOL isiPhoneOS2;
return;
}
// Does the delegate want to handle the data manually?
SEL receivedDataSelector = @selector(request:didReceiveData:);
if ([[self delegate] respondsToSelector:receivedDataSelector]) {
NSMethodSignature *signature = [[[self delegate] class] instanceMethodSignatureForSelector:receivedDataSelector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:[self delegate]];
[invocation setSelector:receivedDataSelector];
[invocation setArgument:self atIndex:2];
[invocation setArgument:[NSData dataWithBytes:buffer length:bytesRead] atIndex:3];
[invocation performSelectorOnMainThread:@selector(invokeWithTarget:) withObject:[self delegate] waitUntilDone:[NSThread isMainThread]];
// Are we downloading to a file?
if ([self downloadDestinationPath]) {
} else if ([self downloadDestinationPath]) {
if (![self fileDownloadOutputStream]) {
BOOL append = NO;
if (![self temporaryFileDownloadPath]) {
... ...
//
// ASIHTTPRequestDelegate.h
// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
//
// Created by Ben Copsey on 13/04/2010.
// Copyright 2010 All-Seeing Interactive. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@class ASIHTTPRequest;
@protocol ASIHTTPRequestDelegate <NSObject>
@optional
// These are the default delegate methods for request status
// You can use different ones by setting didStartSelector / didFinishSelector / didFailSelector
- (void)requestStarted:(ASIHTTPRequest *)request;
- (void)requestFinished:(ASIHTTPRequest *)request;
- (void)requestFailed:(ASIHTTPRequest *)request;
// When a delegate implements this method, it is expected to process all incoming data itself
// This means that responseData / responseString / downloadDestinationPath etc are ignored
- (void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data;
// If a delegate implements one of these, it will be asked to supply credentials when none are available
// The delegate can then either restart the request ([request retryUsingSuppliedCredentials]) once credentials have been set
// or cancel it ([request cancelAuthentication])
- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request;
- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)request;
@end
... ...
//
// ASIProgressDelegate.h
// Mac
// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
//
// Created by Ben Copsey on 13/04/2010.
// Copyright 2010 All-Seeing Interactive. All rights reserved.
... ... @@ -9,11 +9,30 @@
#import <Cocoa/Cocoa.h>
@class ASIHTTPRequest;
@protocol ASIProgressDelegate
@protocol ASIProgressDelegate <NSObject>
@optional
// These methods are used to update UIProgressViews (iPhone OS) or NSProgressIndicators (Mac OS X)
// If you are using a custom progress delegate, you may find it easier to implement didReceiveBytes / didSendBytes instead
#if TARGET_OS_IPHONE
- (void)setProgress:(float)newProgress;
#else
- (void)setDoubleValue:(double)newProgress;
- (void)setMaxValue:(double)newMax;
#endif
// Called when the request recieves some data - bytes is the length of that data
// bytes may be less than zero if a request needs to remove its progress so far
- (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes;
// Called when the request sends some data.
// The first 32KB (128KB on older platforms) of data sent is not included in this amount because of limitations with the CFNetwork API
- (void)request:(ASIHTTPRequest *)request didSendBytes:(long long)bytes;
// Called when a request needs to change the length of the content to download
- (void)request:(ASIHTTPRequest *)request resetDownloadContentLength:(long long)newLength;
// Called when a request needs to change the length of the content to upload
- (void)request:(ASIHTTPRequest *)request resetUploadContentLength:(long long)newLength;
@end
... ...
This diff was suppressed by a .gitattributes entry.