1//
2// HTTPServer.h
3//
4// Library: Net
5// Package: HTTPServer
6// Module: HTTPServer
7//
8// Definition of the HTTPServer class.
9//
10// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Net_HTTPServer_INCLUDED
18#define Net_HTTPServer_INCLUDED
19
20
21#include "Poco/Net/Net.h"
22#include "Poco/Net/TCPServer.h"
23#include "Poco/Net/HTTPRequestHandlerFactory.h"
24#include "Poco/Net/HTTPServerParams.h"
25
26
27namespace Poco {
28namespace Net {
29
30
31class Net_API HTTPServer: public TCPServer
32 /// A subclass of TCPServer that implements a
33 /// full-featured multithreaded HTTP server.
34 ///
35 /// A HTTPRequestHandlerFactory must be supplied.
36 /// The ServerSocket must be bound and in listening state.
37 ///
38 /// To configure various aspects of the server, a HTTPServerParams
39 /// object can be passed to the constructor.
40 ///
41 /// The server supports:
42 /// - HTTP/1.0 and HTTP/1.1
43 /// - automatic handling of persistent connections.
44 /// - automatic decoding/encoding of request/response message bodies
45 /// using chunked transfer encoding.
46 ///
47 /// Please see the TCPServer class for information about
48 /// connection and thread handling.
49 ///
50 /// See RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html> for more
51 /// information about the HTTP protocol.
52{
53public:
54 HTTPServer(HTTPRequestHandlerFactory::Ptr pFactory, Poco::UInt16 portNumber = 80, HTTPServerParams::Ptr pParams = new HTTPServerParams);
55 /// Creates HTTPServer listening on the given port (default 80).
56 ///
57 /// The server takes ownership of the HTTPRequstHandlerFactory
58 /// and deletes it when it's no longer needed.
59 ///
60 /// New threads are taken from the default thread pool.
61
62 HTTPServer(HTTPRequestHandlerFactory::Ptr pFactory, const ServerSocket& socket, HTTPServerParams::Ptr pParams);
63 /// Creates the HTTPServer, using the given ServerSocket.
64 ///
65 /// The server takes ownership of the HTTPRequstHandlerFactory
66 /// and deletes it when it's no longer needed.
67 ///
68 /// The server also takes ownership of the HTTPServerParams object.
69 ///
70 /// New threads are taken from the default thread pool.
71
72 HTTPServer(HTTPRequestHandlerFactory::Ptr pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, HTTPServerParams::Ptr pParams);
73 /// Creates the HTTPServer, using the given ServerSocket.
74 ///
75 /// The server takes ownership of the HTTPRequstHandlerFactory
76 /// and deletes it when it's no longer needed.
77 ///
78 /// The server also takes ownership of the HTTPServerParams object.
79 ///
80 /// New threads are taken from the given thread pool.
81
82 ~HTTPServer();
83 /// Destroys the HTTPServer and its HTTPRequestHandlerFactory.
84
85 void stopAll(bool abortCurrent = false);
86 /// Stops the server. In contrast to TCPServer::stop(), which also
87 /// stops the server, but allows all client connections to finish at
88 /// their pace, this allows finer control over client connections.
89 ///
90 /// If abortCurrent is false, all current requests are allowed to
91 /// complete. If abortCurrent is true, the underlying sockets of
92 /// all client connections are shut down, causing all requests
93 /// to abort.
94
95private:
96 HTTPRequestHandlerFactory::Ptr _pFactory;
97};
98
99
100} } // namespace Poco::Net
101
102
103#endif // Net_HTTPServer_INCLUDED
104