From f72d14030c4d0216f0889811a34eda412bea524d Mon Sep 17 00:00:00 2001 From: CaS Date: Tue, 17 Sep 2002 10:05:47 +0000 Subject: [PATCH] Make handling of incoming http response more robust. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14472 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 2 + Source/GSHTTPURLHandle.m | 81 +++++++++++++++++++++++++--------------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e0918a40..106b5325f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * Tools/AGSParser.m: Bugfix ... look for source files more intelligently. Try both current directory and relative to header. + * Source/GSHTTPURLHandle.m: If response parsing fails, fail the + load operation and (conditionally when debug enabled) log an error. 2002-09-16 Richard Frith-Macdonald diff --git a/Source/GSHTTPURLHandle.m b/Source/GSHTTPURLHandle.m index ad068b603..94a8b1828 100644 --- a/Source/GSHTTPURLHandle.m +++ b/Source/GSHTTPURLHandle.m @@ -301,39 +301,58 @@ static void debugWrite(NSData *data) d = [dict objectForKey: NSFileHandleNotificationDataItem]; if (debug == YES) debugRead(d); - [parser parse: d]; - if ([parser isComplete] == YES) + if ([parser parse: d] == NO) { - GSMimeHeader *info; - NSString *val; + if ([parser isComplete] == YES) + { + GSMimeHeader *info; + NSString *val; - connectionState = idle; - [nc removeObserver: self - name: NSFileHandleReadCompletionNotification - object: sock]; - [sock closeFile]; - DESTROY(sock); - /* - * Retrieve essential keys from document - */ - info = [document headerNamed: @"http"]; - val = [info objectForKey: NSHTTPPropertyServerHTTPVersionKey]; - if (val != nil) - [pageInfo setObject: val forKey: NSHTTPPropertyServerHTTPVersionKey]; - val = [info objectForKey: NSHTTPPropertyStatusCodeKey]; - if (val != nil) - [pageInfo setObject: val forKey: NSHTTPPropertyStatusCodeKey]; - val = [info objectForKey: NSHTTPPropertyStatusReasonKey]; - if (val != nil) - [pageInfo setObject: val forKey: NSHTTPPropertyStatusReasonKey]; - /* - * Tell superclass that we have successfully loaded the data. - */ - d = [parser data]; - r = NSMakeRange(bodyPos, [d length] - bodyPos); - bodyPos = 0; - [self didLoadBytes: [d subdataWithRange: r] - loadComplete: YES]; + connectionState = idle; + [nc removeObserver: self + name: NSFileHandleReadCompletionNotification + object: sock]; + [sock closeFile]; + DESTROY(sock); + + /* + * Retrieve essential keys from document + */ + info = [document headerNamed: @"http"]; + val = [info objectForKey: NSHTTPPropertyServerHTTPVersionKey]; + if (val != nil) + { + [pageInfo setObject: val + forKey: NSHTTPPropertyServerHTTPVersionKey]; + } + val = [info objectForKey: NSHTTPPropertyStatusCodeKey]; + if (val != nil) + { + [pageInfo setObject: val forKey: NSHTTPPropertyStatusCodeKey]; + } + val = [info objectForKey: NSHTTPPropertyStatusReasonKey]; + if (val != nil) + { + [pageInfo setObject: val forKey: NSHTTPPropertyStatusReasonKey]; + } + /* + * Tell superclass that we have successfully loaded the data. + */ + d = [parser data]; + r = NSMakeRange(bodyPos, [d length] - bodyPos); + bodyPos = 0; + [self didLoadBytes: [d subdataWithRange: r] + loadComplete: YES]; + } + else + { + if (debug == YES) + { + NSLog(@"HTTP parse failure - %@", parser); + } + [self endLoadInBackground]; + [self backgroundLoadDidFailWithReason: @"Response parse failed"]; + } } else {