PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Ximura/Helper/Common/Common_HTTP.cs

https://github.com/mbmccormick/Ximura
C# | 239 lines | 82 code | 8 blank | 149 comment | 1 complexity | b49761fb4f3db9cd65238687f87a072d MD5 | raw file
  1. #region Copyright
  2. // *******************************************************************************
  3. // Copyright (c) 2000-2009 Paul Stancer.
  4. // All rights reserved. This program and the accompanying materials
  5. // are made available under the terms of the Eclipse Public License v1.0
  6. // which accompanies this distribution, and is available at
  7. // http://www.eclipse.org/legal/epl-v10.html
  8. //
  9. // Contributors:
  10. // Paul Stancer - initial implementation
  11. // *******************************************************************************
  12. #endregion
  13. #region using
  14. using System;
  15. using System.Text;
  16. using System.IO;
  17. using System.Security;
  18. using System.Reflection;
  19. using System.ComponentModel;
  20. using System.Collections;
  21. using System.Collections.Generic;
  22. using System.Diagnostics;
  23. using System.Globalization;
  24. using System.Runtime.CompilerServices;
  25. using System.Security.Cryptography;
  26. using System.Threading;
  27. using Ximura;
  28. #endregion // using
  29. namespace Ximura
  30. {
  31. /// <summary>
  32. /// The <b>Common</b> class includes a number of useful utilities.
  33. /// </summary>
  34. public static partial class Common
  35. {
  36. #region HTTP Codes
  37. /// <summary>
  38. /// This class provides shortcuts to the HTTP codes.
  39. /// </summary>
  40. public class HTTPCodes
  41. {
  42. /// <summary>
  43. /// 100: Continue
  44. /// </summary>
  45. public static string Continue_100 { get { return "100"; } }
  46. /// <summary>
  47. /// 101: Switching Protocols
  48. /// </summary>
  49. public static string SwitchingProtocols_101 { get { return "101"; } }
  50. /// <summary>
  51. /// 200: OK
  52. /// </summary>
  53. public static string OK_200 { get { return "200"; } }
  54. /// <summary>
  55. /// 201: Created
  56. /// </summary>
  57. public static string Created_201 { get { return "201"; } }
  58. /// <summary>
  59. /// 202: Accepted
  60. /// </summary>
  61. public static string Accepted_202 { get { return "202"; } }
  62. /// <summary>
  63. /// 203: Non Authoritative
  64. /// </summary>
  65. public static string NonAuthoritative_203 { get { return "203"; } }
  66. /// <summary>
  67. /// 204: No Content
  68. /// </summary>
  69. public static string NoContent_204 { get { return "204"; } }
  70. /// <summary>
  71. /// 205: Reset Content
  72. /// </summary>
  73. public static string ResetContent_205 { get { return "205"; } }
  74. /// <summary>
  75. /// 206: Partial Content
  76. /// </summary>
  77. public static string PartialContent_206 { get { return "206"; } }
  78. /// <summary>
  79. /// 300: Multiple Choices
  80. /// </summary>
  81. public static string MultipleChoices_300 { get { return "300"; } }
  82. /// <summary>
  83. /// 301: Moved Permanently
  84. /// </summary>
  85. public static string MovedPermanently_301 { get { return "301"; } }
  86. /// <summary>
  87. /// 302: Found
  88. /// </summary>
  89. public static string Found_302 { get { return "302"; } }
  90. /// <summary>
  91. /// 303: See Other
  92. /// </summary>
  93. public static string SeeOther_303 { get { return "303"; } }
  94. /// <summary>
  95. /// 304: Not Modified
  96. /// </summary>
  97. public static string NotModified_304 { get { return "304"; } }
  98. /// <summary>
  99. /// 305: Use Proxy
  100. /// </summary>
  101. public static string UseProxy_305 { get { return "305"; } }
  102. /// <summary>
  103. /// 306: Redirection Command Not Used
  104. /// </summary>
  105. public static string ReDirectionCommandNotUsed_306 { get { return "306"; } }
  106. /// <summary>
  107. /// 307: Moved Temporarily
  108. /// </summary>
  109. public static string MovedTemporarily_307 { get { return "307"; } }
  110. /// <summary>
  111. /// 400: Bad Request
  112. /// </summary>
  113. public static string BadRequest_400 { get { return "400"; } }
  114. /// <summary>
  115. /// 401: Unauthorized
  116. /// </summary>
  117. public static string Unauthorized_401 { get { return "401"; } }
  118. /// <summary>
  119. /// 402: Payment Required
  120. /// </summary>
  121. public static string PaymentRequired_402 { get { return "402"; } }
  122. /// <summary>
  123. /// 403: Forbidden
  124. /// </summary>
  125. public static string Forbidden_403 { get { return "403"; } }
  126. /// <summary>
  127. /// 404: Not Found
  128. /// </summary>
  129. public static string NotFound_404 { get { return "404"; } }
  130. /// <summary>
  131. /// 405: Method Not Allowed
  132. /// </summary>
  133. public static string MethodNotAllowed_405 { get { return "405"; } }
  134. /// <summary>
  135. /// 406: Not Acceptable
  136. /// </summary>
  137. public static string NotAcceptable_406 { get { return "406"; } }
  138. /// <summary>
  139. /// 407: Proxy Authentication Required
  140. /// </summary>
  141. public static string ProxyAuthenticationRequired_407 { get { return "407"; } }
  142. /// <summary>
  143. /// 408: Request Timeout
  144. /// </summary>
  145. public static string RequestTimeout_408 { get { return "408"; } }
  146. /// <summary>
  147. /// 409: Conflict
  148. /// </summary>
  149. public static string Conflict_409 { get { return "409"; } }
  150. /// <summary>
  151. /// 410: Gone
  152. /// </summary>
  153. public static string Gone_410 { get { return "410"; } }
  154. /// <summary>
  155. /// 411: Length Required
  156. /// </summary>
  157. public static string LengthRequired_411 { get { return "411"; } }
  158. /// <summary>
  159. /// 412: Precondition Failed
  160. /// </summary>
  161. public static string PreconditionFailed_412 { get { return "412"; } }
  162. /// <summary>
  163. /// 413: Request Entity Too Large
  164. /// </summary>
  165. public static string RequestEntityTooLarge_413 { get { return "413"; } }
  166. /// <summary>
  167. /// 414: Request URI Too Long
  168. /// </summary>
  169. public static string RequestURITooLong_414 { get { return "414"; } }
  170. /// <summary>
  171. /// 415: Unsupported Media Type
  172. /// </summary>
  173. public static string UnsupportedMediaType_415 { get { return "415"; } }
  174. /// <summary>
  175. /// 416: Requested Range Not Satisfiable
  176. /// </summary>
  177. public static string RequestedRangeNotSatisfiable_416 { get { return "416"; } }
  178. /// <summary>
  179. /// 417: Expectation Failed
  180. /// </summary>
  181. public static string ExpectationFailed_417 { get { return "417"; } }
  182. /// <summary>
  183. /// 500: Internal Server Error
  184. /// </summary>
  185. public static string InternalServerError_500 { get { return "500"; } }
  186. /// <summary>
  187. /// 501: Not Implemented
  188. /// </summary>
  189. public static string NotImplemented_501 { get { return "501"; } }
  190. /// <summary>
  191. /// 502: Bad Gateway
  192. /// </summary>
  193. public static string BadGateway_502 { get { return "502"; } }
  194. /// <summary>
  195. /// 503: Service Unavailable
  196. /// </summary>
  197. public static string ServiceUnavailable_503 { get { return "503"; } }
  198. /// <summary>
  199. /// 504: Gateway Timeout
  200. /// </summary>
  201. public static string GatewayTimeout_504 { get { return "504"; } }
  202. /// <summary>
  203. /// 505: Version No tSupported
  204. /// </summary>
  205. public static string VersionNotSupported_505 { get { return "505"; } }
  206. #region IsHTTPError(string status)
  207. /// <summary>
  208. /// This method returns true if the status is an HTTP error.
  209. /// </summary>
  210. /// <param name="status">The status to check.</param>
  211. /// <returns>Returns true if the status code denotes an error.</returns>
  212. public static bool IsHTTPError(string status)
  213. {
  214. return IsServerError(status) || status.StartsWith("4", true, CultureInfo.InvariantCulture);
  215. }
  216. #endregion // IsHTTPError(string status)
  217. #region IsServerError(string status)
  218. /// <summary>
  219. /// This method returns true if the status code is an error.
  220. /// </summary>
  221. /// <param name="status">The status to check.</param>
  222. /// <returns>Returns true if the status code denotes an error.</returns>
  223. public static bool IsServerError(string status)
  224. {
  225. return status.StartsWith("5", true, CultureInfo.InvariantCulture);
  226. }
  227. #endregion // IsServerError(string status)
  228. }
  229. #endregion
  230. }
  231. }