Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -49,10 +49,24 @@ /** * \return A new, autoreleased OFHTTPRequest */ + request; +/** + * \param url The URL for the request + * \return A new, autoreleased OFHTTPRequest + */ ++ requestWithURL: (OFURL*)url; + +/** + * Initializes an already allocated OFHTTPRequest with the specified URL. + * + * \param url The URL for the request + * \return An initialized OFHTTPRequest + */ +- initWithURL: (OFURL*)url; + /** * Sets the URL for the HTTP request. * * \param URL The URL for the HTTP request */ Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -38,10 +38,15 @@ @implementation OFHTTPRequest + request { return [[[self alloc] init] autorelease]; } + ++ requestWithURL: (OFURL*)url +{ + return [[[self alloc] initWithURL: url] autorelease]; +} - init { self = [super init]; @@ -48,10 +53,24 @@ requestType = OF_HTTP_REQUEST_TYPE_GET; headers = [[OFDictionary alloc] initWithObject: @"Something using ObjFW " @"" forKey: @"User-Agent"]; + + return self; +} + +- initWithURL: (OFURL*)url +{ + self = [self init]; + + @try { + [self setURL: url]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc Index: tests/OFHTTPRequestTests.m ================================================================== --- tests/OFHTTPRequestTests.m +++ tests/OFHTTPRequestTests.m @@ -103,12 +103,11 @@ url = [OFURL URLWithString: [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server->port]]; - TEST(@"+[request]", (req = [OFHTTPRequest request])) - TEST(@"-[setURL:]", R([req setURL: url])) + TEST(@"+[requestWithURL]", (req = [OFHTTPRequest requestWithURL: url])) [cond wait]; [cond unlock]; TEST(@"-[perform]", (res = [req perform]))