@@ -20,17 +20,18 @@ #include #include #import "OFHTTPClient.h" +#import "OFData.h" +#import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" +#import "OFNumber.h" #import "OFString.h" -#import "OFURL.h" #import "OFTCPSocket.h" -#import "OFDictionary.h" -#import "OFData.h" +#import "OFURL.h" #import "OFAlreadyConnectedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" @@ -80,11 +81,11 @@ constructRequestString(OFHTTPRequest *request) { void *pool = objc_autoreleasePoolPush(); of_http_request_method_t method = [request method]; OFURL *URL = [request URL]; - OFString *scheme = [URL scheme], *path = [URL path]; + OFString *path = [URL path]; OFString *user = [URL user], *password = [URL password]; OFData *body = [request body]; OFMutableString *requestString; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; OFEnumerator OF_GENERIC(OFString *) *keyEnumerator, *objectEnumerator; @@ -108,14 +109,15 @@ headers = [[[request headers] mutableCopy] autorelease]; if (headers == nil) headers = [OFMutableDictionary dictionary]; if ([headers objectForKey: @"Host"] == nil) { - if (([scheme isEqual: @"http"] && [URL port] != 80) || - ([scheme isEqual: @"https"] && [URL port] != 443)) { + OFNumber *port = [URL port]; + + if (port != nil) { OFString *host = [OFString stringWithFormat: - @"%@:%d", [URL host], [URL port]]; + @"%@:%@", [URL host], port]; [headers setObject: host forKey: @"Host"]; } else [headers setObject: [URL host] @@ -707,24 +709,33 @@ - (void)closeAndReconnect { OFURL *URL = [_request URL]; OFTCPSocket *sock; + uint16_t port; + OFNumber *URLPort; [_client close]; if ([[URL scheme] isEqual: @"https"]) { if (of_tls_socket_class == Nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; sock = [[[of_tls_socket_class alloc] init] autorelease]; - } else + port = 443; + } else { sock = [OFTCPSocket socket]; + port = 80; + } + + URLPort = [URL port]; + if (URLPort != nil) + port = [URLPort uInt16Value]; [sock asyncConnectToHost: [URL host] - port: [URL port] + port: port target: self selector: @selector(socketDidConnect:context: exception:) context: nil]; }