diff --git a/Source/GSURLPrivate.h b/Source/GSURLPrivate.h index 6b75bd894..d15a6bb84 100644 --- a/Source/GSURLPrivate.h +++ b/Source/GSURLPrivate.h @@ -57,6 +57,7 @@ */ @interface NSURLRequest (Private) +- (BOOL) _debug; - (id) _propertyForKey: (NSString*)key; - (void) _setProperty: (id)value forKey: (NSString*)key; @end diff --git a/Source/NSURLConnection.m b/Source/NSURLConnection.m index c64fc8c2f..65cd71d3d 100644 --- a/Source/NSURLConnection.m +++ b/Source/NSURLConnection.m @@ -110,7 +110,6 @@ _done = YES; } - - (void) connection: (NSURLConnection *)connection didReceiveData: (NSData *)data { diff --git a/Source/NSURLProtocol.m b/Source/NSURLProtocol.m index fe4d08aed..121be0a38 100644 --- a/Source/NSURLProtocol.m +++ b/Source/NSURLProtocol.m @@ -352,7 +352,6 @@ static NSLock *pairLock = nil; NSURLCredential *_credential; NSHTTPURLResponse *_response; } -- (void) setDebug: (BOOL)flag; @end @interface _NSHTTPSURLProtocol : _NSHTTPURLProtocol @@ -472,28 +471,6 @@ static NSURLProtocol *placeholder = nil; return NO; } -+ (Class) _classToHandleRequest:(NSURLRequest *)request -{ - Class protoClass = nil; - int count; - [regLock lock]; - - count = [registered count]; - while (count-- > 0) - { - Class proto = [registered objectAtIndex: count]; - - if ([proto canInitWithRequest: request] == YES) - { - protoClass = proto; - break; - } - } - [regLock unlock]; - return protoClass; -} - - + (void) setProperty: (id)value forKey: (NSString *)key inRequest: (NSMutableURLRequest *)request @@ -618,17 +595,33 @@ static NSURLProtocol *placeholder = nil; return this->request; } -/* This method is here so that it's safe to set debug on any NSURLProtocol - * even if the concrete subclass doesn't actually support debug logging. - */ -- (void) setDebug: (BOOL)flag +@end + +@implementation NSURLProtocol (Private) + ++ (Class) _classToHandleRequest:(NSURLRequest *)request { - return; + Class protoClass = nil; + int count; + [regLock lock]; + + count = [registered count]; + while (count-- > 0) + { + Class proto = [registered objectAtIndex: count]; + + if ([proto canInitWithRequest: request] == YES) + { + protoClass = proto; + break; + } + } + [regLock unlock]; + return protoClass; } @end - @implementation NSURLProtocol (Subclassing) + (BOOL) canInitWithRequest: (NSURLRequest *)request @@ -705,24 +698,13 @@ static NSURLProtocol *placeholder = nil; [super dealloc]; } -- (id) init -{ - if (nil != (self = [super init])) - { - _debug = GSDebugSet(@"NSURLProtocol"); - } - return self; -} - -- (void) setDebug: (BOOL)flag -{ - _debug = flag; -} - - (void) startLoading { static NSDictionary *methods = nil; + _debug = GSDebugSet(@"NSURLProtocol"); + if (YES == [this->request _debug]) _debug = YES; + if (methods == nil) { methods = [[NSDictionary alloc] initWithObjectsAndKeys: diff --git a/Source/NSURLRequest.m b/Source/NSURLRequest.m index 8ad868805..320cc8358 100644 --- a/Source/NSURLRequest.m +++ b/Source/NSURLRequest.m @@ -38,6 +38,7 @@ typedef struct { NSString *method; NSMutableDictionary *headers; BOOL shouldHandleCookies; + BOOL debug; NSURL *URL; NSURL *mainDocumentURL; NSURLRequestCachePolicy cachePolicy; @@ -114,6 +115,7 @@ typedef struct { ASSIGN(inst->bodyStream, this->bodyStream); ASSIGN(inst->method, this->method); inst->shouldHandleCookies = this->shouldHandleCookies; + inst->debug = this->debug; inst->headers = [this->headers mutableCopy]; } } @@ -268,11 +270,17 @@ typedef struct { ASSIGN(inst->bodyStream, this->bodyStream); ASSIGN(inst->method, this->method); inst->shouldHandleCookies = this->shouldHandleCookies; + inst->debug = this->debug; inst->headers = [this->headers mutableCopy]; } return o; } +- (void) setDebug: (BOOL)flag +{ + this->debug = flag; +} + - (NSTimeInterval) timeoutInterval { return this->timeoutInterval; @@ -427,6 +435,12 @@ typedef struct { @end @implementation NSURLRequest (Private) + +- (BOOL) _debug +{ + return this->debug; +} + - (id) _propertyForKey: (NSString*)key { return [this->properties objectForKey: key];