ObjFW
Loading...
Searching...
No Matches
OFHTTPServer.h
1/*
2 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This file is part of ObjFW. It may be distributed under the terms of the
7 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8 * the packaging of this file.
9 *
10 * Alternatively, it may be distributed under the terms of the GNU General
11 * Public License, either version 2 or 3, which can be found in the file
12 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13 * file.
14 */
15
16#import "OFObject.h"
17
18#ifndef OF_HAVE_SOCKETS
19# error No sockets available!
20#endif
21
22OF_ASSUME_NONNULL_BEGIN
23
24@class OFArray;
25@class OFHTTPRequest;
26@class OFHTTPResponse;
27@class OFHTTPServer;
28@class OFStream;
29@class OFTCPSocket;
30
36@protocol OFHTTPServerDelegate <OFObject>
46- (void)server: (OFHTTPServer *)server
47 didReceiveRequest: (OFHTTPRequest *)request
48 requestBody: (nullable OFStream *)requestBody
49 response: (OFHTTPResponse *)response;
50
51@optional
63- (bool)server: (OFHTTPServer *)server
64 didReceiveExceptionOnListeningSocket: (id)exception;
65
81- (void)server: (OFHTTPServer *)server
82 didReceiveExceptionForResponse: (OFHTTPResponse *)response
83 request: (OFHTTPRequest *)request
84 exception: (id)exception;
85@end
86
92OF_SUBCLASSING_RESTRICTED
94{
95 OFString *_Nullable _host;
96 uint16_t _port;
97 id <OFHTTPServerDelegate> _Nullable _delegate;
98 OFString *_Nullable _name;
99 OFTCPSocket *_Nullable _listeningSocket;
100#ifdef OF_HAVE_THREADS
101 size_t _numberOfThreads, _nextThreadIndex;
102 OFArray *_threadPool;
103#endif
104}
105
112@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *host;
113
120@property (nonatomic) uint16_t port;
121
125@property OF_NULLABLE_PROPERTY (assign, nonatomic)
126 id <OFHTTPServerDelegate> delegate;
127
128#ifdef OF_HAVE_THREADS
140@property (nonatomic) size_t numberOfThreads;
141#endif
142
149@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *name;
150
156+ (instancetype)server;
157
163- (void)start;
164
170- (void)stop;
171@end
172
173OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition OFArray.h:105
A class for storing HTTP requests.
Definition OFHTTPRequest.h:71
A class for representing an HTTP request response as a stream.
Definition OFHTTPResponse.h:33
A class for creating a simple HTTP server inside of applications.
Definition OFHTTPServer.h:94
OFString * name
The server name the server presents to clients.
Definition OFHTTPServer.h:149
OFString * host
The host on which the HTTP server will listen.
Definition OFHTTPServer.h:112
The root class for all other classes inside ObjFW.
Definition OFObject.h:688
A base class for different types of streams.
Definition OFStream.h:188
A class for handling strings.
Definition OFString.h:135
A class which provides methods to create and use TCP sockets.
Definition OFTCPSocket.h:67