...

Source file src/gitlab.hexacode.org/go-libs/requests/status.go

Documentation: gitlab.hexacode.org/go-libs/requests

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

View as plain text