llhttpconstants.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * @file llhttpconstants.cpp
  3. * @brief Implementation of the HTTP request / response constant lookups
  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. #include "linden_common.h"
  33. #include "llhttpconstants.h"
  34. #include "lltimer.h"
  35. const std::string CONTEXT_HEADERS("headers");
  36. const std::string CONTEXT_PATH("path");
  37. const std::string CONTEXT_QUERY_STRING("query-string");
  38. const std::string CONTEXT_REQUEST("request");
  39. const std::string CONTEXT_RESPONSE("response");
  40. const std::string CONTEXT_VERB("verb");
  41. const std::string CONTEXT_WILDCARD("wildcard");
  42. const std::string CONTEXT_REMOTE_HOST("remote-host");
  43. const std::string CONTEXT_REMOTE_PORT("remote-port");
  44. const std::string CONTEXT_DEST_URI_SD_LABEL("dest_uri");
  45. const std::string CONTEXT_TRANSFERED_BYTES("transfered_bytes");
  46. // Outgoing headers. Do *not* use these to check incoming headers.
  47. // For incoming headers, use the lower-case headers, below.
  48. const std::string HTTP_OUT_HEADER_ACCEPT("Accept");
  49. const std::string HTTP_OUT_HEADER_ACCEPT_CHARSET("Accept-Charset");
  50. const std::string HTTP_OUT_HEADER_ACCEPT_ENCODING("Accept-Encoding");
  51. const std::string HTTP_OUT_HEADER_ACCEPT_LANGUAGE("Accept-Language");
  52. const std::string HTTP_OUT_HEADER_ACCEPT_RANGES("Accept-Ranges");
  53. const std::string HTTP_OUT_HEADER_AGE("Age");
  54. const std::string HTTP_OUT_HEADER_ALLOW("Allow");
  55. const std::string HTTP_OUT_HEADER_AUTHORIZATION("Authorization");
  56. const std::string HTTP_OUT_HEADER_CACHE_CONTROL("Cache-Control");
  57. const std::string HTTP_OUT_HEADER_CONNECTION("Connection");
  58. const std::string HTTP_OUT_HEADER_CONTENT_DESCRIPTION("Content-Description");
  59. const std::string HTTP_OUT_HEADER_CONTENT_ENCODING("Content-Encoding");
  60. const std::string HTTP_OUT_HEADER_CONTENT_ID("Content-ID");
  61. const std::string HTTP_OUT_HEADER_CONTENT_LANGUAGE("Content-Language");
  62. const std::string HTTP_OUT_HEADER_CONTENT_LENGTH("Content-Length");
  63. const std::string HTTP_OUT_HEADER_CONTENT_LOCATION("Content-Location");
  64. const std::string HTTP_OUT_HEADER_CONTENT_MD5("Content-MD5");
  65. const std::string HTTP_OUT_HEADER_CONTENT_RANGE("Content-Range");
  66. const std::string HTTP_OUT_HEADER_CONTENT_TRANSFER_ENCODING("Content-Transfer-Encoding");
  67. const std::string HTTP_OUT_HEADER_CONTENT_TYPE("Content-Type");
  68. const std::string HTTP_OUT_HEADER_COOKIE("Cookie");
  69. const std::string HTTP_OUT_HEADER_DATE("Date");
  70. const std::string HTTP_OUT_HEADER_DESTINATION("Destination");
  71. const std::string HTTP_OUT_HEADER_ETAG("ETag");
  72. const std::string HTTP_OUT_HEADER_EXPECT("Expect");
  73. const std::string HTTP_OUT_HEADER_EXPIRES("Expires");
  74. const std::string HTTP_OUT_HEADER_FROM("From");
  75. const std::string HTTP_OUT_HEADER_HOST("Host");
  76. const std::string HTTP_OUT_HEADER_IF_MATCH("If-Match");
  77. const std::string HTTP_OUT_HEADER_IF_MODIFIED_SINCE("If-Modified-Since");
  78. const std::string HTTP_OUT_HEADER_IF_NONE_MATCH("If-None-Match");
  79. const std::string HTTP_OUT_HEADER_IF_RANGE("If-Range");
  80. const std::string HTTP_OUT_HEADER_IF_UNMODIFIED_SINCE("If-Unmodified-Since");
  81. const std::string HTTP_OUT_HEADER_KEEP_ALIVE("Keep-Alive");
  82. const std::string HTTP_OUT_HEADER_LAST_MODIFIED("Last-Modified");
  83. const std::string HTTP_OUT_HEADER_LOCATION("Location");
  84. const std::string HTTP_OUT_HEADER_MAX_FORWARDS("Max-Forwards");
  85. const std::string HTTP_OUT_HEADER_MIME_VERSION("MIME-Version");
  86. const std::string HTTP_OUT_HEADER_PRAGMA("Pragma");
  87. const std::string HTTP_OUT_HEADER_PROXY_AUTHENTICATE("Proxy-Authenticate");
  88. const std::string HTTP_OUT_HEADER_PROXY_AUTHORIZATION("Proxy-Authorization");
  89. const std::string HTTP_OUT_HEADER_RANGE("Range");
  90. const std::string HTTP_OUT_HEADER_REFERER("Referer");
  91. const std::string HTTP_OUT_HEADER_RETRY_AFTER("Retry-After");
  92. const std::string HTTP_OUT_HEADER_SERVER("Server");
  93. const std::string HTTP_OUT_HEADER_SET_COOKIE("Set-Cookie");
  94. const std::string HTTP_OUT_HEADER_TE("TE");
  95. const std::string HTTP_OUT_HEADER_TRAILER("Trailer");
  96. const std::string HTTP_OUT_HEADER_TRANSFER_ENCODING("Transfer-Encoding");
  97. const std::string HTTP_OUT_HEADER_UPGRADE("Upgrade");
  98. const std::string HTTP_OUT_HEADER_USER_AGENT("User-Agent");
  99. const std::string HTTP_OUT_HEADER_VARY("Vary");
  100. const std::string HTTP_OUT_HEADER_VIA("Via");
  101. const std::string HTTP_OUT_HEADER_WARNING("Warning");
  102. const std::string HTTP_OUT_HEADER_WWW_AUTHENTICATE("WWW-Authenticate");
  103. // Incoming headers are normalized to lower-case.
  104. const std::string HTTP_IN_HEADER_ACCEPT_LANGUAGE("accept-language");
  105. const std::string HTTP_IN_HEADER_CACHE_CONTROL("cache-control");
  106. const std::string HTTP_IN_HEADER_CONTENT_LENGTH("content-length");
  107. const std::string HTTP_IN_HEADER_CONTENT_LOCATION("content-location");
  108. const std::string HTTP_IN_HEADER_CONTENT_TYPE("content-type");
  109. const std::string HTTP_IN_HEADER_HOST("host");
  110. const std::string HTTP_IN_HEADER_LOCATION("location");
  111. const std::string HTTP_IN_HEADER_RETRY_AFTER("retry-after");
  112. const std::string HTTP_IN_HEADER_SET_COOKIE("set-cookie");
  113. const std::string HTTP_IN_HEADER_USER_AGENT("user-agent");
  114. const std::string HTTP_IN_HEADER_X_FORWARDED_FOR("x-forwarded-for");
  115. const std::string HTTP_CONTENT_LLSD_XML("application/llsd+xml");
  116. const std::string HTTP_CONTENT_OCTET_STREAM("application/octet-stream");
  117. const std::string HTTP_CONTENT_VND_LL_MESH("application/vnd.ll.mesh");
  118. const std::string HTTP_CONTENT_XML("application/xml");
  119. const std::string HTTP_CONTENT_JSON("application/json");
  120. const std::string HTTP_CONTENT_TEXT_HTML("text/html");
  121. const std::string HTTP_CONTENT_TEXT_HTML_UTF8("text/html; charset=utf-8");
  122. const std::string HTTP_CONTENT_TEXT_PLAIN_UTF8("text/plain; charset=utf-8");
  123. const std::string HTTP_CONTENT_TEXT_LLSD("text/llsd");
  124. const std::string HTTP_CONTENT_TEXT_XML("text/xml");
  125. const std::string HTTP_CONTENT_TEXT_LSL("text/lsl");
  126. const std::string HTTP_CONTENT_TEXT_PLAIN("text/plain");
  127. const std::string HTTP_CONTENT_IMAGE_X_J2C("image/x-j2c");
  128. const std::string HTTP_CONTENT_IMAGE_J2C("image/j2c");
  129. const std::string HTTP_CONTENT_IMAGE_JPEG("image/jpeg");
  130. const std::string HTTP_CONTENT_IMAGE_PNG("image/png");
  131. const std::string HTTP_CONTENT_IMAGE_BMP("image/bmp");
  132. const std::string HTTP_NO_CACHE("no-cache");
  133. const std::string HTTP_NO_CACHE_CONTROL("no-cache, max-age=0");
  134. const std::string HTTP_VERB_INVALID("(invalid)");
  135. const std::string HTTP_VERB_HEAD("HEAD");
  136. const std::string HTTP_VERB_GET("GET");
  137. const std::string HTTP_VERB_PUT("PUT");
  138. const std::string HTTP_VERB_POST("POST");
  139. const std::string HTTP_VERB_DELETE("DELETE");
  140. const std::string HTTP_VERB_MOVE("MOVE");
  141. const std::string HTTP_VERB_OPTIONS("OPTIONS");
  142. const std::string HTTP_VERB_PATCH("PATCH");
  143. const std::string HTTP_VERB_COPY("COPY");
  144. const std::string& httpMethodAsVerb(EHTTPMethod method)
  145. {
  146. static const std::string VERBS[] =
  147. {
  148. HTTP_VERB_INVALID,
  149. HTTP_VERB_HEAD,
  150. HTTP_VERB_GET,
  151. HTTP_VERB_PUT,
  152. HTTP_VERB_POST,
  153. HTTP_VERB_DELETE,
  154. HTTP_VERB_MOVE,
  155. HTTP_VERB_OPTIONS,
  156. HTTP_VERB_PATCH,
  157. HTTP_VERB_COPY
  158. };
  159. if ((S32)method <= 0 || (S32)method >= HTTP_METHOD_COUNT)
  160. {
  161. return VERBS[0];
  162. }
  163. return VERBS[method];
  164. }