1
0
mirror of https://github.com/golang/go synced 2024-11-18 04:14:49 -07:00

vendor, net/http: update x/net for httplex to httpguts merge

Updates x/net to git rev cbb82b59bc for:

    lex/httplex, http/httpguts: merge the httplex package into httpguts
    https://golang.org/cl/111875

    http2: set nextStreamID to 3 when AllowHTTP is set
    https://golang.org/cl/111835

    http2: terminate await request cancel goroutine on conn close
    https://golang.org/cl/108415

Fixes #24776 (CL 111655 didn't actually include it)

Change-Id: I0a21e169ebba2ec35219f347f1e31cd4c67bebdf
Reviewed-on: https://go-review.googlesource.com/111876
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Kunpei Sakai <namusyaka@gmail.com>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Brad Fitzpatrick 2018-05-07 19:09:16 +00:00
parent 9b16b9c7f9
commit 8e9386db0e
8 changed files with 32 additions and 31 deletions

View File

@ -404,7 +404,6 @@ var pkgDeps = map[string][]string{
"golang_org/x/net/http/httpguts", "golang_org/x/net/http/httpguts",
"golang_org/x/net/http2/hpack", "golang_org/x/net/http2/hpack",
"golang_org/x/net/idna", "golang_org/x/net/idna",
"golang_org/x/net/lex/httplex",
"golang_org/x/text/unicode/norm", "golang_org/x/text/unicode/norm",
"golang_org/x/text/width", "golang_org/x/text/width",
"internal/nettrace", "internal/nettrace",

View File

@ -47,7 +47,6 @@ import (
"golang_org/x/net/http/httpguts" "golang_org/x/net/http/httpguts"
"golang_org/x/net/http2/hpack" "golang_org/x/net/http2/hpack"
"golang_org/x/net/idna" "golang_org/x/net/idna"
"golang_org/x/net/lex/httplex"
) )
// A list of the possible cipher suite ids. Taken from // A list of the possible cipher suite ids. Taken from
@ -2746,7 +2745,7 @@ func (fr *http2Framer) readMetaFrame(hf *http2HeadersFrame) (*http2MetaHeadersFr
if http2VerboseLogs && fr.logReads { if http2VerboseLogs && fr.logReads {
fr.debugReadLoggerf("http2: decoded hpack field %+v", hf) fr.debugReadLoggerf("http2: decoded hpack field %+v", hf)
} }
if !httplex.ValidHeaderFieldValue(hf.Value) { if !httpguts.ValidHeaderFieldValue(hf.Value) {
invalid = http2headerFieldValueError(hf.Value) invalid = http2headerFieldValueError(hf.Value)
} }
isPseudo := strings.HasPrefix(hf.Name, ":") isPseudo := strings.HasPrefix(hf.Name, ":")
@ -3372,7 +3371,7 @@ var (
) )
// validWireHeaderFieldName reports whether v is a valid header field // validWireHeaderFieldName reports whether v is a valid header field
// name (key). See httplex.ValidHeaderName for the base rules. // name (key). See httpguts.ValidHeaderName for the base rules.
// //
// Further, http2 says: // Further, http2 says:
// "Just as in HTTP/1.x, header field names are strings of ASCII // "Just as in HTTP/1.x, header field names are strings of ASCII
@ -3384,7 +3383,7 @@ func http2validWireHeaderFieldName(v string) bool {
return false return false
} }
for _, r := range v { for _, r := range v {
if !httplex.IsTokenRune(r) { if !httpguts.IsTokenRune(r) {
return false return false
} }
if 'A' <= r && r <= 'Z' { if 'A' <= r && r <= 'Z' {
@ -6846,7 +6845,9 @@ func (http2noCachedConnError) Error() string { return "http2: no cached connecti
// or its equivalent renamed type in net/http2's h2_bundle.go. Both types // or its equivalent renamed type in net/http2's h2_bundle.go. Both types
// may coexist in the same running program. // may coexist in the same running program.
func http2isNoCachedConnError(err error) bool { func http2isNoCachedConnError(err error) bool {
_, ok := err.(interface{ IsHTTP2NoCachedConnError() }) _, ok := err.(interface {
IsHTTP2NoCachedConnError()
})
return ok return ok
} }
@ -7092,6 +7093,10 @@ func (t *http2Transport) newClientConn(c net.Conn, singleUse bool) (*http2Client
// henc in response to SETTINGS frames? // henc in response to SETTINGS frames?
cc.henc = hpack.NewEncoder(&cc.hbuf) cc.henc = hpack.NewEncoder(&cc.hbuf)
if t.AllowHTTP {
cc.nextStreamID = 3
}
if cs, ok := c.(http2connectionStater); ok { if cs, ok := c.(http2connectionStater); ok {
state := cs.ConnectionState() state := cs.ConnectionState()
cc.tlsState = &state cc.tlsState = &state
@ -7476,6 +7481,9 @@ func (cc *http2ClientConn) awaitOpenSlotForRequest(req *Request) error {
for { for {
cc.lastActive = time.Now() cc.lastActive = time.Now()
if cc.closed || !cc.canTakeNewRequestLocked() { if cc.closed || !cc.canTakeNewRequestLocked() {
if waitingForConn != nil {
close(waitingForConn)
}
return http2errClientConnUnusable return http2errClientConnUnusable
} }
if int64(len(cc.streams))+1 <= int64(cc.maxConcurrentStreams) { if int64(len(cc.streams))+1 <= int64(cc.maxConcurrentStreams) {
@ -7699,7 +7707,7 @@ func (cc *http2ClientConn) encodeHeaders(req *Request, addGzipHeader bool, trail
if host == "" { if host == "" {
host = req.URL.Host host = req.URL.Host
} }
host, err := httplex.PunycodeHostPort(host) host, err := httpguts.PunycodeHostPort(host)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -7724,11 +7732,11 @@ func (cc *http2ClientConn) encodeHeaders(req *Request, addGzipHeader bool, trail
// potentially pollute our hpack state. (We want to be able to // potentially pollute our hpack state. (We want to be able to
// continue to reuse the hpack encoder for future requests) // continue to reuse the hpack encoder for future requests)
for k, vv := range req.Header { for k, vv := range req.Header {
if !httplex.ValidHeaderFieldName(k) { if !httpguts.ValidHeaderFieldName(k) {
return nil, fmt.Errorf("invalid HTTP header name %q", k) return nil, fmt.Errorf("invalid HTTP header name %q", k)
} }
for _, v := range vv { for _, v := range vv {
if !httplex.ValidHeaderFieldValue(v) { if !httpguts.ValidHeaderFieldValue(v) {
return nil, fmt.Errorf("invalid HTTP header value %q for header %q", v, k) return nil, fmt.Errorf("invalid HTTP header value %q for header %q", v, k)
} }
} }
@ -8769,7 +8777,7 @@ func (t *http2Transport) getBodyWriterState(cs *http2clientStream, body io.Reade
} }
s.delay = t.expectContinueTimeout() s.delay = t.expectContinueTimeout()
if s.delay == 0 || if s.delay == 0 ||
!httplex.HeaderValuesContainsToken( !httpguts.HeaderValuesContainsToken(
cs.req.Header["Expect"], cs.req.Header["Expect"],
"100-continue") { "100-continue") {
return return
@ -8824,7 +8832,7 @@ func (s http2bodyWriterState) scheduleBodyWrite() {
// isConnectionCloseRequest reports whether req should use its own // isConnectionCloseRequest reports whether req should use its own
// connection for a single request and then close the connection. // connection for a single request and then close the connection.
func http2isConnectionCloseRequest(req *Request) bool { func http2isConnectionCloseRequest(req *Request) bool {
return req.Close || httplex.HeaderValuesContainsToken(req.Header["Connection"], "close") return req.Close || httpguts.HeaderValuesContainsToken(req.Header["Connection"], "close")
} }
// writeFramer is implemented by any type that is used to write frames. // writeFramer is implemented by any type that is used to write frames.
@ -9164,7 +9172,7 @@ func http2encodeHeaders(enc *hpack.Encoder, h Header, keys []string) {
} }
isTE := k == "transfer-encoding" isTE := k == "transfer-encoding"
for _, v := range vv { for _, v := range vv {
if !httplex.ValidHeaderFieldValue(v) { if !httpguts.ValidHeaderFieldValue(v) {
// TODO: return an error? golang.org/issue/14048 // TODO: return an error? golang.org/issue/14048
// For now just omit it. // For now just omit it.
continue continue

View File

@ -11,7 +11,7 @@ import (
"time" "time"
"unicode/utf8" "unicode/utf8"
"golang_org/x/net/lex/httplex" "golang_org/x/net/http/httpguts"
) )
// maxInt64 is the effective "infinite" value for the Server and // maxInt64 is the effective "infinite" value for the Server and
@ -47,7 +47,7 @@ func removeEmptyPort(host string) string {
} }
func isNotToken(r rune) bool { func isNotToken(r rune) bool {
return !httplex.IsTokenRune(r) return !httpguts.IsTokenRune(r)
} }
func isASCII(s string) bool { func isASCII(s string) bool {

View File

@ -29,7 +29,6 @@ import (
"time" "time"
"golang_org/x/net/http/httpguts" "golang_org/x/net/http/httpguts"
"golang_org/x/net/lex/httplex"
) )
// Errors used by the HTTP server. // Errors used by the HTTP server.
@ -964,15 +963,15 @@ func (c *conn) readRequest(ctx context.Context) (w *response, err error) {
if len(hosts) > 1 { if len(hosts) > 1 {
return nil, badRequestError("too many Host headers") return nil, badRequestError("too many Host headers")
} }
if len(hosts) == 1 && !httplex.ValidHostHeader(hosts[0]) { if len(hosts) == 1 && !httpguts.ValidHostHeader(hosts[0]) {
return nil, badRequestError("malformed Host header") return nil, badRequestError("malformed Host header")
} }
for k, vv := range req.Header { for k, vv := range req.Header {
if !httplex.ValidHeaderFieldName(k) { if !httpguts.ValidHeaderFieldName(k) {
return nil, badRequestError("invalid header name") return nil, badRequestError("invalid header name")
} }
for _, v := range vv { for _, v := range vv {
if !httplex.ValidHeaderFieldValue(v) { if !httpguts.ValidHeaderFieldValue(v) {
return nil, badRequestError("invalid header value") return nil, badRequestError("invalid header value")
} }
} }

View File

@ -19,7 +19,7 @@ import (
"sync" "sync"
"time" "time"
"golang_org/x/net/lex/httplex" "golang_org/x/net/http/httpguts"
) )
// ErrLineTooLong is returned when reading request or response bodies // ErrLineTooLong is returned when reading request or response bodies
@ -690,9 +690,9 @@ func shouldClose(major, minor int, header Header, removeCloseHeader bool) bool {
} }
conv := header["Connection"] conv := header["Connection"]
hasClose := httplex.HeaderValuesContainsToken(conv, "close") hasClose := httpguts.HeaderValuesContainsToken(conv, "close")
if major == 1 && minor == 0 { if major == 1 && minor == 0 {
return hasClose || !httplex.HeaderValuesContainsToken(conv, "keep-alive") return hasClose || !httpguts.HeaderValuesContainsToken(conv, "keep-alive")
} }
if hasClose && removeCloseHeader { if hasClose && removeCloseHeader {

View File

@ -28,7 +28,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"golang_org/x/net/lex/httplex" "golang_org/x/net/http/httpguts"
) )
// DefaultTransport is the default implementation of Transport and is // DefaultTransport is the default implementation of Transport and is
@ -363,11 +363,11 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {
isHTTP := scheme == "http" || scheme == "https" isHTTP := scheme == "http" || scheme == "https"
if isHTTP { if isHTTP {
for k, vv := range req.Header { for k, vv := range req.Header {
if !httplex.ValidHeaderFieldName(k) { if !httpguts.ValidHeaderFieldName(k) {
return nil, fmt.Errorf("net/http: invalid header field name %q", k) return nil, fmt.Errorf("net/http: invalid header field name %q", k)
} }
for _, v := range vv { for _, v := range vv {
if !httplex.ValidHeaderFieldValue(v) { if !httpguts.ValidHeaderFieldValue(v) {
return nil, fmt.Errorf("net/http: invalid header field value %q for key %v", v, k) return nil, fmt.Errorf("net/http: invalid header field value %q for key %v", v, k)
} }
} }

View File

@ -2,12 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Package httplex contains rules around lexical matters of various package httpguts
// HTTP-related specifications.
//
// This package is shared by the standard library (which vendors it)
// and x/net/http2. It comes with no API stability promise.
package httplex
import ( import (
"net" "net"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package httplex package httpguts
import ( import (
"testing" "testing"