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