diff --git a/Headers/Additions/GNUstepBase/GSMime.h b/Headers/Additions/GNUstepBase/GSMime.h index 74659d3f1..6eb8e315b 100644 --- a/Headers/Additions/GNUstepBase/GSMime.h +++ b/Headers/Additions/GNUstepBase/GSMime.h @@ -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 diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m index 8a6f69831..383bfa02e 100644 --- a/Source/Additions/GSMime.m +++ b/Source/Additions/GSMime.m @@ -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).
+ * 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).
+ * Use the -fullValue m,ethod if you want parameter included. */ - (NSString*) value { diff --git a/Source/NSURLProtocol.m b/Source/NSURLProtocol.m index ec01656c8..4297b5119 100644 --- a/Source/NSURLProtocol.m +++ b/Source/NSURLProtocol.m @@ -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); diff --git a/Source/NSURLResponse.m b/Source/NSURLResponse.m index 453a76e61..23cb2a8a4 100644 --- a/Source/NSURLResponse.m +++ b/Source/NSURLResponse.m @@ -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]; } }