package reqimport ()// Given a string of the form "host", "host:port", or "[ipv6::address]:port",// return true if the string includes a port.func hasPort( string) bool { returnstrings.LastIndex(, ":") > strings.LastIndex(, "]") }// removeEmptyPort strips the empty port in ":port" to ""// as mandated by RFC 3986 Section 6.2.3.func removeEmptyPort( string) string {ifhasPort() {returnstrings.TrimSuffix(, ":") }return}func isNotToken( rune) bool {return !httpguts.IsTokenRune()}func validMethod( string) bool {/* Method = "OPTIONS" ; Section 9.2 | "GET" ; Section 9.3 | "HEAD" ; Section 9.4 | "POST" ; Section 9.5 | "PUT" ; Section 9.6 | "DELETE" ; Section 9.7 | "TRACE" ; Section 9.8 | "CONNECT" ; Section 9.9 | extension-method extension-method = token token = 1*<any CHAR except CTLs or separators> */returnlen() > 0 && strings.IndexFunc(, isNotToken) == -1}func closeBody( *http.Request) error {if .Body == nil {returnnil }return .Body.Close()}// requestBodyReadError wraps an error from (*Request).write to indicate// that the error came from a Read call on the Request.Body.// This error type should not escape the net/http package to users.type requestBodyReadError struct{ error }// Return value if nonempty, def otherwise.func valueOrDefault(, string) string {if != "" {return }return}// outgoingLength reports the Content-Length of this outgoing (Client) request.// It maps 0 into -1 (unknown) when the Body is non-nil.func outgoingLength( *http.Request) int64 {if .Body == nil || .Body == NoBody {return0 }if .ContentLength != 0 {return .ContentLength }return -1}// errMissingHost is returned by Write when there is no Host or URL present in// the Request.var errMissingHost = errors.New("http: Request.Write on Request with no Host or URL set")func closeRequestBody( *http.Request) error {if .Body == nil {returnnil }return .Body.Close()}// Headers that Request.Write handles itself and should be skipped.var reqWriteExcludeHeader = map[string]bool{"Host": true, // not in Header map anyway"User-Agent": true,"Content-Length": true,"Transfer-Encoding": true,"Trailer": true,header.HeaderOderKey: true,header.PseudoHeaderOderKey: true,}// requestMethodUsuallyLacksBody reports whether the given request// method is one that typically does not involve a request body.// This is used by the Transport (via// transferWriter.shouldSendChunkedRequestBody) to determine whether// we try to test-read a byte from a non-nil Request.Body when// Request.outgoingLength() returns -1. See the comments in// shouldSendChunkedRequestBody.func requestMethodUsuallyLacksBody( string) bool {switch {case"GET", "HEAD", "DELETE", "OPTIONS", "PROPFIND", "SEARCH":returntrue }returnfalse}// requiresHTTP1 reports whether this request requires being sent on// an HTTP/1 connection.func requestRequiresHTTP1( *http.Request) bool {returnhasToken(.Header.Get("Connection"), "upgrade") &&ascii.EqualFold(.Header.Get("Upgrade"), "websocket")}func isReplayable( *http.Request) bool {if .Body == nil || .Body == NoBody || .GetBody != nil {switchvalueOrDefault(.Method, "GET") {case"GET", "HEAD", "OPTIONS", "TRACE":returntrue }// The Idempotency-Key, while non-standard, is widely used to // mean a POST or other request is idempotent. See // https://golang.org/issue/19943#issuecomment-421092421ifheaderHas(.Header, "Idempotency-Key") || headerHas(.Header, "X-Idempotency-Key") {returntrue } }returnfalse}func reqExpectsContinue( *http.Request) bool {returnhasToken(headerGet(.Header, "Expect"), "100-continue")}func reqWantsClose( *http.Request) bool {if .Close {returntrue }returnhasToken(headerGet(.Header, "Connection"), "close")}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.