| // Copyright 2016 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package http |
| |
| import ( |
| "strings" |
| |
| "golang_org/x/net/lex/httplex" |
| ) |
| |
| // maxInt64 is the effective "infinite" value for the Server and |
| // Transport's byte-limiting readers. |
| const maxInt64 = 1<<63 - 1 |
| |
| // TODO(bradfitz): move common stuff here. The other files have accumulated |
| // generic http stuff in random places. |
| |
| // contextKey is a value for use with context.WithValue. It's used as |
| // a pointer so it fits in an interface{} without allocation. |
| type contextKey struct { |
| name string |
| } |
| |
| func (k *contextKey) String() string { return "net/http context value " + k.name } |
| |
| // Given a string of the form "host", "host:port", or "[ipv6::address]:port", |
| // return true if the string includes a port. |
| func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") } |
| |
| // removeEmptyPort strips the empty port in ":port" to "" |
| // as mandated by RFC 3986 Section 6.2.3. |
| func removeEmptyPort(host string) string { |
| if hasPort(host) { |
| return strings.TrimSuffix(host, ":") |
| } |
| return host |
| } |
| |
| func isNotToken(r rune) bool { |
| return !httplex.IsTokenRune(r) |
| } |