github.com/sbinet/go@v0.0.0-20160827155028-54d7de7dd62b/src/net/http/http.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package http
     6  
     7  import (
     8  	"strings"
     9  
    10  	"golang_org/x/net/lex/httplex"
    11  )
    12  
    13  // maxInt64 is the effective "infinite" value for the Server and
    14  // Transport's byte-limiting readers.
    15  const maxInt64 = 1<<63 - 1
    16  
    17  // TODO(bradfitz): move common stuff here. The other files have accumulated
    18  // generic http stuff in random places.
    19  
    20  // contextKey is a value for use with context.WithValue. It's used as
    21  // a pointer so it fits in an interface{} without allocation.
    22  type contextKey struct {
    23  	name string
    24  }
    25  
    26  func (k *contextKey) String() string { return "net/http context value " + k.name }
    27  
    28  // Given a string of the form "host", "host:port", or "[ipv6::address]:port",
    29  // return true if the string includes a port.
    30  func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
    31  
    32  // removeEmptyPort strips the empty port in ":port" to ""
    33  // as mandated by RFC 3986 Section 6.2.3.
    34  func removeEmptyPort(host string) string {
    35  	if hasPort(host) {
    36  		return strings.TrimSuffix(host, ":")
    37  	}
    38  	return host
    39  }
    40  
    41  func isNotToken(r rune) bool {
    42  	return !httplex.IsTokenRune(r)
    43  }