mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Improve code deciding when to expect body after headers.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18577 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5aad007dac
commit
47ec878faf
2 changed files with 88 additions and 50 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2004-02-11 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/GSHTTPURLHandle.m: Expect to read content data after headers
|
||||||
|
if content-length is non-zero
|
||||||
|
or if content-transfer-encoding is chunked
|
||||||
|
or if server http version is less than 1
|
||||||
|
|
||||||
2004-02-09 Adam Fedor <fedor@gnu.org>
|
2004-02-09 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
||||||
* configure.ac: Add ffcall dir to INCLUDE_FLAGS.
|
* configure.ac: Add ffcall dir to INCLUDE_FLAGS.
|
||||||
|
|
|
@ -310,63 +310,94 @@ static void debugWrite(NSData *data)
|
||||||
[self endLoadInBackground];
|
[self endLoadInBackground];
|
||||||
[self backgroundLoadDidFailWithReason: @"Response parse failed"];
|
[self backgroundLoadDidFailWithReason: @"Response parse failed"];
|
||||||
}
|
}
|
||||||
else if ([parser isComplete] == YES
|
|
||||||
|| ([parser isInHeaders] == NO &&
|
|
||||||
[[[document headerNamed: @"content-length"] value] intValue] > 0))
|
|
||||||
{
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
BOOL complete = [parser isComplete];
|
||||||
* Report partial data if possible.
|
|
||||||
*/
|
if (complete == NO && [parser isInHeaders] == NO)
|
||||||
if ([parser isInBody])
|
|
||||||
{
|
{
|
||||||
|
NSString *enc;
|
||||||
|
NSString *len;
|
||||||
|
int ver;
|
||||||
|
|
||||||
|
ver = [[[document headerNamed: @"http"]
|
||||||
|
objectForKey: NSHTTPPropertyServerHTTPVersionKey] intValue];
|
||||||
|
len = [[document headerNamed: @"content-length"] value];
|
||||||
|
enc = [[document headerNamed: @"content-transfer-encoding"] value];
|
||||||
|
if (enc == nil)
|
||||||
|
{
|
||||||
|
enc = [[document headerNamed: @"transfer-encoding"] value];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([enc isEqualToString: @"chunked"] == YES)
|
||||||
|
{
|
||||||
|
complete = NO; // Read chunked body data
|
||||||
|
}
|
||||||
|
else if (ver >= 1 && [len intValue] == 0)
|
||||||
|
{
|
||||||
|
complete = YES; // No content
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
complete = NO; // No
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (complete == 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];
|
d = [parser data];
|
||||||
r = NSMakeRange(bodyPos, [d length] - bodyPos);
|
r = NSMakeRange(bodyPos, [d length] - bodyPos);
|
||||||
bodyPos = [d length];
|
bodyPos = 0;
|
||||||
[self didLoadBytes: [d subdataWithRange: r]
|
[self didLoadBytes: [d subdataWithRange: r]
|
||||||
loadComplete: NO];
|
loadComplete: YES];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Report partial data if possible.
|
||||||
|
*/
|
||||||
|
if ([parser isInBody])
|
||||||
|
{
|
||||||
|
d = [parser data];
|
||||||
|
r = NSMakeRange(bodyPos, [d length] - bodyPos);
|
||||||
|
bodyPos = [d length];
|
||||||
|
[self didLoadBytes: [d subdataWithRange: r]
|
||||||
|
loadComplete: NO];
|
||||||
|
}
|
||||||
|
[sock readInBackgroundAndNotify];
|
||||||
}
|
}
|
||||||
[sock readInBackgroundAndNotify];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue