Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
HttpServer.h
Go to the documentation of this file.
1
/* Project nGenEx
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: NetEx.lib
6
FILE: HttpServer.h
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Network Server Pump for HTTP Server
13
*/
14
15
16
#ifndef HttpServer_h
17
#define HttpServer_h
18
19
#include "
NetServer.h
"
20
21
// +-------------------------------------------------------------------+
22
23
class
HttpParam
;
24
class
HttpRequest
;
25
class
HttpResponse
;
26
27
// +-------------------------------------------------------------------+
28
29
class
HttpServer
:
public
NetServer
30
{
31
public
:
32
static
const
char
*
TYPENAME
() {
return
"HttpServer"
; }
33
34
HttpServer
(WORD port,
int
poolsize
=1);
35
virtual
~HttpServer
();
36
37
int
operator ==
(
const
HttpServer
& l)
const
{
return
addr
== l.
addr
; }
38
39
virtual
Text
ProcessRequest
(
Text
request,
const
NetAddr
&
addr
);
40
virtual
Text
DefaultResponse
();
41
virtual
Text
ErrorResponse
();
42
43
virtual
bool
DoGet
(
HttpRequest
& request,
HttpResponse
& response);
44
virtual
bool
DoPost
(
HttpRequest
& request,
HttpResponse
& response);
45
virtual
bool
DoHead
(
HttpRequest
& request,
HttpResponse
& response);
46
47
virtual
Text
GetServerName
();
48
virtual
void
SetServerName
(
const
char
* name);
49
50
protected
:
51
Text
http_server_name
;
52
};
53
54
// +-------------------------------------------------------------------+
55
56
class
HttpParam
57
{
58
public
:
59
static
const
char
*
TYPENAME
() {
return
"HttpParam"
; }
60
61
HttpParam
(
const
char
* n,
const
char
* v) :
name
(n),
value
(v) { }
62
63
int
operator ==
(
const
HttpParam
& p)
const
{
return
name
== p.
name
; }
64
65
Text
name
;
66
Text
value
;
67
};
68
69
// +-------------------------------------------------------------------+
70
71
class
HttpRequest
72
{
73
public
:
74
static
const
char
*
TYPENAME
() {
return
"HttpRequest"
; }
75
76
enum
METHOD
{
77
HTTP_OPTIONS
,
78
HTTP_GET
,
79
HTTP_HEAD
,
80
HTTP_POST
,
81
HTTP_PUT
,
82
HTTP_DELETE
,
83
HTTP_TRACE
,
84
HTTP_CONNECT
85
};
86
87
HttpRequest
(
const
char
* request=0);
88
~HttpRequest
();
89
90
operator
Text
();
91
92
void
ParseRequest
(
Text
request);
93
void
ParseCookie
(
const
char
* param);
94
95
int
Method
()
const
{
return
method; }
96
Text
URI
()
const
{
return
uri; }
97
Text
Content
()
const
{
return
content; }
98
Text
RequestLine
()
const
{
return
request_line; }
99
100
List<HttpParam>
&
GetQuery
() {
return
query; }
101
List<HttpParam>
&
GetHeaders
() {
return
headers; }
102
List<HttpParam>
&
GetCookies
() {
return
cookies; }
103
104
NetAddr
GetClientAddr
()
const
{
return
client_addr; }
105
void
SetClientAddr
(
const
NetAddr
& a) { client_addr = a; }
106
107
Text
GetParam
(
const
char
* name);
108
109
Text
GetHeader
(
const
char
* name);
110
void
SetHeader
(
const
char
* name,
const
char
* value);
111
void
AddHeader
(
const
char
* name,
const
char
* value);
112
Text
GetCookie
(
const
char
* name);
113
void
SetCookie
(
const
char
* name,
const
char
* value);
114
void
AddCookie
(
const
char
* name,
const
char
* value);
115
116
Text
DecodeParam
(
const
char
* value);
117
static
Text
EncodeParam
(
const
char
* value);
118
119
private
:
120
int
method;
121
Text
uri;
122
Text
content;
123
Text
request_line;
124
NetAddr
client_addr;
125
126
List<HttpParam>
query;
127
List<HttpParam>
headers;
128
List<HttpParam>
cookies;
129
};
130
131
// +-------------------------------------------------------------------+
132
133
class
HttpResponse
134
{
135
public
:
136
static
const
char
*
TYPENAME
() {
return
"HttpResponse"
; }
137
138
enum
STATUS
{
139
SC_CONTINUE
= 100,
140
SC_SWITCHING_PROTOCOLS
= 101,
141
142
SC_OK
= 200,
143
SC_CREATED
= 201,
144
SC_ACCEPTED
= 202,
145
SC_NON_AUTHORITATIVE
= 203,
146
SC_NO_CONTENT
= 204,
147
SC_RESET_CONTENT
= 205,
148
SC_PARTIAL_CONTENT
= 206,
149
150
SC_MULTIPLE_CHOICES
= 300,
151
SC_MOVED_PERMANENTLY
= 301,
152
SC_FOUND
= 302,
153
SC_SEE_OTHER
= 303,
154
SC_NOT_MODIFIED
= 304,
155
SC_USE_PROXY
= 305,
156
SC_TEMPORARY_REDIRECT
= 307,
157
158
SC_BAD_REQUEST
= 400,
159
SC_UNAUTHORIZED
= 401,
160
SC_PAYMENT_REQUIRED
= 402,
161
SC_FORBIDDEN
= 403,
162
SC_NOT_FOUND
= 404,
163
SC_METHOD_NOT_ALLOWED
= 405,
164
SC_NOT_ACCEPTABLE
= 406,
165
SC_PROXY_AUTH_REQ
= 407,
166
SC_REQUEST_TIME_OUT
= 408,
167
SC_CONFLICT
= 409,
168
SC_GONE
= 410,
169
SC_LENGTH_REQUIRED
= 411,
170
171
SC_SERVER_ERROR
= 500,
172
SC_NOT_IMPLEMENTED
= 501,
173
SC_BAD_GATEWAY
= 502,
174
SC_SERVICE_UNAVAILABLE
= 503,
175
SC_GATEWAY_TIMEOUT
= 504,
176
SC_VERSION_NOT_SUPPORTED
= 505
177
};
178
179
180
HttpResponse
(
int
status=500,
const
char
* content=0);
181
HttpResponse
(
const
char
* response);
182
~HttpResponse
();
183
184
operator
Text
();
185
186
void
ParseResponse
(
Text
request);
187
void
ParseCookie
(
const
char
* param);
188
189
int
Status
()
const
{
return
status; }
190
void
SetStatus
(
int
s) { status = s; }
191
192
Text
Content
()
const
{
return
content; }
193
void
SetContent
(
Text
t) { content = t; }
194
void
AddContent
(
Text
t) { content += t; }
195
196
List<HttpParam>
&
GetHeaders
() {
return
headers; }
197
List<HttpParam>
&
GetCookies
() {
return
cookies; }
198
199
Text
GetHeader
(
const
char
* name);
200
void
SetHeader
(
const
char
* name,
const
char
* value);
201
void
AddHeader
(
const
char
* name,
const
char
* value);
202
Text
GetCookie
(
const
char
* name);
203
void
SetCookie
(
const
char
* name,
const
char
* value);
204
void
AddCookie
(
const
char
* name,
const
char
* value);
205
206
void
SendRedirect
(
const
char
* url);
207
208
private
:
209
int
status;
210
Text
content;
211
212
List<HttpParam>
headers;
213
List<HttpParam>
cookies;
214
};
215
216
217
#endif HttpServer_h
NetEx
HttpServer.h
Generated on Thu May 31 2012 16:30:50 for Starshatter_Open by
1.8.1