mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +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
2a1d86f63d
commit
9740458609
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;
|
||||
- (id) copyWithZone: (NSZone*)z;
|
||||
- (NSString*) fullValue;
|
||||
- (id) initWithName: (NSString*)n
|
||||
value: (NSString*)v;
|
||||
- (id) initWithName: (NSString*)n
|
||||
|
|
|
@ -3070,6 +3070,41 @@ static NSCharacterSet *tokenSet = nil;
|
|||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
|
|
|
@ -348,7 +348,7 @@ static NSURLProtocol *placeholder = nil;
|
|||
|
||||
_isLoading = YES;
|
||||
_complete = NO;
|
||||
_debug = YES;
|
||||
_debug = NO;
|
||||
|
||||
/* Perform a redirect if the path is empty.
|
||||
* As per MacOs-X documentation.
|
||||
|
@ -764,17 +764,7 @@ static NSURLProtocol *placeholder = nil;
|
|||
[this->client URLProtocol: self didLoadData: d];
|
||||
}
|
||||
}
|
||||
|
||||
if (_statusCode >= 200 && _statusCode < 300)
|
||||
{
|
||||
[this->client URLProtocolDidFinishLoading: self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[this->client URLProtocol: self
|
||||
didFailWithError: [NSError errorWithDomain: @"receive error" code: 0 userInfo: nil]];
|
||||
|
||||
}
|
||||
[this->client URLProtocolDidFinishLoading: self];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -812,8 +802,10 @@ static NSURLProtocol *placeholder = nil;
|
|||
{
|
||||
NSLog(@"HTTP response not received - %@", _parser);
|
||||
}
|
||||
[this->client URLProtocol: self
|
||||
didFailWithError: [NSError errorWithDomain: @"receive error" code: 0 userInfo: nil]];
|
||||
[this->client URLProtocol: self didFailWithError:
|
||||
[NSError errorWithDomain: @"receive incomplete"
|
||||
code: 0
|
||||
userInfo: nil]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -936,6 +928,7 @@ static NSURLProtocol *placeholder = nil;
|
|||
case NSStreamEventHasSpaceAvailable:
|
||||
{
|
||||
int written;
|
||||
BOOL sent = NO;
|
||||
|
||||
// FIXME: should also send out relevant Cookies
|
||||
if (_writeData != nil)
|
||||
|
@ -969,6 +962,10 @@ static NSURLProtocol *placeholder = nil;
|
|||
_body = [_body initWithData: d];
|
||||
[_body open];
|
||||
}
|
||||
else
|
||||
{
|
||||
sent = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -989,7 +986,10 @@ static NSURLProtocol *placeholder = nil;
|
|||
NSLog(@"error reading from HTTPBody stream %@",
|
||||
[NSError _last]);
|
||||
}
|
||||
[self _unschedule];
|
||||
[this->client URLProtocol: self didFailWithError:
|
||||
[NSError errorWithDomain: @"can't read body"
|
||||
code: 0
|
||||
userInfo: nil]];
|
||||
return;
|
||||
}
|
||||
else if (len > 0)
|
||||
|
@ -1018,15 +1018,17 @@ static NSURLProtocol *placeholder = nil;
|
|||
{
|
||||
[_body close];
|
||||
DESTROY(_body);
|
||||
sent = YES;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[_body close];
|
||||
DESTROY(_body);
|
||||
sent = YES;
|
||||
}
|
||||
}
|
||||
if (_writeData == nil && _body == nil)
|
||||
if (sent == YES)
|
||||
{
|
||||
if (_debug)
|
||||
{
|
||||
|
@ -1101,7 +1103,9 @@ static NSURLProtocol *placeholder = nil;
|
|||
if (this->input == nil || this->output == nil)
|
||||
{
|
||||
[this->client URLProtocol: self didFailWithError:
|
||||
[NSError errorWithDomain: @"can't connect" code: 0 userInfo: nil]];
|
||||
[NSError errorWithDomain: @"can't connect"
|
||||
code: 0
|
||||
userInfo: nil]];
|
||||
return;
|
||||
}
|
||||
RETAIN(this->input);
|
||||
|
|
|
@ -75,18 +75,14 @@ typedef struct {
|
|||
e = [headers objectEnumerator];
|
||||
while ((h = [e nextObject]) != nil)
|
||||
{
|
||||
NSString *n = [h name];
|
||||
NSString *n = [h namePreservingCase: YES];
|
||||
NSString *v = [h fullValue];
|
||||
|
||||
v = [h value];
|
||||
[self _setValue: v forHTTPHeaderField: n];
|
||||
if ([n isEqualToString: @"content-length"] == YES)
|
||||
{
|
||||
contentLength = v;
|
||||
}
|
||||
else if ([n isEqualToString: @"content-type"] == YES)
|
||||
if ([n caseInsensitiveCompare: @"content-type"] == NSOrderedSame)
|
||||
{
|
||||
contentType = h;
|
||||
}
|
||||
[self _setValue: v forHTTPHeaderField: n];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue