Add some diagnostics

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27781 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-02-04 14:28:41 +00:00
parent 091dd549e4
commit caf400979f
2 changed files with 37 additions and 3 deletions

View file

@ -2,6 +2,7 @@
* Source/NSURLProtocol.m: Add some diagnostics and ensure that * Source/NSURLProtocol.m: Add some diagnostics and ensure that
delegates are removed from streams. delegates are removed from streams.
* Source/NSURLConnection.m: Add diagnostics for redirect.
2009-02-04 David Chisnall <csdavec@swansea.ac.uk> 2009-02-04 David Chisnall <csdavec@swansea.ac.uk>

View file

@ -23,6 +23,7 @@
*/ */
#import <Foundation/NSRunLoop.h> #import <Foundation/NSRunLoop.h>
#import <Foundation/NSDebug.h>
#import "GSURLPrivate.h" #import "GSURLPrivate.h"
@ -144,6 +145,7 @@ typedef struct
NSURLRequest *_request; NSURLRequest *_request;
NSURLProtocol *_protocol; NSURLProtocol *_protocol;
id _delegate; // Not retained id _delegate; // Not retained
BOOL _debug;
} Internal; } Internal;
typedef struct { typedef struct {
@ -160,8 +162,13 @@ typedef struct {
if (o != nil) if (o != nil)
{ {
#if GS_WITH_GC
o->_NSURLConnectionInternal
= NSAllocateCollectable(sizeof(Internal), NSScannedOption);
#else
o->_NSURLConnectionInternal = NSZoneCalloc(GSObjCZone(self), o->_NSURLConnectionInternal = NSZoneCalloc(GSObjCZone(self),
1, sizeof(Internal)); 1, sizeof(Internal));
#endif
} }
return o; return o;
} }
@ -180,6 +187,12 @@ typedef struct {
return AUTORELEASE(o); return AUTORELEASE(o);
} }
- (void) cancel
{
[this->_protocol stopLoading];
DESTROY(this->_protocol);
}
- (void) dealloc - (void) dealloc
{ {
if (this != 0) if (this != 0)
@ -192,10 +205,12 @@ typedef struct {
[super dealloc]; [super dealloc];
} }
- (void) cancel - (void) finalize
{ {
[this->_protocol stopLoading]; if (this != 0)
DESTROY(this->_protocol); {
[self cancel];
}
} }
- (id) initWithRequest: (NSURLRequest *)request delegate: (id)delegate - (id) initWithRequest: (NSURLRequest *)request delegate: (id)delegate
@ -209,6 +224,7 @@ typedef struct {
cachedResponse: nil cachedResponse: nil
client: (id<NSURLProtocolClient>)self]; client: (id<NSURLProtocolClient>)self];
[this->_protocol startLoading]; [this->_protocol startLoading];
this->_debug = GSDebugSet(@"NSURLConnection");
} }
return self; return self;
} }
@ -347,17 +363,30 @@ typedef struct {
wasRedirectedToRequest: (NSURLRequest *)request wasRedirectedToRequest: (NSURLRequest *)request
redirectResponse: (NSURLResponse *)redirectResponse redirectResponse: (NSURLResponse *)redirectResponse
{ {
if (this->_debug)
{
NSLog(@"%@ tell delegate %@ about redirect to %@ as a result of %@",
self, this->_delegate, request, redirectResponse);
}
request = [this->_delegate connection: self request = [this->_delegate connection: self
willSendRequest: request willSendRequest: request
redirectResponse: redirectResponse]; redirectResponse: redirectResponse];
if (this->_protocol == nil) if (this->_protocol == nil)
{ {
if (this->_debug)
{
NSLog(@"%@ delegate cancelled request", self);
}
/* Our protocol is nil, so we have been cancelled by the delegate. /* Our protocol is nil, so we have been cancelled by the delegate.
*/ */
return; return;
} }
if (request != nil) if (request != nil)
{ {
if (this->_debug)
{
NSLog(@"%@ delegate allowed redirect to %@", self, request);
}
/* Follow the redirect ... stop the old load and start a new one. /* Follow the redirect ... stop the old load and start a new one.
*/ */
[this->_protocol stopLoading]; [this->_protocol stopLoading];
@ -369,6 +398,10 @@ typedef struct {
client: (id<NSURLProtocolClient>)self]; client: (id<NSURLProtocolClient>)self];
[this->_protocol startLoading]; [this->_protocol startLoading];
} }
else if (this->_debug)
{
NSLog(@"%@ delegate cancelled redirect", self);
}
} }
- (void) URLProtocolDidFinishLoading: (NSURLProtocol *)protocol - (void) URLProtocolDidFinishLoading: (NSURLProtocol *)protocol