summaryrefslogtreecommitdiff
path: root/lib/httpserver/HTTPServer.h
blob: 88da7abf15bc35df84edf12cacd87cb54716ea97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// --------------------------------------------------------------------------
//
// File
//		Name:    HTTPServer.h
//		Purpose: HTTP server class
//		Created: 26/3/04
//
// --------------------------------------------------------------------------

#ifndef HTTPSERVER__H
#define HTTPSERVER__H

#include "ServerStream.h"
#include "SocketStream.h"

class HTTPRequest;
class HTTPResponse;

// --------------------------------------------------------------------------
//
// Class
//		Name:    HTTPServer
//		Purpose: HTTP server
//		Created: 26/3/04
//
// --------------------------------------------------------------------------
class HTTPServer : public ServerStream<SocketStream, 80>
{
public:
	HTTPServer();
	~HTTPServer();
private:
	// no copying
	HTTPServer(const HTTPServer &);
	HTTPServer &operator=(const HTTPServer &);
public:

	int GetTimeout() const {return mTimeout;}

	// --------------------------------------------------------------------------
	//
	// Function
	//		Name:    HTTPServer::Handle(const HTTPRequest &, HTTPResponse &)
	//		Purpose: Response to a request, filling in the response object for sending
	//				 at some point in the future.
	//		Created: 26/3/04
	//
	// --------------------------------------------------------------------------
	virtual void Handle(const HTTPRequest &rRequest, HTTPResponse &rResponse) = 0;
	
	// For notifications to derived classes
	virtual void HTTPConnectionOpening();
	virtual void HTTPConnectionClosing();

private:
	const char *DaemonName() const;
	const ConfigurationVerify *GetConfigVerify() const;
	void Run();
	void Connection(SocketStream &rStream);
	void SendInternalErrorResponse(const char *Error, SocketStream &rStream);

private:
	int mTimeout;	// Timeout for read operations
};

// Root level
#define HTTPSERVER_VERIFY_ROOT_KEYS \
	{"AddressPrefix", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0}

// AddressPrefix is, for example, http://localhost:1080 -- ie the beginning of the URI
// This is used for handling redirections.

// Server level
#define HTTPSERVER_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES) \
	SERVERSTREAM_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES)

#endif // HTTPSERVER__H