Package rfc6585
Overview
Package rfc6585 builds the status codes added by RFC 6585 (Additional HTTP Status Codes) as rfc9110.Status values, so they work anywhere a status from package rfc9110 does:
rfc6585.TooManyRequests().WithRetryAfter(rfc9110.RetryAfterDelay(time.Minute))RFC 6585 says responses with these codes "MUST NOT be stored by a cache". That's a rule for caches, so the package doesn't add a Cache-Control field.
The RFC text is in rfc6585.txt in this directory, and the doc comments cite its sections.
Index
func NetworkAuthenticationRequiredfunc PreconditionRequiredfunc RequestHeaderFieldsTooLargefunc TooManyRequests
Functions
NetworkAuthenticationRequired source
func NetworkAuthenticationRequired() rfc9110.StatusNetworkAuthenticationRequired returns 511 Network Authentication Required: the client needs to authenticate to gain network access (Section 6). It's meant for intercepting proxies, and Section 6 says origin servers "SHOULD NOT" generate it.
PreconditionRequired source
func PreconditionRequired() rfc9110.StatusPreconditionRequired returns 428 Precondition Required: the server requires the request to be conditional (Section 3).
RequestHeaderFieldsTooLarge source
func RequestHeaderFieldsTooLarge() rfc9110.StatusRequestHeaderFieldsTooLarge returns 431 Request Header Fields Too Large: the server won't process the request because its header fields are too large (Section 5).
TooManyRequests source
func TooManyRequests() rfc9110.StatusTooManyRequests returns 429 Too Many Requests: the client has sent too many
requests in a given time (Section 4). Section 4 says the response "MAY
include a Retry-After header", so add one with
rfc9110.Status.WithRetryAfter when you know how long the client should
wait. ExampleTooManyRequests shows a 429 telling the client to retry in an hour,
which RFC 6585, Section 4, allows with Retry-After. Output:Example
package main
import (
"fmt"
"time"
"funnyhaha.technology/rfc/rfc6585"
"funnyhaha.technology/rfc/rfc9110"
)
func main() {
s := rfc6585.TooManyRequests().WithRetryAfter(rfc9110.RetryAfterDelay(time.Hour))
fmt.Println(s.Code(), s.Header().Get("Retry-After"))
}
429 3600