mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Tweka header parsing for http response.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25158 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ce98e93c13
commit
428ed5fd0d
4 changed files with 63 additions and 26 deletions
|
@ -78,6 +78,7 @@ extern "C" {
|
||||||
+ (NSString*) makeToken: (NSString*)t preservingCase: (BOOL)preserve;
|
+ (NSString*) makeToken: (NSString*)t preservingCase: (BOOL)preserve;
|
||||||
+ (NSString*) makeToken: (NSString*)t;
|
+ (NSString*) makeToken: (NSString*)t;
|
||||||
- (id) copyWithZone: (NSZone*)z;
|
- (id) copyWithZone: (NSZone*)z;
|
||||||
|
- (NSString*) fullValue;
|
||||||
- (id) initWithName: (NSString*)n
|
- (id) initWithName: (NSString*)n
|
||||||
value: (NSString*)v;
|
value: (NSString*)v;
|
||||||
- (id) initWithName: (NSString*)n
|
- (id) initWithName: (NSString*)n
|
||||||
|
|
|
@ -3070,6 +3070,41 @@ static NSCharacterSet *tokenSet = nil;
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the full value of the header including any parameters and
|
||||||
|
* preserving case. This is an unfolded (long) line with no escape
|
||||||
|
* sequences (ie contains a unicode string not necessarily plain ASCII).<br />
|
||||||
|
* If you just want the plain value excluding any parameters, use the
|
||||||
|
* -value method instead.
|
||||||
|
*/
|
||||||
|
- (NSString*) fullValue
|
||||||
|
{
|
||||||
|
if ([params count] > 0)
|
||||||
|
{
|
||||||
|
NSMutableString *m;
|
||||||
|
NSEnumerator *e;
|
||||||
|
NSString *k;
|
||||||
|
|
||||||
|
m = [value mutableCopy];
|
||||||
|
e = [params keyEnumerator];
|
||||||
|
while ((k = [e nextObject]) != nil)
|
||||||
|
{
|
||||||
|
NSString *v;
|
||||||
|
|
||||||
|
v = [GSMimeHeader makeQuoted: [params objectForKey: k] always: NO];
|
||||||
|
[m appendString: @"; "];
|
||||||
|
[m appendString: k];
|
||||||
|
[m appendString: @"="];
|
||||||
|
[m appendString: v];
|
||||||
|
}
|
||||||
|
k = [m makeImmutableCopyOnFail: YES];
|
||||||
|
return AUTORELEASE(k);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
return [self initWithName: @"unknown" value: @"none" parameters: nil];
|
return [self initWithName: @"unknown" value: @"none" parameters: nil];
|
||||||
|
@ -3441,7 +3476,8 @@ static NSCharacterSet *tokenSet = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of this header (excluding any parameters)
|
* Returns the value of this header (excluding any parameters).<br />
|
||||||
|
* Use the -fullValue m,ethod if you want parameter included.
|
||||||
*/
|
*/
|
||||||
- (NSString*) value
|
- (NSString*) value
|
||||||
{
|
{
|
||||||
|
|
|
@ -348,7 +348,7 @@ static NSURLProtocol *placeholder = nil;
|
||||||
|
|
||||||
_isLoading = YES;
|
_isLoading = YES;
|
||||||
_complete = NO;
|
_complete = NO;
|
||||||
_debug = YES;
|
_debug = NO;
|
||||||
|
|
||||||
/* Perform a redirect if the path is empty.
|
/* Perform a redirect if the path is empty.
|
||||||
* As per MacOs-X documentation.
|
* As per MacOs-X documentation.
|
||||||
|
@ -764,17 +764,7 @@ static NSURLProtocol *placeholder = nil;
|
||||||
[this->client URLProtocol: self didLoadData: d];
|
[this->client URLProtocol: self didLoadData: d];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[this->client URLProtocolDidFinishLoading: self];
|
||||||
if (_statusCode >= 200 && _statusCode < 300)
|
|
||||||
{
|
|
||||||
[this->client URLProtocolDidFinishLoading: self];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[this->client URLProtocol: self
|
|
||||||
didFailWithError: [NSError errorWithDomain: @"receive error" code: 0 userInfo: nil]];
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -812,8 +802,10 @@ static NSURLProtocol *placeholder = nil;
|
||||||
{
|
{
|
||||||
NSLog(@"HTTP response not received - %@", _parser);
|
NSLog(@"HTTP response not received - %@", _parser);
|
||||||
}
|
}
|
||||||
[this->client URLProtocol: self
|
[this->client URLProtocol: self didFailWithError:
|
||||||
didFailWithError: [NSError errorWithDomain: @"receive error" code: 0 userInfo: nil]];
|
[NSError errorWithDomain: @"receive incomplete"
|
||||||
|
code: 0
|
||||||
|
userInfo: nil]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -936,6 +928,7 @@ static NSURLProtocol *placeholder = nil;
|
||||||
case NSStreamEventHasSpaceAvailable:
|
case NSStreamEventHasSpaceAvailable:
|
||||||
{
|
{
|
||||||
int written;
|
int written;
|
||||||
|
BOOL sent = NO;
|
||||||
|
|
||||||
// FIXME: should also send out relevant Cookies
|
// FIXME: should also send out relevant Cookies
|
||||||
if (_writeData != nil)
|
if (_writeData != nil)
|
||||||
|
@ -969,6 +962,10 @@ static NSURLProtocol *placeholder = nil;
|
||||||
_body = [_body initWithData: d];
|
_body = [_body initWithData: d];
|
||||||
[_body open];
|
[_body open];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sent = YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -989,7 +986,10 @@ static NSURLProtocol *placeholder = nil;
|
||||||
NSLog(@"error reading from HTTPBody stream %@",
|
NSLog(@"error reading from HTTPBody stream %@",
|
||||||
[NSError _last]);
|
[NSError _last]);
|
||||||
}
|
}
|
||||||
[self _unschedule];
|
[this->client URLProtocol: self didFailWithError:
|
||||||
|
[NSError errorWithDomain: @"can't read body"
|
||||||
|
code: 0
|
||||||
|
userInfo: nil]];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (len > 0)
|
else if (len > 0)
|
||||||
|
@ -1018,15 +1018,17 @@ static NSURLProtocol *placeholder = nil;
|
||||||
{
|
{
|
||||||
[_body close];
|
[_body close];
|
||||||
DESTROY(_body);
|
DESTROY(_body);
|
||||||
|
sent = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[_body close];
|
[_body close];
|
||||||
DESTROY(_body);
|
DESTROY(_body);
|
||||||
|
sent = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_writeData == nil && _body == nil)
|
if (sent == YES)
|
||||||
{
|
{
|
||||||
if (_debug)
|
if (_debug)
|
||||||
{
|
{
|
||||||
|
@ -1101,7 +1103,9 @@ static NSURLProtocol *placeholder = nil;
|
||||||
if (this->input == nil || this->output == nil)
|
if (this->input == nil || this->output == nil)
|
||||||
{
|
{
|
||||||
[this->client URLProtocol: self didFailWithError:
|
[this->client URLProtocol: self didFailWithError:
|
||||||
[NSError errorWithDomain: @"can't connect" code: 0 userInfo: nil]];
|
[NSError errorWithDomain: @"can't connect"
|
||||||
|
code: 0
|
||||||
|
userInfo: nil]];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RETAIN(this->input);
|
RETAIN(this->input);
|
||||||
|
|
|
@ -75,18 +75,14 @@ typedef struct {
|
||||||
e = [headers objectEnumerator];
|
e = [headers objectEnumerator];
|
||||||
while ((h = [e nextObject]) != nil)
|
while ((h = [e nextObject]) != nil)
|
||||||
{
|
{
|
||||||
NSString *n = [h name];
|
NSString *n = [h namePreservingCase: YES];
|
||||||
|
NSString *v = [h fullValue];
|
||||||
|
|
||||||
v = [h value];
|
if ([n caseInsensitiveCompare: @"content-type"] == NSOrderedSame)
|
||||||
[self _setValue: v forHTTPHeaderField: n];
|
|
||||||
if ([n isEqualToString: @"content-length"] == YES)
|
|
||||||
{
|
|
||||||
contentLength = v;
|
|
||||||
}
|
|
||||||
else if ([n isEqualToString: @"content-type"] == YES)
|
|
||||||
{
|
{
|
||||||
contentType = h;
|
contentType = h;
|
||||||
}
|
}
|
||||||
|
[self _setValue: v forHTTPHeaderField: n];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue