132
|
1 /*******************************************************************************
|
|
2
|
|
3 copyright: Copyright (c) 2004 Kris Bell. All rights reserved
|
|
4
|
|
5 license: BSD style: $(LICENSE)
|
|
6
|
|
7 version: Initial release: April 2004
|
|
8
|
|
9 author: Kris
|
|
10
|
|
11 *******************************************************************************/
|
|
12
|
|
13 module tango.net.http.HttpConst;
|
|
14
|
|
15 /*******************************************************************************
|
|
16
|
|
17 Constants
|
|
18
|
|
19 *******************************************************************************/
|
|
20
|
|
21 struct HttpConst
|
|
22 {
|
|
23 const char[] Eol = "\r\n";
|
|
24 }
|
|
25
|
|
26 /*******************************************************************************
|
|
27
|
|
28 Headers are distinct types in their own right. This is because they
|
|
29 are somewhat optimized via a trailing ':' character.
|
|
30
|
|
31 *******************************************************************************/
|
|
32
|
|
33 struct HttpHeaderName
|
|
34 {
|
|
35 final char[] value;
|
|
36 }
|
|
37
|
|
38 /*******************************************************************************
|
|
39
|
|
40 Define the traditional set of HTTP header names
|
|
41
|
|
42 *******************************************************************************/
|
|
43
|
|
44 struct HttpHeader
|
|
45 {
|
|
46 // size of both the request & response buffer (per thread)
|
|
47 const int IOBufferSize = 16 * 1024;
|
|
48
|
|
49 // maximum length for POST parameters (to avoid DOS ...)
|
|
50 const int MaxPostParamSize = 4 * 1024;
|
|
51
|
|
52 const HttpHeaderName Version = {"HTTP/1.0"};
|
|
53 const HttpHeaderName TextHtml = {"text/html"};
|
|
54
|
|
55 const HttpHeaderName Accept = {"Accept:"};
|
|
56 const HttpHeaderName AcceptCharset = {"Accept-Charset:"};
|
|
57 const HttpHeaderName AcceptEncoding = {"Accept-Encoding:"};
|
|
58 const HttpHeaderName AcceptLanguage = {"Accept-Language:"};
|
|
59 const HttpHeaderName AcceptRanges = {"Accept-Ranges:"};
|
|
60 const HttpHeaderName Age = {"Age:"};
|
|
61 const HttpHeaderName Allow = {"Allow:"};
|
|
62 const HttpHeaderName Authorization = {"Authorization:"};
|
|
63 const HttpHeaderName CacheControl = {"Cache-Control:"};
|
|
64 const HttpHeaderName Connection = {"Connection:"};
|
|
65 const HttpHeaderName ContentEncoding = {"Content-Encoding:"};
|
|
66 const HttpHeaderName ContentLanguage = {"Content-Language:"};
|
|
67 const HttpHeaderName ContentLength = {"Content-Length:"};
|
|
68 const HttpHeaderName ContentLocation = {"Content-Location:"};
|
|
69 const HttpHeaderName ContentRange = {"Content-Range:"};
|
|
70 const HttpHeaderName ContentType = {"Content-Type:"};
|
|
71 const HttpHeaderName Cookie = {"Cookie:"};
|
|
72 const HttpHeaderName Date = {"Date:"};
|
|
73 const HttpHeaderName ETag = {"ETag:"};
|
|
74 const HttpHeaderName Expect = {"Expect:"};
|
|
75 const HttpHeaderName Expires = {"Expires:"};
|
|
76 const HttpHeaderName From = {"From:"};
|
|
77 const HttpHeaderName Host = {"Host:"};
|
|
78 const HttpHeaderName Identity = {"Identity:"};
|
|
79 const HttpHeaderName IfMatch = {"If-Match:"};
|
|
80 const HttpHeaderName IfModifiedSince = {"If-Modified-Since:"};
|
|
81 const HttpHeaderName IfNoneMatch = {"If-None-Match:"};
|
|
82 const HttpHeaderName IfRange = {"If-Range:"};
|
|
83 const HttpHeaderName IfUnmodifiedSince = {"If-Unmodified-Since:"};
|
|
84 const HttpHeaderName LastModified = {"Last-Modified:"};
|
|
85 const HttpHeaderName Location = {"Location:"};
|
|
86 const HttpHeaderName MaxForwards = {"Max-Forwards:"};
|
|
87 const HttpHeaderName MimeVersion = {"MIME-Version:"};
|
|
88 const HttpHeaderName Pragma = {"Pragma:"};
|
|
89 const HttpHeaderName ProxyAuthenticate = {"Proxy-Authenticate:"};
|
|
90 const HttpHeaderName ProxyConnection = {"Proxy-Connection:"};
|
|
91 const HttpHeaderName Range = {"Range:"};
|
|
92 const HttpHeaderName Referrer = {"Referer:"};
|
|
93 const HttpHeaderName RetryAfter = {"Retry-After:"};
|
|
94 const HttpHeaderName Server = {"Server:"};
|
|
95 const HttpHeaderName ServletEngine = {"Servlet-Engine:"};
|
|
96 const HttpHeaderName SetCookie = {"Set-Cookie:"};
|
|
97 const HttpHeaderName SetCookie2 = {"Set-Cookie2:"};
|
|
98 const HttpHeaderName TE = {"TE:"};
|
|
99 const HttpHeaderName Trailer = {"Trailer:"};
|
|
100 const HttpHeaderName TransferEncoding = {"Transfer-Encoding:"};
|
|
101 const HttpHeaderName Upgrade = {"Upgrade:"};
|
|
102 const HttpHeaderName UserAgent = {"User-Agent:"};
|
|
103 const HttpHeaderName Vary = {"Vary:"};
|
|
104 const HttpHeaderName Warning = {"Warning:"};
|
|
105 const HttpHeaderName WwwAuthenticate = {"WWW-Authenticate:"};
|
|
106 }
|
|
107
|
|
108
|
|
109 /*******************************************************************************
|
|
110
|
|
111 Declare the traditional set of HTTP response codes
|
|
112
|
|
113 *******************************************************************************/
|
|
114
|
|
115 enum HttpResponseCode
|
|
116 {
|
|
117 Continue = 100,
|
|
118 SwitchingProtocols = 101,
|
|
119 OK = 200,
|
|
120 Created = 201,
|
|
121 Accepted = 202,
|
|
122 NonAuthoritativeInformation = 203,
|
|
123 NoContent = 204,
|
|
124 ResetContent = 205,
|
|
125 PartialContent = 206,
|
|
126 MultipleChoices = 300,
|
|
127 MovedPermanently = 301,
|
|
128 MovedTemporarily = 302,
|
|
129 SeeOther = 303,
|
|
130 NotModified = 304,
|
|
131 UseProxy = 305,
|
|
132 TemporaryRedirect = 307,
|
|
133 BadRequest = 400,
|
|
134 Unauthorized = 401,
|
|
135 PaymentRequired = 402,
|
|
136 Forbidden = 403,
|
|
137 NotFound = 404,
|
|
138 MethodNotAllowed = 405,
|
|
139 NotAcceptable = 406,
|
|
140 ProxyAuthenticationRequired = 407,
|
|
141 RequestTimeout = 408,
|
|
142 Conflict = 409,
|
|
143 Gone = 410,
|
|
144 LengthRequired = 411,
|
|
145 PreconditionFailed = 412,
|
|
146 RequestEntityTooLarge = 413,
|
|
147 RequestURITooLarge = 414,
|
|
148 UnsupportedMediaType = 415,
|
|
149 RequestedRangeNotSatisfiable = 416,
|
|
150 ExpectationFailed = 417,
|
|
151 InternalServerError = 500,
|
|
152 NotImplemented = 501,
|
|
153 BadGateway = 502,
|
|
154 ServiceUnavailable = 503,
|
|
155 GatewayTimeout = 504,
|
|
156 VersionNotSupported = 505,
|
|
157 };
|
|
158
|
|
159 /*******************************************************************************
|
|
160
|
|
161 Status is a compound type, with a name and a code.
|
|
162
|
|
163 *******************************************************************************/
|
|
164
|
|
165 struct HttpStatus
|
|
166 {
|
|
167 final int code;
|
|
168 final char[] name;
|
|
169 }
|
|
170
|
|
171 /*******************************************************************************
|
|
172
|
|
173 Declare the traditional set of HTTP responses
|
|
174
|
|
175 *******************************************************************************/
|
|
176
|
|
177 struct HttpResponses
|
|
178 {
|
|
179 static HttpStatus Continue = {HttpResponseCode.Continue, "Continue"};
|
|
180 static HttpStatus SwitchingProtocols = {HttpResponseCode.SwitchingProtocols, "SwitchingProtocols"};
|
|
181 static HttpStatus OK = {HttpResponseCode.OK, "OK"};
|
|
182 static HttpStatus Created = {HttpResponseCode.Created, "Created"};
|
|
183 static HttpStatus Accepted = {HttpResponseCode.Accepted, "Accepted"};
|
|
184 static HttpStatus NonAuthoritativeInformation = {HttpResponseCode.NonAuthoritativeInformation, "NonAuthoritativeInformation"};
|
|
185 static HttpStatus NoContent = {HttpResponseCode.NoContent, "NoContent"};
|
|
186 static HttpStatus ResetContent = {HttpResponseCode.ResetContent, "ResetContent"};
|
|
187 static HttpStatus PartialContent = {HttpResponseCode.PartialContent, "PartialContent"};
|
|
188 static HttpStatus MultipleChoices = {HttpResponseCode.MultipleChoices, "MultipleChoices"};
|
|
189 static HttpStatus MovedPermanently = {HttpResponseCode.MovedPermanently, "MovedPermanently"};
|
|
190 static HttpStatus MovedTemporarily = {HttpResponseCode.MovedTemporarily, "MovedTemporarily"};
|
|
191 static HttpStatus SeeOther = {HttpResponseCode.SeeOther, "SeeOther"};
|
|
192 static HttpStatus NotModified = {HttpResponseCode.NotModified, "NotModified"};
|
|
193 static HttpStatus UseProxy = {HttpResponseCode.UseProxy, "UseProxy"};
|
|
194 static HttpStatus BadRequest = {HttpResponseCode.BadRequest, "BadRequest"};
|
|
195 static HttpStatus Unauthorized = {HttpResponseCode.Unauthorized, "Unauthorized"};
|
|
196 static HttpStatus PaymentRequired = {HttpResponseCode.PaymentRequired, "PaymentRequired"};
|
|
197 static HttpStatus Forbidden = {HttpResponseCode.Forbidden, "Forbidden"};
|
|
198 static HttpStatus NotFound = {HttpResponseCode.NotFound, "NotFound"};
|
|
199 static HttpStatus MethodNotAllowed = {HttpResponseCode.MethodNotAllowed, "MethodNotAllowed"};
|
|
200 static HttpStatus NotAcceptable = {HttpResponseCode.NotAcceptable, "NotAcceptable"};
|
|
201 static HttpStatus ProxyAuthenticationRequired = {HttpResponseCode.ProxyAuthenticationRequired, "ProxyAuthenticationRequired"};
|
|
202 static HttpStatus RequestTimeout = {HttpResponseCode.RequestTimeout, "RequestTimeout"};
|
|
203 static HttpStatus Conflict = {HttpResponseCode.Conflict, "Conflict"};
|
|
204 static HttpStatus Gone = {HttpResponseCode.Gone, "Gone"};
|
|
205 static HttpStatus LengthRequired = {HttpResponseCode.LengthRequired, "LengthRequired"};
|
|
206 static HttpStatus PreconditionFailed = {HttpResponseCode.PreconditionFailed, "PreconditionFailed"};
|
|
207 static HttpStatus RequestEntityTooLarge = {HttpResponseCode.RequestEntityTooLarge, "RequestEntityTooLarge"};
|
|
208 static HttpStatus RequestURITooLarge = {HttpResponseCode.RequestURITooLarge, "RequestURITooLarge"};
|
|
209 static HttpStatus UnsupportedMediaType = {HttpResponseCode.UnsupportedMediaType, "UnsupportedMediaType"};
|
|
210 static HttpStatus RequestedRangeNotSatisfiable = {HttpResponseCode.RequestedRangeNotSatisfiable, "RequestedRangeNotSatisfiable"};
|
|
211 static HttpStatus ExpectationFailed = {HttpResponseCode.ExpectationFailed, "ExpectationFailed"};
|
|
212 static HttpStatus InternalServerError = {HttpResponseCode.InternalServerError, "InternalServerError"};
|
|
213 static HttpStatus NotImplemented = {HttpResponseCode.NotImplemented, "NotImplemented"};
|
|
214 static HttpStatus BadGateway = {HttpResponseCode.BadGateway, "BadGateway"};
|
|
215 static HttpStatus ServiceUnavailable = {HttpResponseCode.ServiceUnavailable, "ServiceUnavailable"};
|
|
216 static HttpStatus GatewayTimeout = {HttpResponseCode.GatewayTimeout, "GatewayTimeout"};
|
|
217 static HttpStatus VersionNotSupported = {HttpResponseCode.VersionNotSupported, "VersionNotSupported"};
|
|
218 }
|