From 65541445d00b2716e5fb7ef2bcba8a842ce96627 Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Thu, 2 May 2002 17:06:04 +0000 Subject: [PATCH] Fix error in last 'host' mod, and add some chacks git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13576 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 4 +++- Source/GSHTTPURLHandle.m | 52 +++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c63a1271..dce8a7159 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,7 +14,9 @@ * Source/NSURLHandle.m: Implement ([-hash]) and ([-isEqual:]) based on ([-absoluteString]) rather than simple pointer comparison. - * Source/GSHTTPURLHandle.m: ([-bgdConnect]) set host header + * Source/GSHTTPURLHandle.m: ([-bgdConnect]) check for existing + headers before writing ... avoid overriding them and only set things + that the programmer has not bothered to set. ([-loadInBackGround]) use URL port if available. More fixes thanks to lcampbel via savannah * Headers/Foundation/NSURLHanlde.h: include NSObject.h diff --git a/Source/GSHTTPURLHandle.m b/Source/GSHTTPURLHandle.m index ab78e7b52..aca160c99 100644 --- a/Source/GSHTTPURLHandle.m +++ b/Source/GSHTTPURLHandle.m @@ -568,24 +568,22 @@ static void debugWrite(NSData *data) { s = [[NSMutableString alloc] initWithFormat: @"%@ http://%@%@", method, [url host], [url path]]; - if ([[url query] length] > 0) - { - [s appendFormat: @"?%@", [url query]]; - } - [s appendFormat: @" HTTP/%@\r\n", httpVersion]; } else // no proxy { s = [[NSMutableString alloc] initWithFormat: @"%@ %@", method, [url path]]; - if ([[url query] length] > 0) - { - [s appendFormat: @"?%@", [url query]]; - } - [s appendFormat: @" HTTP/%@\nHost: %@\r\n", httpVersion, [url host]]; } + if ([[url query] length] > 0) + { + [s appendFormat: @"?%@", [url query]]; + } + [s appendFormat: @" HTTP/%@\r\n", httpVersion]; - [wProperties setObject: [url host] forKey: @"host"]; + if ([wProperties objectForKey: @"host"] == nil) + { + [wProperties setObject: [url host] forKey: @"host"]; + } if ([wData length] > 0) { @@ -600,24 +598,28 @@ static void debugWrite(NSData *data) forKey: @"content-type"]; } } - if ([url user] != nil) + if ([wProperties objectForKey: @"authorisation"] == nil) { - NSString *auth; - - if ([[url password] length] > 0) - { - auth = [NSString stringWithFormat: @"%@:%@", - [url user], [url password]]; - } - else + if ([url user] != nil) { - auth = [NSString stringWithFormat: @"%@", [url user]]; + NSString *auth; + + if ([[url password] length] > 0) + { + auth = [NSString stringWithFormat: @"%@:%@", + [url user], [url password]]; + } + else + { + auth = [NSString stringWithFormat: @"%@", [url user]]; + } + auth = [NSString stringWithFormat: @"Basic %@", + [self encodebase64: auth]]; + [wProperties setObject: auth + forKey: @"authorization"]; } - auth = [NSString stringWithFormat: @"Basic %@", - [self encodebase64: auth]]; - [wProperties setObject: auth - forKey: @"Authorization"]; } + wpEnumerator = [wProperties keyEnumerator]; while ((key = [wpEnumerator nextObject])) {