diff --git a/ChangeLog b/ChangeLog index 9f25f415f..c7f4c1cdf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2014-05-20 Richard Frith-Macdonald + + * Source/GSHTTPURLHandle.m: + * Source/NSURLProtocol.m: + When creating the 'Host' header, omit the port part if the scheme is + http/https and the port is the normal 80/443. A workaround for buggy + software which doesn't understand the spec saying that the port is + 'optional', not 'omitted' in these cases. + 2014-05-09 Richard Frith-Macdonald * Source/NSDebug.m: diff --git a/Source/GSHTTPURLHandle.m b/Source/GSHTTPURLHandle.m index 8db20b6c5..2a0617c5f 100644 --- a/Source/GSHTTPURLHandle.m +++ b/Source/GSHTTPURLHandle.m @@ -407,6 +407,7 @@ debugWrite(GSHTTPURLHandle *handle, NSData *data) if ((id)NSMapGet(wProperties, (void*)@"Host") == nil) { + NSString *s = [u scheme]; id p = [u port]; id h = [u host]; @@ -414,7 +415,16 @@ debugWrite(GSHTTPURLHandle *handle, NSData *data) { h = @""; // Must use an empty host header } - if (p == nil) + if (([s isEqualToString: @"http"] && [p intValue] == 80) + || ([s isEqualToString: @"https"] && [p intValue] == 443)) + { + /* Some buggy systems object to the port being in the Host + * header when it's the default (optional) value. To keep + * them happy let's omit it in those cases. + */ + p = nil; + } + if (nil == p) { NSMapInsert(wProperties, (void*)@"Host", (void*)h); } diff --git a/Source/NSURLProtocol.m b/Source/NSURLProtocol.m index 2d54da4e9..398b0ec9b 100644 --- a/Source/NSURLProtocol.m +++ b/Source/NSURLProtocol.m @@ -1454,14 +1454,25 @@ static NSURLProtocol *placeholder = nil; } if ([this->request valueForHTTPHeaderField: @"Host"] == nil) { - id p = [u port]; - id h = [u host]; + NSString *s = [u scheme]; + id p = [u port]; + id h = [u host]; if (h == nil) { h = @""; // Must send an empty host header } - if (p == nil) + if (([s isEqualToString: @"http"] && [p intValue] == 80) + || ([s isEqualToString: @"https"] && [p intValue] == 443)) + { + /* Some buggy systems object to the port being in + * the Host header when it's the default (optional) + * value. + * To keep them happy let's omit it in those cases. + */ + p = nil; + } + if (nil == p) { [m appendFormat: @"Host: %@\r\n", h]; }