const.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package yu_http
  2. const (
  3. ContentTypeFormUrlencoded = "application/x-www-form-urlencoded" // 原生Form表单
  4. ContentTypeFormData = "multipart/form-data" // 另一个常见的POST数据提交的方式,它会将表单的数据处理为一条消息,以标签为单元,用分隔符(这就是boundary的作用)分开
  5. ContentTypeJson = "application/json" // 用来告诉服务端消息主体是序列化后的JSON字符串
  6. )
  7. type Status int16
  8. // HTTP status codes as registered with IANA.
  9. // See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
  10. const (
  11. StatusContinue Status = 100 // RFC 9110, 15.2.1
  12. StatusSwitchingProtocols Status = 101 // RFC 9110, 15.2.2
  13. StatusProcessing Status = 102 // RFC 2518, 10.1
  14. StatusEarlyHints Status = 103 // RFC 8297
  15. StatusOK Status = 200 // RFC 9110, 15.3.1
  16. StatusCreated Status = 201 // RFC 9110, 15.3.2
  17. StatusAccepted Status = 202 // RFC 9110, 15.3.3
  18. StatusNonAuthoritativeInfo Status = 203 // RFC 9110, 15.3.4
  19. StatusNoContent Status = 204 // RFC 9110, 15.3.5
  20. StatusResetContent Status = 205 // RFC 9110, 15.3.6
  21. StatusPartialContent Status = 206 // RFC 9110, 15.3.7
  22. StatusMultiStatus Status = 207 // RFC 4918, 11.1
  23. StatusAlreadyReported Status = 208 // RFC 5842, 7.1
  24. StatusIMUsed Status = 226 // RFC 3229, 10.4.1
  25. StatusMultipleChoices Status = 300 // RFC 9110, 15.4.1
  26. StatusMovedPermanently Status = 301 // RFC 9110, 15.4.2
  27. StatusFound Status = 302 // RFC 9110, 15.4.3
  28. StatusSeeOther Status = 303 // RFC 9110, 15.4.4
  29. StatusNotModified Status = 304 // RFC 9110, 15.4.5
  30. StatusUseProxy Status = 305 // RFC 9110, 15.4.6
  31. _ Status = 306 // RFC 9110, 15.4.7 (Unused)
  32. StatusTemporaryRedirect Status = 307 // RFC 9110, 15.4.8
  33. StatusPermanentRedirect Status = 308 // RFC 9110, 15.4.9
  34. StatusBadRequest Status = 400 // RFC 9110, 15.5.1
  35. StatusUnauthorized Status = 401 // RFC 9110, 15.5.2
  36. StatusPaymentRequired Status = 402 // RFC 9110, 15.5.3
  37. StatusForbidden Status = 403 // RFC 9110, 15.5.4
  38. StatusNotFound Status = 404 // RFC 9110, 15.5.5
  39. StatusMethodNotAllowed Status = 405 // RFC 9110, 15.5.6
  40. StatusNotAcceptable Status = 406 // RFC 9110, 15.5.7
  41. StatusProxyAuthRequired Status = 407 // RFC 9110, 15.5.8
  42. StatusRequestTimeout Status = 408 // RFC 9110, 15.5.9
  43. StatusConflict Status = 409 // RFC 9110, 15.5.10
  44. StatusGone Status = 410 // RFC 9110, 15.5.11
  45. StatusLengthRequired Status = 411 // RFC 9110, 15.5.12
  46. StatusPreconditionFailed Status = 412 // RFC 9110, 15.5.13
  47. StatusRequestEntityTooLarge Status = 413 // RFC 9110, 15.5.14
  48. StatusRequestURITooLong Status = 414 // RFC 9110, 15.5.15
  49. StatusUnsupportedMediaType Status = 415 // RFC 9110, 15.5.16
  50. StatusRequestedRangeNotSatisfiable Status = 416 // RFC 9110, 15.5.17
  51. StatusExpectationFailed Status = 417 // RFC 9110, 15.5.18
  52. StatusTeapot Status = 418 // RFC 9110, 15.5.19 (Unused)
  53. StatusMisdirectedRequest Status = 421 // RFC 9110, 15.5.20
  54. StatusUnprocessableEntity Status = 422 // RFC 9110, 15.5.21
  55. StatusLocked Status = 423 // RFC 4918, 11.3
  56. StatusFailedDependency Status = 424 // RFC 4918, 11.4
  57. StatusTooEarly Status = 425 // RFC 8470, 5.2.
  58. StatusUpgradeRequired Status = 426 // RFC 9110, 15.5.22
  59. StatusPreconditionRequired Status = 428 // RFC 6585, 3
  60. StatusTooManyRequests Status = 429 // RFC 6585, 4
  61. StatusRequestHeaderFieldsTooLarge Status = 431 // RFC 6585, 5
  62. StatusUnavailableForLegalReasons Status = 451 // RFC 7725, 3
  63. StatusInternalServerError Status = 500 // RFC 9110, 15.6.1
  64. StatusNotImplemented Status = 501 // RFC 9110, 15.6.2
  65. StatusBadGateway Status = 502 // RFC 9110, 15.6.3
  66. StatusServiceUnavailable Status = 503 // RFC 9110, 15.6.4
  67. StatusGatewayTimeout Status = 504 // RFC 9110, 15.6.5
  68. StatusHTTPVersionNotSupported Status = 505 // RFC 9110, 15.6.6
  69. StatusVariantAlsoNegotiates Status = 506 // RFC 2295, 8.1
  70. StatusInsufficientStorage Status = 507 // RFC 4918, 11.5
  71. StatusLoopDetected Status = 508 // RFC 5842, 7.2
  72. StatusNotExtended Status = 510 // RFC 2774, 7
  73. StatusNetworkAuthenticationRequired Status = 511 // RFC 6585, 6
  74. )
  75. // StatusText
  76. //
  77. // @Description: 返回HTTP状态代码的文本。如果代码未知,它返回空的字符串。
  78. func StatusText(code Status) string {
  79. switch code {
  80. case StatusContinue:
  81. return "Continue"
  82. case StatusSwitchingProtocols:
  83. return "Switching Protocols"
  84. case StatusProcessing:
  85. return "Processing"
  86. case StatusEarlyHints:
  87. return "Early Hints"
  88. case StatusOK:
  89. return "OK"
  90. case StatusCreated:
  91. return "Created"
  92. case StatusAccepted:
  93. return "Accepted"
  94. case StatusNonAuthoritativeInfo:
  95. return "Non-Authoritative Information"
  96. case StatusNoContent:
  97. return "No Content"
  98. case StatusResetContent:
  99. return "Reset Content"
  100. case StatusPartialContent:
  101. return "Partial Content"
  102. case StatusMultiStatus:
  103. return "Multi-Status"
  104. case StatusAlreadyReported:
  105. return "Already Reported"
  106. case StatusIMUsed:
  107. return "IM Used"
  108. case StatusMultipleChoices:
  109. return "Multiple Choices"
  110. case StatusMovedPermanently:
  111. return "Moved Permanently"
  112. case StatusFound:
  113. return "Found"
  114. case StatusSeeOther:
  115. return "See Other"
  116. case StatusNotModified:
  117. return "Not Modified"
  118. case StatusUseProxy:
  119. return "Use Proxy"
  120. case StatusTemporaryRedirect:
  121. return "Temporary Redirect"
  122. case StatusPermanentRedirect:
  123. return "Permanent Redirect"
  124. case StatusBadRequest:
  125. return "Bad Request"
  126. case StatusUnauthorized:
  127. return "Unauthorized"
  128. case StatusPaymentRequired:
  129. return "Payment Required"
  130. case StatusForbidden:
  131. return "Forbidden"
  132. case StatusNotFound:
  133. return "Not Found"
  134. case StatusMethodNotAllowed:
  135. return "Method Not Allowed"
  136. case StatusNotAcceptable:
  137. return "Not Acceptable"
  138. case StatusProxyAuthRequired:
  139. return "Proxy Authentication Required"
  140. case StatusRequestTimeout:
  141. return "Request Timeout"
  142. case StatusConflict:
  143. return "Conflict"
  144. case StatusGone:
  145. return "Gone"
  146. case StatusLengthRequired:
  147. return "Length Required"
  148. case StatusPreconditionFailed:
  149. return "Precondition Failed"
  150. case StatusRequestEntityTooLarge:
  151. return "Request Entity Too Large"
  152. case StatusRequestURITooLong:
  153. return "Request URI Too Long"
  154. case StatusUnsupportedMediaType:
  155. return "Unsupported Media Type"
  156. case StatusRequestedRangeNotSatisfiable:
  157. return "Requested Range Not Satisfiable"
  158. case StatusExpectationFailed:
  159. return "Expectation Failed"
  160. case StatusTeapot:
  161. return "I'm a teapot"
  162. case StatusMisdirectedRequest:
  163. return "Misdirected Request"
  164. case StatusUnprocessableEntity:
  165. return "Unprocessable Entity"
  166. case StatusLocked:
  167. return "Locked"
  168. case StatusFailedDependency:
  169. return "Failed Dependency"
  170. case StatusTooEarly:
  171. return "Too Early"
  172. case StatusUpgradeRequired:
  173. return "Upgrade Required"
  174. case StatusPreconditionRequired:
  175. return "Precondition Required"
  176. case StatusTooManyRequests:
  177. return "Too Many Requests"
  178. case StatusRequestHeaderFieldsTooLarge:
  179. return "Request Header Fields Too Large"
  180. case StatusUnavailableForLegalReasons:
  181. return "Unavailable For Legal Reasons"
  182. case StatusInternalServerError:
  183. return "Internal Server Error"
  184. case StatusNotImplemented:
  185. return "Not Implemented"
  186. case StatusBadGateway:
  187. return "Bad Gateway"
  188. case StatusServiceUnavailable:
  189. return "Service Unavailable"
  190. case StatusGatewayTimeout:
  191. return "Gateway Timeout"
  192. case StatusHTTPVersionNotSupported:
  193. return "HTTP Version Not Supported"
  194. case StatusVariantAlsoNegotiates:
  195. return "Variant Also Negotiates"
  196. case StatusInsufficientStorage:
  197. return "Insufficient Storage"
  198. case StatusLoopDetected:
  199. return "Loop Detected"
  200. case StatusNotExtended:
  201. return "Not Extended"
  202. case StatusNetworkAuthenticationRequired:
  203. return "Network Authentication Required"
  204. default:
  205. return ""
  206. }
  207. }