ObjFW
OFHTTPServer.h
1 /*
2  * Copyright (c) 2008-2025 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 
22 #ifndef OF_HAVE_SOCKETS
23 # error No sockets available!
24 #endif
25 
26 OF_ASSUME_NONNULL_BEGIN
27 
28 @class OFArray OF_GENERIC(ObjectType);
29 @class OFHTTPRequest;
30 @class OFHTTPResponse;
31 @class OFHTTPServer;
32 @class OFStream;
33 @class OFTCPSocket;
35 
51 - (void)server: (OFHTTPServer *)server
52  didReceiveRequest: (OFHTTPRequest *)request
53  requestBody: (nullable OFStream *)requestBody
54  response: (OFHTTPResponse *)response;
55 
56 @optional
80 - (void)server: (OFHTTPServer *)server
81  didEncounterException: (id)exception
82  request: (nullable OFHTTPRequest *)request
83  response: (nullable OFHTTPResponse *)response;
84 
98 - (bool)server: (OFHTTPServer *)server
99  didReceiveExceptionOnListeningSocket: (id)exception
100  OF_DEPRECATED(ObjFW, 1, 3,
101  "Use -[server:didEncounterException:request:response:] instead");
102 
120 - (void)server: (OFHTTPServer *)server
121  didReceiveExceptionForResponse: (OFHTTPResponse *)response
122  request: (OFHTTPRequest *)request
123  exception: (id)exception
124  OF_DEPRECATED(ObjFW, 1, 3,
125  "Use -[server:didEncounterException:request:response:] instead");
126 @end
127 
133 OF_SUBCLASSING_RESTRICTED
135 {
136  OFString *_Nullable _host;
137  uint16_t _port;
138  OFObject <OFHTTPServerDelegate> *_Nullable _delegate;
139  OFString *_Nullable _name;
140  OFTCPSocket *_Nullable _listeningSocket;
141  bool _usesTLS;
142  OFArray OF_GENERIC(OFX509Certificate *) *_Nullable _certificateChain;
143 #ifdef OF_HAVE_THREADS
144  size_t _numberOfThreads, _nextThreadIndex;
145  OFArray *_threadPool;
146 #endif
147 }
148 
155 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *host;
156 
163 @property (nonatomic) uint16_t port;
164 
171 @property (nonatomic) bool usesTLS;
172 
176 @property OF_NULLABLE_PROPERTY (copy, nonatomic)
177  OFArray OF_GENERIC(OFX509Certificate *) *certificateChain;
178 
182 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
184 
185 #ifdef OF_HAVE_THREADS
186 
197 @property (nonatomic) size_t numberOfThreads;
198 #endif
199 
206 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *name;
207 
213 + (instancetype)server;
214 
220 - (void)start;
221 
227 - (void)stop;
228 @end
229 
230 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:107
The root class for all other classes inside ObjFW.
Definition: OFObject.h:690
A class for representing an HTTP request response as a stream.
Definition: OFHTTPResponse.h:36
A base class for different types of streams.
Definition: OFStream.h:278
A delegate for OFHTTPServer.
Definition: OFHTTPServer.h:34
A class for handling strings.
Definition: OFString.h:142
A class which provides methods to create and use TCP sockets.
Definition: OFTCPSocket.h:85
A class for creating a simple HTTP server inside of applications.
Definition: OFHTTPServer.h:134
An X.509 certificate, optionally with an associated private key.
Definition: OFX509Certificate.h:32
A class for storing HTTP requests.
Definition: OFHTTPRequest.h:73