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
This commit is contained in:
Richard Frith-Macdonald 2002-09-17 10:05:47 +00:00
parent d9a98baa47
commit af514e9b42
2 changed files with 52 additions and 31 deletions

View file

@ -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 <rfm@gnu.org>

View file

@ -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
{