llhttpconstants.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /**
  2. * @file llhttpconstants.h
  3. * @brief Constants for HTTP requests and responses
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2013, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_HTTP_CONSTANTS_H
  33. #define LL_HTTP_CONSTANTS_H
  34. #include "llpreprocessor.h"
  35. /////// HTTP STATUS CODES ///////
  36. // Standard errors from HTTP spec:
  37. // http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1
  38. constexpr S32 HTTP_CONTINUE = 100;
  39. constexpr S32 HTTP_SWITCHING_PROTOCOLS = 101;
  40. // Success
  41. constexpr S32 HTTP_OK = 200;
  42. constexpr S32 HTTP_CREATED = 201;
  43. constexpr S32 HTTP_ACCEPTED = 202;
  44. constexpr S32 HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
  45. constexpr S32 HTTP_NO_CONTENT = 204;
  46. constexpr S32 HTTP_RESET_CONTENT = 205;
  47. constexpr S32 HTTP_PARTIAL_CONTENT = 206;
  48. // Redirection
  49. constexpr S32 HTTP_MULTIPLE_CHOICES = 300;
  50. constexpr S32 HTTP_MOVED_PERMANENTLY = 301;
  51. constexpr S32 HTTP_FOUND = 302;
  52. constexpr S32 HTTP_SEE_OTHER = 303;
  53. constexpr S32 HTTP_NOT_MODIFIED = 304;
  54. constexpr S32 HTTP_USE_PROXY = 305;
  55. constexpr S32 HTTP_TEMPORARY_REDIRECT = 307;
  56. // Client Error
  57. constexpr S32 HTTP_BAD_REQUEST = 400;
  58. constexpr S32 HTTP_UNAUTHORIZED = 401;
  59. constexpr S32 HTTP_PAYMENT_REQUIRED = 402;
  60. constexpr S32 HTTP_FORBIDDEN = 403;
  61. constexpr S32 HTTP_NOT_FOUND = 404;
  62. constexpr S32 HTTP_METHOD_NOT_ALLOWED = 405;
  63. constexpr S32 HTTP_NOT_ACCEPTABLE = 406;
  64. constexpr S32 HTTP_PROXY_AUTHENTICATION_REQUIRED = 407;
  65. constexpr S32 HTTP_REQUEST_TIME_OUT = 408;
  66. constexpr S32 HTTP_CONFLICT = 409;
  67. constexpr S32 HTTP_GONE = 410;
  68. constexpr S32 HTTP_LENGTH_REQUIRED = 411;
  69. constexpr S32 HTTP_PRECONDITION_FAILED = 412;
  70. constexpr S32 HTTP_REQUEST_ENTITY_TOO_LARGE = 413;
  71. constexpr S32 HTTP_REQUEST_URI_TOO_LARGE = 414;
  72. constexpr S32 HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
  73. constexpr S32 HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
  74. constexpr S32 HTTP_EXPECTATION_FAILED = 417;
  75. // Server Error
  76. constexpr S32 HTTP_INTERNAL_SERVER_ERROR = 500;
  77. constexpr S32 HTTP_NOT_IMPLEMENTED = 501;
  78. constexpr S32 HTTP_BAD_GATEWAY = 502;
  79. constexpr S32 HTTP_SERVICE_UNAVAILABLE = 503;
  80. constexpr S32 HTTP_GATEWAY_TIME_OUT = 504;
  81. constexpr S32 HTTP_VERSION_NOT_SUPPORTED = 505;
  82. // We combine internal process errors with status codes. These status codes
  83. // should not be sent over the wire and indicate something went wrong
  84. // internally. If you get these they are not normal.
  85. constexpr S32 HTTP_INTERNAL_CURL_ERROR = 498;
  86. constexpr S32 HTTP_INTERNAL_ERROR = 499;
  87. ////// HTTP Methods //////
  88. extern const std::string HTTP_VERB_INVALID;
  89. extern const std::string HTTP_VERB_HEAD;
  90. extern const std::string HTTP_VERB_GET;
  91. extern const std::string HTTP_VERB_PUT;
  92. extern const std::string HTTP_VERB_POST;
  93. extern const std::string HTTP_VERB_DELETE;
  94. extern const std::string HTTP_VERB_MOVE;
  95. extern const std::string HTTP_VERB_OPTIONS;
  96. extern const std::string HTTP_VERB_PATCH;
  97. extern const std::string HTTP_VERB_COPY;
  98. enum EHTTPMethod
  99. {
  100. HTTP_INVALID = 0,
  101. HTTP_HEAD,
  102. HTTP_GET,
  103. HTTP_PUT,
  104. HTTP_POST,
  105. HTTP_DELETE,
  106. HTTP_MOVE, // Caller will need to set 'Destination' header
  107. HTTP_OPTIONS,
  108. HTTP_PATCH,
  109. HTTP_COPY,
  110. HTTP_METHOD_COUNT
  111. };
  112. LL_INLINE bool isHttpInformationalStatus(S32 status)
  113. {
  114. // Check for status 1xx.
  115. return status >= 100 && status < 200;
  116. }
  117. LL_INLINE bool isHttpGoodStatus(S32 status)
  118. {
  119. // Check for status 2xx.
  120. return status >= 200 && status < 300;
  121. }
  122. LL_INLINE bool isHttpRedirectStatus(S32 status)
  123. {
  124. // Check for status 3xx.
  125. return status >= 300 && status < 400;
  126. }
  127. LL_INLINE bool isHttpClientErrorStatus(S32 status)
  128. {
  129. // Check for status 4xx.
  130. // Status 499 is sometimes used for re-interpreted status 2xx errors based
  131. // on body content. Treat these as potentially retryable 'server' status
  132. // errors, since we do not have enough context to know if this will always
  133. // fail.
  134. return status != 499 && status >= 400 && status < 500;
  135. }
  136. LL_INLINE bool isHttpServerErrorStatus(S32 status)
  137. {
  138. // Check for status 5xx.
  139. // Status 499 is sometimes used for re-interpreted status 2xx errors.
  140. // Allow retry of these, since we don't have enough information in this
  141. // context to know if this will always fail.
  142. return status == 499 || (status >= 500 && status < 600);
  143. }
  144. const std::string& httpMethodAsVerb(EHTTPMethod method);
  145. // Outgoing headers. Do *not* use these to check incoming headers.
  146. // For incoming headers, use the lower-case headers, below.
  147. extern const std::string HTTP_OUT_HEADER_ACCEPT;
  148. extern const std::string HTTP_OUT_HEADER_ACCEPT_CHARSET;
  149. extern const std::string HTTP_OUT_HEADER_ACCEPT_ENCODING;
  150. extern const std::string HTTP_OUT_HEADER_ACCEPT_LANGUAGE;
  151. extern const std::string HTTP_OUT_HEADER_ACCEPT_RANGES;
  152. extern const std::string HTTP_OUT_HEADER_AGE;
  153. extern const std::string HTTP_OUT_HEADER_ALLOW;
  154. extern const std::string HTTP_OUT_HEADER_AUTHORIZATION;
  155. extern const std::string HTTP_OUT_HEADER_CACHE_CONTROL;
  156. extern const std::string HTTP_OUT_HEADER_CONNECTION;
  157. extern const std::string HTTP_OUT_HEADER_CONTENT_DESCRIPTION;
  158. extern const std::string HTTP_OUT_HEADER_CONTENT_ENCODING;
  159. extern const std::string HTTP_OUT_HEADER_CONTENT_ID;
  160. extern const std::string HTTP_OUT_HEADER_CONTENT_LANGUAGE;
  161. extern const std::string HTTP_OUT_HEADER_CONTENT_LENGTH;
  162. extern const std::string HTTP_OUT_HEADER_CONTENT_LOCATION;
  163. extern const std::string HTTP_OUT_HEADER_CONTENT_MD5;
  164. extern const std::string HTTP_OUT_HEADER_CONTENT_RANGE;
  165. extern const std::string HTTP_OUT_HEADER_CONTENT_TRANSFER_ENCODING;
  166. extern const std::string HTTP_OUT_HEADER_CONTENT_TYPE;
  167. extern const std::string HTTP_OUT_HEADER_COOKIE;
  168. extern const std::string HTTP_OUT_HEADER_DATE;
  169. extern const std::string HTTP_OUT_HEADER_DESTINATION;
  170. extern const std::string HTTP_OUT_HEADER_ETAG;
  171. extern const std::string HTTP_OUT_HEADER_EXPECT;
  172. extern const std::string HTTP_OUT_HEADER_EXPIRES;
  173. extern const std::string HTTP_OUT_HEADER_FROM;
  174. extern const std::string HTTP_OUT_HEADER_HOST;
  175. extern const std::string HTTP_OUT_HEADER_IF_MATCH;
  176. extern const std::string HTTP_OUT_HEADER_IF_MODIFIED_SINCE;
  177. extern const std::string HTTP_OUT_HEADER_IF_NONE_MATCH;
  178. extern const std::string HTTP_OUT_HEADER_IF_RANGE;
  179. extern const std::string HTTP_OUT_HEADER_IF_UNMODIFIED_SINCE;
  180. extern const std::string HTTP_OUT_HEADER_KEEP_ALIVE;
  181. extern const std::string HTTP_OUT_HEADER_LAST_MODIFIED;
  182. extern const std::string HTTP_OUT_HEADER_LOCATION;
  183. extern const std::string HTTP_OUT_HEADER_MAX_FORWARDS;
  184. extern const std::string HTTP_OUT_HEADER_MIME_VERSION;
  185. extern const std::string HTTP_OUT_HEADER_PRAGMA;
  186. extern const std::string HTTP_OUT_HEADER_PROXY_AUTHENTICATE;
  187. extern const std::string HTTP_OUT_HEADER_PROXY_AUTHORIZATION;
  188. extern const std::string HTTP_OUT_HEADER_RANGE;
  189. extern const std::string HTTP_OUT_HEADER_REFERER;
  190. extern const std::string HTTP_OUT_HEADER_RETRY_AFTER;
  191. extern const std::string HTTP_OUT_HEADER_SERVER;
  192. extern const std::string HTTP_OUT_HEADER_SET_COOKIE;
  193. extern const std::string HTTP_OUT_HEADER_TE;
  194. extern const std::string HTTP_OUT_HEADER_TRAILER;
  195. extern const std::string HTTP_OUT_HEADER_TRANSFER_ENCODING;
  196. extern const std::string HTTP_OUT_HEADER_UPGRADE;
  197. extern const std::string HTTP_OUT_HEADER_USER_AGENT;
  198. extern const std::string HTTP_OUT_HEADER_VARY;
  199. extern const std::string HTTP_OUT_HEADER_VIA;
  200. extern const std::string HTTP_OUT_HEADER_WARNING;
  201. extern const std::string HTTP_OUT_HEADER_WWW_AUTHENTICATE;
  202. // Incoming headers are normalized to lower-case.
  203. extern const std::string HTTP_IN_HEADER_ACCEPT_LANGUAGE;
  204. extern const std::string HTTP_IN_HEADER_CACHE_CONTROL;
  205. extern const std::string HTTP_IN_HEADER_CONTENT_LENGTH;
  206. extern const std::string HTTP_IN_HEADER_CONTENT_LOCATION;
  207. extern const std::string HTTP_IN_HEADER_CONTENT_TYPE;
  208. extern const std::string HTTP_IN_HEADER_HOST;
  209. extern const std::string HTTP_IN_HEADER_LOCATION;
  210. extern const std::string HTTP_IN_HEADER_RETRY_AFTER;
  211. extern const std::string HTTP_IN_HEADER_SET_COOKIE;
  212. extern const std::string HTTP_IN_HEADER_USER_AGENT;
  213. extern const std::string HTTP_IN_HEADER_X_FORWARDED_FOR;
  214. //// HTTP Content Types ////
  215. extern const std::string HTTP_CONTENT_LLSD_XML;
  216. extern const std::string HTTP_CONTENT_OCTET_STREAM;
  217. extern const std::string HTTP_CONTENT_VND_LL_MESH;
  218. extern const std::string HTTP_CONTENT_XML;
  219. extern const std::string HTTP_CONTENT_JSON;
  220. extern const std::string HTTP_CONTENT_TEXT_HTML;
  221. extern const std::string HTTP_CONTENT_TEXT_HTML_UTF8;
  222. extern const std::string HTTP_CONTENT_TEXT_PLAIN_UTF8;
  223. extern const std::string HTTP_CONTENT_TEXT_LLSD;
  224. extern const std::string HTTP_CONTENT_TEXT_XML;
  225. extern const std::string HTTP_CONTENT_TEXT_LSL;
  226. extern const std::string HTTP_CONTENT_TEXT_PLAIN;
  227. extern const std::string HTTP_CONTENT_IMAGE_X_J2C;
  228. extern const std::string HTTP_CONTENT_IMAGE_J2C;
  229. extern const std::string HTTP_CONTENT_IMAGE_JPEG;
  230. extern const std::string HTTP_CONTENT_IMAGE_PNG;
  231. extern const std::string HTTP_CONTENT_IMAGE_BMP;
  232. //// HTTP Cache Settings ////
  233. extern const std::string HTTP_NO_CACHE;
  234. extern const std::string HTTP_NO_CACHE_CONTROL;
  235. // Common strings use for populating the context. bascally 'request',
  236. // 'wildcard', and 'headers'.
  237. extern const std::string CONTEXT_HEADERS;
  238. extern const std::string CONTEXT_PATH;
  239. extern const std::string CONTEXT_QUERY_STRING;
  240. extern const std::string CONTEXT_REQUEST;
  241. extern const std::string CONTEXT_RESPONSE;
  242. extern const std::string CONTEXT_VERB;
  243. extern const std::string CONTEXT_WILDCARD;
  244. extern const std::string CONTEXT_REMOTE_HOST;
  245. extern const std::string CONTEXT_REMOTE_PORT;
  246. extern const std::string CONTEXT_DEST_URI_SD_LABEL;
  247. extern const std::string CONTEXT_TRANSFERED_BYTES;
  248. #endif // LL_HTTP_CONSTANTS_H