ObjFW
OFHTTPServer.h
1 /*
2  * Copyright (c) 2008-2021 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 
22 OF_ASSUME_NONNULL_BEGIN
23 
24 @class OFArray;
25 @class OFHTTPRequest;
26 @class OFHTTPResponse;
27 @class OFHTTPServer;
28 @class OFStream;
29 @class OFTCPSocket;
30 
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 
80 - (void)server: (OFHTTPServer *)server
81  didReceiveExceptionForResponse: (OFHTTPResponse *)response
82  request: (OFHTTPRequest *)request
83  exception: (id)exception;
84 @end
85 
91 OF_SUBCLASSING_RESTRICTED
93 {
94  OFString *_Nullable _host;
95  uint16_t _port;
96  bool _usesTLS;
97  OFString *_Nullable _certificateFile, *_Nullable _privateKeyFile;
98  const char *_Nullable _privateKeyPassphrase;
99  id <OFHTTPServerDelegate> _Nullable _delegate;
100  OFString *_Nullable _name;
101  OFTCPSocket *_Nullable _listeningSocket;
102 #ifdef OF_HAVE_THREADS
103  size_t _numberOfThreads, _nextThreadIndex;
104  OFArray *_threadPool;
105 #endif
106 }
107 
114 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *host;
115 
122 @property (nonatomic) uint16_t port;
123 
130 @property (nonatomic) bool usesTLS;
131 
138 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *certificateFile;
139 
146 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *privateKeyFile;
147 
157 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
158  const char *privateKeyPassphrase;
159 
163 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
164  id <OFHTTPServerDelegate> delegate;
165 
166 #ifdef OF_HAVE_THREADS
178 @property (nonatomic) size_t numberOfThreads;
179 #endif
180 
187 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *name;
188 
194 + (instancetype)server;
195 
199 - (void)start;
200 
206 - (void)stop;
207 @end
208 
209 OF_ASSUME_NONNULL_END
struct objc_object * id
A pointer to any object.
Definition: ObjFWRT.h:90
An abstract class for storing objects in an array.
Definition: OFArray.h:92
A class for storing HTTP requests.
Definition: OFHTTPRequest.h:74
A class for representing an HTTP request reply as a stream.
Definition: OFHTTPResponse.h:30
A class for creating a simple HTTP server inside of applications.
Definition: OFHTTPServer.h:93
OFString * certificateFile
The path to the X.509 certificate file to use for TLS.
Definition: OFHTTPServer.h:138
OFString * name
The server name the server presents to clients.
Definition: OFHTTPServer.h:187
OFString * privateKeyFile
The path to the PKCS#8 private key file to use for TLS.
Definition: OFHTTPServer.h:146
OFString * host
The host on which the HTTP server will listen.
Definition: OFHTTPServer.h:114
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A base class for different types of streams.
Definition: OFStream.h:191
A class for handling strings.
Definition: OFString.h:132
A class which provides methods to create and use TCP sockets.
Definition: OFTCPSocket.h:67
A delegate for OFHTTPServer.
Definition: OFHTTPServer.h:36