Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -284,11 +284,11 @@ { return [self performRequest: request redirects: 10]; } -- (OFTCPSocket*)OF_createSocketForRequest: (OFHTTPRequest*)request +- (OFTCPSocket*)OF_closeAndCreateSocketForRequest: (OFHTTPRequest*)request { OFURL *URL = [request URL]; OFTCPSocket *socket; [self close]; @@ -336,11 +336,11 @@ if (![scheme isEqual: @"http"] && ![scheme isEqual: @"https"]) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; /* Can we reuse the socket? */ - if (_socket != nil && [[_lastURL scheme] isEqual: [URL scheme]] && + if (_socket != nil && [[_lastURL scheme] isEqual: scheme] && [[_lastURL host] isEqual: [URL host]] && [_lastURL port] == [URL port]) { /* * Set _socket to nil, so that in case of an error it won't be * reused. If everything is successfull, we set _socket again @@ -361,11 +361,11 @@ } [_lastResponse release]; _lastResponse = nil; } else - socket = [self OF_createSocketForRequest: request]; + socket = [self OF_closeAndCreateSocketForRequest: request]; /* * As a work around for a bug with split packets in lighttpd when using * HTTPS, we construct the complete request in a buffer string and then * send it all at once. @@ -379,15 +379,16 @@ requestString = [OFMutableString stringWithFormat: @"%s /%@ HTTP/%@\r\n", of_http_request_method_to_string(method), [URL path], [request protocolVersionString]]; - if ([URL port] == 80) - [requestString appendFormat: @"Host: %@\r\n", [URL host]]; + if (([scheme isEqual: @"http"] && [URL port] != 80) || + ([scheme isEqual: @"https"] && [URL port] != 443)) + [requestString appendFormat: @"Host: %@:%d\r\n", + [URL host], [URL port]]; else - [requestString appendFormat: @"Host: %@:%d\r\n", [URL host], - [URL port]]; + [requestString appendFormat: @"Host: %@\r\n", [URL host]]; user = [URL user]; password = [URL password]; if ([user length] > 0 || [password length] > 0) { @@ -439,11 +440,11 @@ } @catch (OFWriteFailedException *e) { if ([e errNo] != ECONNRESET && [e errNo] != EPIPE) @throw e; /* Reconnect in case a keep-alive connection timed out */ - socket = [self OF_createSocketForRequest: request]; + socket = [self OF_closeAndCreateSocketForRequest: request]; [socket writeString: requestString]; } if (entity != nil) [socket writeBuffer: [entity items] @@ -459,11 +460,11 @@ * It's possible that the write succeeds on a connection that is * keep-alive, but the connection has already been closed by the remote * end due to a timeout. In this case, we need to reconnect. */ if (line == nil) { - socket = [self OF_createSocketForRequest: request]; + socket = [self OF_closeAndCreateSocketForRequest: request]; [socket writeString: requestString]; if (entity != nil) [socket writeBuffer: [entity items] length: [entity count] *