@@ -33,10 +33,11 @@ #import "OFHTTPRequestFailedException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFNotConnectedException.h" +#import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" @@ -322,11 +323,11 @@ redirects: (size_t)redirects { void *pool = objc_autoreleasePoolPush(); OFURL *URL = [request URL]; OFString *scheme = [URL scheme]; - of_http_request_type_t requestType = [request requestType]; + of_http_request_method_t method = [request method]; OFMutableString *requestString; OFDictionary *headers = [request headers]; OFDataArray *POSTData = [request POSTData]; OFTCPSocket *socket; OFHTTPClientResponse *response; @@ -333,14 +334,19 @@ OFString *line, *path, *version, *redirect, *keepAlive; OFMutableDictionary *serverHeaders; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; int status; - const char *type = NULL; if (![scheme isEqual: @"http"] && ![scheme isEqual: @"https"]) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; + + if (method != OF_HTTP_REQUEST_METHOD_GET && + method != OF_HTTP_REQUEST_METHOD_HEAD && + method != OF_HTTP_REQUEST_METHOD_POST) + @throw [OFNotImplementedException exceptionWithSelector: _cmd + object: self]; /* Can we reuse the socket? */ if (_socket != nil && [[_lastURL scheme] isEqual: [URL scheme]] && [[_lastURL host] isEqual: [URL host]] && [_lastURL port] == [URL port]) { @@ -366,17 +372,10 @@ [_lastResponse release]; _lastResponse = nil; } else socket = [self OF_createSocketForRequest: request]; - if (requestType == OF_HTTP_REQUEST_TYPE_GET) - type = "GET"; - if (requestType == OF_HTTP_REQUEST_TYPE_HEAD) - type = "HEAD"; - if (requestType == OF_HTTP_REQUEST_TYPE_POST) - type = "POST"; - if ([(path = [URL path]) length] == 0) path = @"/"; /* * As a work around for a bug with split packets in lighttpd when using @@ -384,15 +383,17 @@ * send it all at once. */ if ([URL query] != nil) requestString = [OFMutableString stringWithFormat: @"%s %@?%@ HTTP/%@\r\n", - type, path, [URL query], [request protocolVersionString]]; + of_http_request_method_to_string(method), path, [URL query], + [request protocolVersionString]]; else requestString = [OFMutableString stringWithFormat: @"%s %@ HTTP/%@\r\n", - type, path, [request protocolVersionString]]; + of_http_request_method_to_string(method), path, + [request protocolVersionString]]; if ([URL port] == 80) [requestString appendFormat: @"Host: %@\r\n", [URL host]]; else [requestString appendFormat: @"Host: %@:%d\r\n", [URL host], @@ -408,11 +409,11 @@ while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [requestString appendFormat: @"%@: %@\r\n", key, object]; - if (requestType == OF_HTTP_REQUEST_TYPE_POST) { + if (method == OF_HTTP_REQUEST_METHOD_POST) { OFString *contentType = [request MIMEType]; if (contentType == nil) contentType = @"application/x-www-form-urlencoded; " @"charset=UTF-8"; @@ -438,11 +439,11 @@ /* Reconnect in case a keep-alive connection timed out */ socket = [self OF_createSocketForRequest: request]; [socket writeString: requestString]; } - if (requestType == OF_HTTP_REQUEST_TYPE_POST) + if (method == OF_HTTP_REQUEST_METHOD_POST) [socket writeBuffer: [POSTData items] length: [POSTData count] * [POSTData itemSize]]; @try { line = [socket readLine]; @@ -457,11 +458,11 @@ */ if (line == nil) { socket = [self OF_createSocketForRequest: request]; [socket writeString: requestString]; - if (requestType == OF_HTTP_REQUEST_TYPE_POST) + if (method == OF_HTTP_REQUEST_METHOD_POST) [socket writeBuffer: [POSTData items] length: [POSTData count] * [POSTData itemSize]]; @try { @@ -575,18 +576,18 @@ if (follow) { OFHTTPRequest *newRequest; newRequest = [OFHTTPRequest requestWithURL: newURL]; - [newRequest setRequestType: requestType]; + [newRequest setMethod: method]; [newRequest setHeaders: headers]; [newRequest setPOSTData: POSTData]; [newRequest setMIMEType: [request MIMEType]]; if (status == 303) { [newRequest - setRequestType: OF_HTTP_REQUEST_TYPE_GET]; + setMethod: OF_HTTP_REQUEST_METHOD_GET]; [newRequest setPOSTData: nil]; [newRequest setMIMEType: nil]; } [newRequest retain];