@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2022 Jonathan Schleifer + * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -16,48 +16,48 @@ #include "config.h" #include #import "OFHTTPRequest.h" -#import "OFString.h" -#import "OFURI.h" +#import "OFArray.h" +#import "OFData.h" #import "OFDictionary.h" -#import "OFData.h" -#import "OFArray.h" +#import "OFIRI.h" +#import "OFString.h" #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,25 +74,39 @@ 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 URI = _URI, method = _method, headers = _headers; +@synthesize IRI = _IRI, method = _method, headers = _headers; -+ (instancetype)requestWithURI: (OFURI *)URI ++ (instancetype)requestWithIRI: (OFIRI *)IRI { - return [[[self alloc] initWithURI: URI] autorelease]; + return [[[self alloc] initWithIRI: IRI] autorelease]; } -- (instancetype)initWithURI: (OFURI *)URI +- (instancetype)initWithIRI: (OFIRI *)IRI { self = [super init]; @try { - _URI = [URI copy]; + _IRI = [IRI copy]; _method = OFHTTPRequestMethodGet; _protocolVersion.major = 1; _protocolVersion.minor = 1; } @catch (id e) { [self release]; @@ -107,11 +121,11 @@ OF_INVALID_INIT_METHOD } - (void)dealloc { - [_URI release]; + [_IRI release]; [_headers release]; [super dealloc]; } @@ -131,11 +145,11 @@ return NULL; } - (id)copy { - OFHTTPRequest *copy = [[OFHTTPRequest alloc] initWithURI: _URI]; + OFHTTPRequest *copy = [[OFHTTPRequest alloc] initWithIRI: _IRI]; @try { copy->_method = _method; copy->_protocolVersion = _protocolVersion; copy.headers = _headers; @@ -161,11 +175,11 @@ request = object; if (request->_method != _method || request->_protocolVersion.major != _protocolVersion.major || request->_protocolVersion.minor != _protocolVersion.minor || - ![request->_URI isEqual: _URI] || + ![request->_IRI isEqual: _IRI] || ![request->_headers isEqual: _headers]) return false; if (request.remoteAddress != self.remoteAddress && !OFSocketAddressEqual(request.remoteAddress, self.remoteAddress)) @@ -181,11 +195,11 @@ OFHashInit(&hash); OFHashAddByte(&hash, _method); OFHashAddByte(&hash, _protocolVersion.major); OFHashAddByte(&hash, _protocolVersion.minor); - OFHashAddHash(&hash, _URI.hash); + OFHashAddHash(&hash, _IRI.hash); OFHashAddHash(&hash, _headers.hash); if (_hasRemoteAddress) OFHashAddHash(&hash, OFSocketAddressHash(&_remoteAddress)); OFHashFinalize(&hash); @@ -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"]; @@ -254,17 +268,17 @@ remoteAddress = OFSocketAddressString(&_remoteAddress); else remoteAddress = nil; ret = [[OFString alloc] initWithFormat: - @"<%@:\n\tURI = %@\n" - @"\tMethod = %s\n" + @"<%@:\n\tIRI = %@\n" + @"\tMethod = %@\n" @"\tHeaders = %@\n" @"\tRemote address = %@\n" @">", - self.class, _URI, method, indentedHeaders, remoteAddress]; + self.class, _IRI, method, indentedHeaders, remoteAddress]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end