Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -186,11 +186,12 @@ SRCS_SOCKETS += OFKernelEventObserver.m \ ${OFKERNELEVENTOBSERVER_EPOLL_M} \ ${OFKERNELEVENTOBSERVER_KQUEUE_M} \ ${OFKERNELEVENTOBSERVER_POLL_M} \ ${OFKERNELEVENTOBSERVER_SELECT_M} \ - OFTCPSocket+SOCKS5.m + OFTCPSocket+SOCKS5.m \ + OFURLHandler_HTTP.m OBJS_EXTRA = ${RUNTIME_RUNTIME_A} \ ${EXCEPTIONS_EXCEPTIONS_A} \ ${ENCODINGS_ENCODINGS_A} \ ${FORWARDING_FORWARDING_A} \ Index: src/OFURLHandler.m ================================================================== --- src/OFURLHandler.m +++ src/OFURLHandler.m @@ -25,10 +25,13 @@ #endif #ifdef OF_HAVE_FILES # import "OFURLHandler_file.h" #endif +#ifdef OF_HAVE_SOCKETS +# import "OFURLHandler_HTTP.h" +#endif static OFMutableDictionary OF_GENERIC(OFString *, OFURLHandler *) *handlers; #ifdef OF_HAVE_THREADS static OFMutex *mutex; #endif @@ -48,10 +51,16 @@ #ifdef OF_HAVE_FILES [self registerClass: [OFURLHandler_file class] forScheme: @"file"]; #endif +#ifdef OF_HAVE_SOCKETS + [self registerClass: [OFURLHandler_HTTP class] + forScheme: @"http"]; + [self registerClass: [OFURLHandler_HTTP class] + forScheme: @"https"]; +#endif } + (bool)registerClass: (Class)class forScheme: (OFString *)scheme { ADDED src/OFURLHandler_HTTP.h Index: src/OFURLHandler_HTTP.h ================================================================== --- src/OFURLHandler_HTTP.h +++ src/OFURLHandler_HTTP.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018 + * 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 + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFURLHandler.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface OFURLHandler_HTTP: OFURLHandler +@end + +OF_ASSUME_NONNULL_END ADDED src/OFURLHandler_HTTP.m Index: src/OFURLHandler_HTTP.m ================================================================== --- src/OFURLHandler_HTTP.m +++ src/OFURLHandler_HTTP.m @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018 + * 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 + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFURLHandler_HTTP.h" +#import "OFHTTPClient.h" +#import "OFHTTPRequest.h" +#import "OFHTTPResponse.h" + +@implementation OFURLHandler_HTTP +- (OFStream *)openItemAtURL: (OFURL *)URL + mode: (OFString *)mode +{ + void *pool = objc_autoreleasePoolPush(); + OFHTTPClient *client = [OFHTTPClient client]; + OFHTTPRequest *request = [OFHTTPRequest requestWithURL: URL]; + OFHTTPResponse *response = [client performRequest: request]; + + [response retain]; + + objc_autoreleasePoolPop(pool); + + return [response autorelease]; +} +@end