ObjFW
OFHTTPServer.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 
19 #ifndef OF_HAVE_SOCKETS
20 # error No sockets available!
21 #endif
22 
23 OF_ASSUME_NONNULL_BEGIN
24 
25 @class OFHTTPServer;
26 @class OFHTTPRequest;
27 @class OFHTTPResponse;
28 @class OFTCPSocket;
29 @class OFException;
30 
45 - (void)server: (OFHTTPServer *)server
46  didReceiveRequest: (OFHTTPRequest *)request
47  response: (OFHTTPResponse *)response;
48 
49 @optional
61 - (bool)server: (OFHTTPServer *)server
62  didReceiveExceptionOnListeningSocket: (OFException *)exception;
63 
78 - (void)server: (OFHTTPServer *)server
79  didReceiveExceptionForResponse: (OFHTTPResponse *)response
80  request: (OFHTTPRequest *)request
81  exception: (OFException *)exception;
82 @end
83 
90 {
91  OFString *_Nullable _host;
92  uint16_t _port;
93  id <OFHTTPServerDelegate> _Nullable _delegate;
94  OFString *_Nullable _name;
95  OFTCPSocket *_Nullable _listeningSocket;
96 }
97 
101 @property OF_NULLABLE_PROPERTY (nonatomic, copy) OFString *host;
102 
106 @property (nonatomic) uint16_t port;
107 
111 @property OF_NULLABLE_PROPERTY (nonatomic, assign)
112  id <OFHTTPServerDelegate> delegate;
113 
120 @property OF_NULLABLE_PROPERTY (nonatomic, copy) OFString *name;
121 
127 + (instancetype)server;
128 
132 - (void)start;
133 
139 - (void)stop;
140 @end
141 
142 OF_ASSUME_NONNULL_END
uint16_t port
Definition: OFHTTPServer.h:106
nonatomic
Definition: OFHTTPServer.h:101
A delegate for OFHTTPServer.
Definition: OFHTTPServer.h:29
id copy()
Returns the class.
Definition: OFObject.m:1133
A class for handling strings.
Definition: OFString.h:114
A class for creating a simple HTTP server inside of applications.
Definition: OFHTTPServer.h:89
void stop()
Stops the HTTP server, meaning it will not accept any new incoming connections, but still handle exis...
Definition: OFHTTPServer.m:729
The base class for all exceptions in ObjFW.
Definition: OFException.h:143
A class which provides methods to create and use TCP sockets.
Definition: OFTCPSocket.h:61
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
A class for storing HTTP requests.
Definition: OFHTTPRequest.h:69
A class for representing an HTTP request reply as a stream.
Definition: OFHTTPResponse.h:30
void start()
Starts the HTTP server in the current thread&#39;s run loop.
Definition: OFHTTPServer.m:710