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 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
26OF_ASSUME_NONNULL_BEGIN
27
28@class OFArray;
29@class OFHTTPRequest;
30@class OFHTTPResponse;
31@class OFHTTPServer;
32@class OFStream;
33@class OFTCPSocket;
34
40@protocol OFHTTPServerDelegate <OFObject>
50- (void)server: (OFHTTPServer *)server
51 didReceiveRequest: (OFHTTPRequest *)request
52 requestBody: (nullable OFStream *)requestBody
53 response: (OFHTTPResponse *)response;
54
55@optional
67- (bool)server: (OFHTTPServer *)server
68 didReceiveExceptionOnListeningSocket: (id)exception;
69
85- (void)server: (OFHTTPServer *)server
86 didReceiveExceptionForResponse: (OFHTTPResponse *)response
87 request: (OFHTTPRequest *)request
88 exception: (id)exception;
89@end
90
96OF_SUBCLASSING_RESTRICTED
98{
99 OFString *_Nullable _host;
100 uint16_t _port;
101 id <OFHTTPServerDelegate> _Nullable _delegate;
102 OFString *_Nullable _name;
103 OFTCPSocket *_Nullable _listeningSocket;
104#ifdef OF_HAVE_THREADS
105 size_t _numberOfThreads, _nextThreadIndex;
106 OFArray *_threadPool;
107#endif
108}
109
116@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *host;
117
124@property (nonatomic) uint16_t port;
125
129@property OF_NULLABLE_PROPERTY (assign, nonatomic)
130 id <OFHTTPServerDelegate> delegate;
131
132#ifdef OF_HAVE_THREADS
144@property (nonatomic) size_t numberOfThreads;
145#endif
146
153@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *name;
154
160+ (instancetype)server;
161
167- (void)start;
168
174- (void)stop;
175@end
176
177OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition OFArray.h:109
A class for storing HTTP requests.
Definition OFHTTPRequest.h:75
A class for representing an HTTP request response as a stream.
Definition OFHTTPResponse.h:37
A class for creating a simple HTTP server inside of applications.
Definition OFHTTPServer.h:98
OFString * name
The server name the server presents to clients.
Definition OFHTTPServer.h:153
OFString * host
The host on which the HTTP server will listen.
Definition OFHTTPServer.h:116
The root class for all other classes inside ObjFW.
Definition OFObject.h:692
A base class for different types of streams.
Definition OFStream.h:192
A class for handling strings.
Definition OFString.h:139
A class which provides methods to create and use TCP sockets.
Definition OFTCPSocket.h:71