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         enum 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         const(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         enum int IOBufferSize                 = 16 * 1024;
48 
49         // maximum length for POST parameters (to avoid DOS ...)
50         enum int MaxPostParamSize             = 4 * 1024;
51 
52         enum HttpHeaderName Version           = {"HTTP/1.1"};
53         enum HttpHeaderName TextHtml          = {"text/html"};
54 
55         enum HttpHeaderName Accept            = {"Accept:"};
56         enum HttpHeaderName AcceptCharset     = {"Accept-Charset:"};
57         enum HttpHeaderName AcceptEncoding    = {"Accept-Encoding:"};
58         enum HttpHeaderName AcceptLanguage    = {"Accept-Language:"};
59         enum HttpHeaderName AcceptRanges      = {"Accept-Ranges:"};
60         enum HttpHeaderName Age               = {"Age:"};
61         enum HttpHeaderName Allow             = {"Allow:"};
62         enum HttpHeaderName Authorization     = {"Authorization:"};
63         enum HttpHeaderName CacheControl      = {"Cache-Control:"};
64         enum HttpHeaderName Connection        = {"Connection:"};
65         enum HttpHeaderName ContentEncoding   = {"Content-Encoding:"};
66         enum HttpHeaderName ContentLanguage   = {"Content-Language:"};
67         enum HttpHeaderName ContentLength     = {"Content-Length:"};
68         enum HttpHeaderName ContentLocation   = {"Content-Location:"};
69         enum HttpHeaderName ContentRange      = {"Content-Range:"};
70         enum HttpHeaderName ContentType       = {"Content-Type:"};
71         enum HttpHeaderName Cookie            = {"Cookie:"};
72         enum HttpHeaderName Date              = {"Date:"};
73         enum HttpHeaderName ETag              = {"ETag:"};
74         enum HttpHeaderName Expect            = {"Expect:"};
75         enum HttpHeaderName Expires           = {"Expires:"};
76         enum HttpHeaderName From              = {"From:"};
77         enum HttpHeaderName Host              = {"Host:"};
78         enum HttpHeaderName Identity          = {"Identity:"};
79         enum HttpHeaderName IfMatch           = {"If-Match:"};
80         enum HttpHeaderName IfModifiedSince   = {"If-Modified-Since:"};
81         enum HttpHeaderName IfNoneMatch       = {"If-None-Match:"};
82         enum HttpHeaderName IfRange           = {"If-Range:"};
83         enum HttpHeaderName IfUnmodifiedSince = {"If-Unmodified-Since:"};
84         enum HttpHeaderName KeepAlive         = {"Keep-Alive:"};
85         enum HttpHeaderName LastModified      = {"Last-Modified:"};
86         enum HttpHeaderName Location          = {"Location:"};
87         enum HttpHeaderName MaxForwards       = {"Max-Forwards:"};
88         enum HttpHeaderName MimeVersion       = {"MIME-Version:"};
89         enum HttpHeaderName Pragma            = {"Pragma:"};
90         enum HttpHeaderName ProxyAuthenticate = {"Proxy-Authenticate:"};
91         enum HttpHeaderName ProxyConnection   = {"Proxy-Connection:"};
92         enum HttpHeaderName Range             = {"Range:"};
93         enum HttpHeaderName Referrer          = {"Referer:"};
94         enum HttpHeaderName RetryAfter        = {"Retry-After:"};
95         enum HttpHeaderName Server            = {"Server:"};
96         enum HttpHeaderName ServletEngine     = {"Servlet-Engine:"};
97         enum HttpHeaderName SetCookie         = {"Set-Cookie:"};
98         enum HttpHeaderName SetCookie2        = {"Set-Cookie2:"};
99         enum HttpHeaderName TE                = {"TE:"};
100         enum HttpHeaderName Trailer           = {"Trailer:"};
101         enum HttpHeaderName TransferEncoding  = {"Transfer-Encoding:"};
102         enum HttpHeaderName Upgrade           = {"Upgrade:"};
103         enum HttpHeaderName UserAgent         = {"User-Agent:"};
104         enum HttpHeaderName Vary              = {"Vary:"};
105         enum HttpHeaderName Warning           = {"Warning:"};
106         enum HttpHeaderName WwwAuthenticate   = {"WWW-Authenticate:"};
107 }
108 
109 
110 /*******************************************************************************
111 
112         Declare the traditional set of HTTP response codes
113 
114 *******************************************************************************/
115 
116 enum HttpResponseCode
117 {       
118         Continue                     = 100,
119         SwitchingProtocols           = 101,
120         OK                           = 200,
121         Created                      = 201,
122         Accepted                     = 202,
123         NonAuthoritativeInformation  = 203,
124         NoContent                    = 204,
125         ResetContent                 = 205,
126         PartialContent               = 206,
127         MultipleChoices              = 300,
128         MovedPermanently             = 301,
129         Found                        = 302,
130         SeeOther                     = 303,
131         NotModified                  = 304,
132         UseProxy                     = 305,
133         TemporaryRedirect            = 307,
134         BadRequest                   = 400,
135         Unauthorized                 = 401,
136         PaymentRequired              = 402,
137         Forbidden                    = 403,
138         NotFound                     = 404,
139         MethodNotAllowed             = 405,
140         NotAcceptable                = 406,
141         ProxyAuthenticationRequired  = 407,
142         RequestTimeout               = 408,
143         Conflict                     = 409,
144         Gone                         = 410,
145         LengthRequired               = 411,
146         PreconditionFailed           = 412,
147         RequestEntityTooLarge        = 413,
148         RequestURITooLarge           = 414,
149         UnsupportedMediaType         = 415,
150         RequestedRangeNotSatisfiable = 416,
151         ExpectationFailed            = 417,
152         InternalServerError          = 500,
153         NotImplemented               = 501,
154         BadGateway                   = 502,
155         ServiceUnavailable           = 503,
156         GatewayTimeout               = 504,
157         VersionNotSupported          = 505,
158 }
159 
160 /*******************************************************************************
161 
162         Status is a compound type, with a name and a code.
163 
164 *******************************************************************************/
165 
166 struct HttpStatus
167 {
168         int     code; 
169         const(char)[]  name;  
170 }
171 
172 /*******************************************************************************
173 
174         Declare the traditional set of HTTP responses
175 
176 *******************************************************************************/
177 
178 struct HttpResponses
179 {       
180     enum 
181     {
182         HttpStatus Continue          = HttpStatus(HttpResponseCode.Continue, "Continue"),
183         SwitchingProtocols           = HttpStatus(HttpResponseCode.SwitchingProtocols, "SwitchingProtocols"),
184         OK                           = HttpStatus(HttpResponseCode.OK, "OK"),
185         Created                      = HttpStatus(HttpResponseCode.Created, "Created"),
186         Accepted                     = HttpStatus(HttpResponseCode.Accepted, "Accepted"),
187         NonAuthoritativeInformation  = HttpStatus(HttpResponseCode.NonAuthoritativeInformation, "NonAuthoritativeInformation"),
188         NoContent                    = HttpStatus(HttpResponseCode.NoContent, "NoContent"),
189         ResetContent                 = HttpStatus(HttpResponseCode.ResetContent, "ResetContent"),
190         PartialContent               = HttpStatus(HttpResponseCode.PartialContent, "PartialContent"),
191         MultipleChoices              = HttpStatus(HttpResponseCode.MultipleChoices, "MultipleChoices"),
192         MovedPermanently             = HttpStatus(HttpResponseCode.MovedPermanently, "MovedPermanently"),
193         Found                        = HttpStatus(HttpResponseCode.Found, "Found"),
194         TemporaryRedirect            = HttpStatus(HttpResponseCode.TemporaryRedirect, "TemporaryRedirect"),
195         SeeOther                     = HttpStatus(HttpResponseCode.SeeOther, "SeeOther"),
196         NotModified                  = HttpStatus(HttpResponseCode.NotModified, "NotModified"),
197         UseProxy                     = HttpStatus(HttpResponseCode.UseProxy, "UseProxy"),
198         BadRequest                   = HttpStatus(HttpResponseCode.BadRequest, "BadRequest"),
199         Unauthorized                 = HttpStatus(HttpResponseCode.Unauthorized, "Unauthorized"),
200         PaymentRequired              = HttpStatus(HttpResponseCode.PaymentRequired, "PaymentRequired"),
201         Forbidden                    = HttpStatus(HttpResponseCode.Forbidden, "Forbidden"),
202         NotFound                     = HttpStatus(HttpResponseCode.NotFound, "NotFound"),
203         MethodNotAllowed             = HttpStatus(HttpResponseCode.MethodNotAllowed, "MethodNotAllowed"),
204         NotAcceptable                = HttpStatus(HttpResponseCode.NotAcceptable, "NotAcceptable"),
205         ProxyAuthenticationRequired  = HttpStatus(HttpResponseCode.ProxyAuthenticationRequired, "ProxyAuthenticationRequired"),
206         RequestTimeout               = HttpStatus(HttpResponseCode.RequestTimeout, "RequestTimeout"),
207         Conflict                     = HttpStatus(HttpResponseCode.Conflict, "Conflict"),
208         Gone                         = HttpStatus(HttpResponseCode.Gone, "Gone"),
209         LengthRequired               = HttpStatus(HttpResponseCode.LengthRequired, "LengthRequired"),
210         PreconditionFailed           = HttpStatus(HttpResponseCode.PreconditionFailed, "PreconditionFailed"),
211         RequestEntityTooLarge        = HttpStatus(HttpResponseCode.RequestEntityTooLarge, "RequestEntityTooLarge"),
212         RequestURITooLarge           = HttpStatus(HttpResponseCode.RequestURITooLarge, "RequestURITooLarge"),
213         UnsupportedMediaType         = HttpStatus(HttpResponseCode.UnsupportedMediaType, "UnsupportedMediaType"),
214         RequestedRangeNotSatisfiable = HttpStatus(HttpResponseCode.RequestedRangeNotSatisfiable, "RequestedRangeNotSatisfiable"),
215         ExpectationFailed            = HttpStatus(HttpResponseCode.ExpectationFailed, "ExpectationFailed"),
216         InternalServerError          = HttpStatus(HttpResponseCode.InternalServerError, "InternalServerError"),
217         NotImplemented               = HttpStatus(HttpResponseCode.NotImplemented, "NotImplemented"),
218         BadGateway                   = HttpStatus(HttpResponseCode.BadGateway, "BadGateway"),
219         ServiceUnavailable           = HttpStatus(HttpResponseCode.ServiceUnavailable, "ServiceUnavailable"),
220         GatewayTimeout               = HttpStatus(HttpResponseCode.GatewayTimeout, "GatewayTimeout"),
221         VersionNotSupported          = HttpStatus(HttpResponseCode.VersionNotSupported, "VersionNotSupported"),
222     }
223 }