Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -154,11 +154,11 @@ * * @param string The string for which the request method should be returned * @return The request method for the specified string */ extern of_http_request_method_t of_http_request_method_from_string( - const char *string); + OFString *string); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -24,10 +24,11 @@ #import "OFURL.h" #import "OFDictionary.h" #import "OFData.h" #import "OFArray.h" +#import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFUnsupportedVersionException.h" const char * @@ -54,30 +55,30 @@ return NULL; } of_http_request_method_t -of_http_request_method_from_string(const char *string) +of_http_request_method_from_string(OFString *string) { - if (strcmp(string, "OPTIONS") == 0) + if ([string isEqual: @"OPTIONS"]) return OF_HTTP_REQUEST_METHOD_OPTIONS; - if (strcmp(string, "GET") == 0) + if ([string isEqual: @"GET"]) return OF_HTTP_REQUEST_METHOD_GET; - if (strcmp(string, "HEAD") == 0) + if ([string isEqual: @"HEAD"]) return OF_HTTP_REQUEST_METHOD_HEAD; - if (strcmp(string, "POST") == 0) + if ([string isEqual: @"POST"]) return OF_HTTP_REQUEST_METHOD_POST; - if (strcmp(string, "PUT") == 0) + if ([string isEqual: @"PUT"]) return OF_HTTP_REQUEST_METHOD_PUT; - if (strcmp(string, "DELETE") == 0) + if ([string isEqual: @"DELETE"]) return OF_HTTP_REQUEST_METHOD_DELETE; - if (strcmp(string, "TRACE") == 0) + if ([string isEqual: @"TRACE"]) return OF_HTTP_REQUEST_METHOD_TRACE; - if (strcmp(string, "CONNECT") == 0) + if ([string isEqual: @"CONNECT"]) return OF_HTTP_REQUEST_METHOD_CONNECT; - @throw [OFInvalidFormatException exception]; + @throw [OFInvalidArgumentException exception]; } @implementation OFHTTPRequest @synthesize URL = _URL, method = _method, headers = _headers; Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -370,12 +370,12 @@ if (pos == OF_NOT_FOUND) return [self sendErrorAndClose: 400]; method = [line substringWithRange: of_range(0, pos)]; @try { - _method = of_http_request_method_from_string(method.UTF8String); - } @catch (OFInvalidFormatException *e) { + _method = of_http_request_method_from_string(method); + } @catch (OFInvalidArgumentException *e) { return [self sendErrorAndClose: 405]; } @try { of_range_t range = of_range(pos + 1, line.length - pos - 10); Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -35,10 +35,11 @@ #import "OFTLSSocket.h" #import "OFURL.h" #import "OFConnectionFailedException.h" #import "OFHTTPRequestFailedException.h" +#import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" @@ -335,23 +336,13 @@ { void *pool = objc_autoreleasePoolPush(); method = method.uppercaseString; - if ([method isEqual: @"GET"]) - _method = OF_HTTP_REQUEST_METHOD_GET; - else if ([method isEqual: @"HEAD"]) - _method = OF_HTTP_REQUEST_METHOD_HEAD; - else if ([method isEqual: @"POST"]) - _method = OF_HTTP_REQUEST_METHOD_POST; - else if ([method isEqual: @"PUT"]) - _method = OF_HTTP_REQUEST_METHOD_PUT; - else if ([method isEqual: @"DELETE"]) - _method = OF_HTTP_REQUEST_METHOD_DELETE; - else if ([method isEqual: @"TRACE"]) - _method = OF_HTTP_REQUEST_METHOD_TRACE; - else { + @try { + _method = of_http_request_method_from_string(method); + } @catch (OFInvalidArgumentException *e) { [of_stderr writeLine: OF_LOCALIZED(@"invalid_input_method", @"%[prog]: Invalid request method %[method]!", @"prog", [OFApplication programName], @"method", method)]; [OFApplication terminateWithStatus: 1];