1 /*****************************************************************
3 | Platinum - HTTP Server
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
7 | http://www.plutinosoft.com
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
33 ****************************************************************/
39 #ifndef _PLT_HTTP_SERVER_H_
40 #define _PLT_HTTP_SERVER_H_
42 /*----------------------------------------------------------------------
44 +---------------------------------------------------------------------*/
46 #include "PltHttpServerTask.h"
48 /*----------------------------------------------------------------------
49 | PLT_HttpServer class
50 +---------------------------------------------------------------------*/
52 The PLT_HttpServer class provides an asynchronous way to handle multiple HTTP requests
53 concurrently. Pipelining requests and keep-alive connections are supported.
55 class PLT_HttpServer
: public NPT_HttpRequestHandler
,
59 PLT_HttpServer(NPT_IpAddress address
= NPT_IpAddress::Any
,
61 bool allow_random_port_on_bind_failure
= false,
62 NPT_Cardinal max_clients
= 50,
63 bool reuse_address
= false);
64 ~PLT_HttpServer() override
;
67 static NPT_Result
ServeFile(const NPT_HttpRequest
& request
,
68 const NPT_HttpRequestContext
& context
,
69 NPT_HttpResponse
& response
,
70 NPT_String file_path
);
71 static NPT_Result
ServeStream(const NPT_HttpRequest
& request
,
72 const NPT_HttpRequestContext
& context
,
73 NPT_HttpResponse
& response
,
74 NPT_InputStreamReference
& stream
,
75 const char* content_type
);
77 // NPT_HttpRequestHandler methods
78 NPT_Result
SetupResponse(NPT_HttpRequest
& request
,
79 const NPT_HttpRequestContext
& context
,
80 NPT_HttpResponse
& response
) override
;
83 virtual NPT_Result
Start();
84 virtual NPT_Result
Stop();
85 virtual unsigned int GetPort() { return m_Port
; }
88 PLT_TaskManagerReference m_TaskManager
;
89 NPT_Reference
<NPT_HttpServer
> m_Server
;
90 NPT_IpAddress m_Address
;
92 bool m_AllowRandomPortOnBindFailure
;
98 typedef NPT_Reference
<PLT_HttpServer
> PLT_HttpServerReference
;
100 #endif /* _PLT_HTTP_SERVER_H_ */