Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -130,11 +130,11 @@ path = IRI.percentEncodedPath; else path = @"/"; requestString = [OFMutableString stringWithFormat: - @"%s %@", OFHTTPRequestMethodName(method), path]; + @"%@ %@", OFHTTPRequestMethodString(method), path]; if (IRI.query != nil) { [requestString appendString: @"?"]; [requestString appendString: IRI.percentEncodedQuery]; } Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -138,16 +138,16 @@ #ifdef __cplusplus extern "C" { #endif /** - * @brief Returns a C string describing the specified request method. + * @brief Returns a string describing the specified request method. * - * @param method The request method which should be described as a C string - * @return A C string describing the specified request method + * @param method The request method which should be described as a string + * @return A string describing the specified request method */ -extern const char *_Nullable OFHTTPRequestMethodName( +extern OFString *_Nullable OFHTTPRequestMethodString( OFHTTPRequestMethod method); /** * @brief Returns the request method for the specified string. * @@ -154,11 +154,35 @@ * @param string The string for which the request method should be returned * @return The request method for the specified string * @throw OFInvalidFormatException The specified string is not a valid HTTP * request method */ -extern OFHTTPRequestMethod OFHTTPRequestMethodParseName(OFString *string); +extern OFHTTPRequestMethod OFHTTPRequestMethodParseString(OFString *string); + +/** + * @brief Returns a C string describing the specified request method. + * + * @deprecated Use @ref OFHTTPRequestMethodString instead. + * + * @param method The request method which should be described as a C string + * @return A C string describing the specified request method + */ +extern const char *_Nullable OFHTTPRequestMethodName(OFHTTPRequestMethod method) + OF_DEPRECATED(ObjFW, 1, 1, "Use OFHTTPRequestMethodString instead"); + +/** + * @brief Returns the request method for the specified string. + * + * @deprecated Use @ref OFHTTPRequestMethodParseString instead. + * + * @param string The string for which the request method should be returned + * @return The request method for the specified string + * @throw OFInvalidFormatException The specified string is not a valid HTTP + * request method + */ +extern OFHTTPRequestMethod OFHTTPRequestMethodParseName(OFString *string) + OF_DEPRECATED(ObjFW, 1, 1, "Use OFHTTPRequestMethodParseString instead"); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -27,37 +27,37 @@ #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFUnsupportedVersionException.h" -const char * -OFHTTPRequestMethodName(OFHTTPRequestMethod method) +OFString * +OFHTTPRequestMethodString(OFHTTPRequestMethod method) { switch (method) { case OFHTTPRequestMethodOptions: - return "OPTIONS"; - case OFHTTPRequestMethodGet: - return "GET"; - case OFHTTPRequestMethodHead: - return "HEAD"; - case OFHTTPRequestMethodPost: - return "POST"; - case OFHTTPRequestMethodPut: - return "PUT"; - case OFHTTPRequestMethodDelete: - return "DELETE"; - case OFHTTPRequestMethodTrace: - return "TRACE"; - case OFHTTPRequestMethodConnect: - return "CONNECT"; - } - - return NULL; + return @"OPTIONS"; + case OFHTTPRequestMethodGet: + return @"GET"; + case OFHTTPRequestMethodHead: + return @"HEAD"; + case OFHTTPRequestMethodPost: + return @"POST"; + case OFHTTPRequestMethodPut: + return @"PUT"; + case OFHTTPRequestMethodDelete: + return @"DELETE"; + case OFHTTPRequestMethodTrace: + return @"TRACE"; + case OFHTTPRequestMethodConnect: + return @"CONNECT"; + } + + return nil; } OFHTTPRequestMethod -OFHTTPRequestMethodParseName(OFString *string) +OFHTTPRequestMethodParseString(OFString *string) { if ([string isEqual: @"OPTIONS"]) return OFHTTPRequestMethodOptions; if ([string isEqual: @"GET"]) return OFHTTPRequestMethodGet; @@ -74,10 +74,24 @@ if ([string isEqual: @"CONNECT"]) return OFHTTPRequestMethodConnect; @throw [OFInvalidFormatException exception]; } + +/* Deprecated */ +const char * +OFHTTPRequestMethodName(OFHTTPRequestMethod method) +{ + return OFHTTPRequestMethodString(method).UTF8String; +} + +/* Deprecated */ +OFHTTPRequestMethod +OFHTTPRequestMethodParseName(OFString *string) +{ + return OFHTTPRequestMethodParseString(string); +} @implementation OFHTTPRequest @synthesize IRI = _IRI, method = _method, headers = _headers; + (instancetype)requestWithIRI: (OFIRI *)IRI @@ -241,11 +255,11 @@ } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); - const char *method = OFHTTPRequestMethodName(_method); + OFString *method = OFHTTPRequestMethodString(_method); OFString *indentedHeaders, *remoteAddress, *ret; indentedHeaders = [_headers.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; @@ -255,11 +269,11 @@ else remoteAddress = nil; ret = [[OFString alloc] initWithFormat: @"<%@:\n\tIRI = %@\n" - @"\tMethod = %s\n" + @"\tMethod = %@\n" @"\tHeaders = %@\n" @"\tRemote address = %@\n" @">", self.class, _IRI, method, indentedHeaders, remoteAddress]; Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -380,11 +380,11 @@ if (pos == OFNotFound) return [self sendErrorAndClose: 400]; method = [line substringToIndex: pos]; @try { - _method = OFHTTPRequestMethodParseName(method); + _method = OFHTTPRequestMethodParseString(method); } @catch (OFInvalidArgumentException *e) { return [self sendErrorAndClose: 405]; } @try { Index: src/exceptions/OFHTTPRequestFailedException.m ================================================================== --- src/exceptions/OFHTTPRequestFailedException.m +++ src/exceptions/OFHTTPRequestFailedException.m @@ -59,12 +59,12 @@ [super dealloc]; } - (OFString *)description { - const char *method = OFHTTPRequestMethodName(_request.method); + OFString *method = OFHTTPRequestMethodString(_request.method); return [OFString stringWithFormat: - @"An HTTP %s request with IRI %@ failed with code %hd!", method, + @"An HTTP %@ request with IRI %@ failed with code %hd!", method, _request.IRI, _response.statusCode]; } @end Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -371,11 +371,11 @@ void *pool = objc_autoreleasePoolPush(); method = method.uppercaseString; @try { - _method = OFHTTPRequestMethodParseName(method); + _method = OFHTTPRequestMethodParseString(method); } @catch (OFInvalidArgumentException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_input_method", @"%[prog]: Invalid request method %[method]!", @"prog", [OFApplication programName], @"method", method)];