mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 09:24:23 +00:00
Update golang/x/net dependency to release-branch.go1.11
This commit is contained in:
7
Gopkg.lock
generated
7
Gopkg.lock
generated
@@ -207,16 +207,16 @@
|
|||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:d1a6ebe75268a41b6fbb1d43947cf8688d8580423b7484fa5ae608beef6df24d"
|
digest = "1:18108bc7e384e395b4805632a637405a3df71fa518e22f9b39b0c08b89a52b96"
|
||||||
name = "golang.org/x/net"
|
name = "golang.org/x/net"
|
||||||
packages = [
|
packages = [
|
||||||
|
"http/httpguts",
|
||||||
"http2",
|
"http2",
|
||||||
"http2/hpack",
|
"http2/hpack",
|
||||||
"idna",
|
"idna",
|
||||||
"lex/httplex",
|
|
||||||
]
|
]
|
||||||
pruneopts = "NUT"
|
pruneopts = "NUT"
|
||||||
revision = "1c05540f6879653db88113bc4a2b70aec4bd491f"
|
revision = "fe579d43d83210096a79b46dcca0e3721058393a"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:e33513a825fcd765e97b5de639a2f7547542d1a8245df0cef18e1fd390b778a9"
|
digest = "1:e33513a825fcd765e97b5de639a2f7547542d1a8245df0cef18e1fd390b778a9"
|
||||||
@@ -366,6 +366,7 @@
|
|||||||
input-imports = [
|
input-imports = [
|
||||||
"github.com/evanphx/json-patch",
|
"github.com/evanphx/json-patch",
|
||||||
"github.com/ghodss/yaml",
|
"github.com/ghodss/yaml",
|
||||||
|
"github.com/go-openapi/spec",
|
||||||
"github.com/pkg/errors",
|
"github.com/pkg/errors",
|
||||||
"github.com/spf13/cobra",
|
"github.com/spf13/cobra",
|
||||||
"gopkg.in/yaml.v2",
|
"gopkg.in/yaml.v2",
|
||||||
|
|||||||
50
vendor/golang.org/x/net/http/httpguts/guts.go
generated
vendored
Normal file
50
vendor/golang.org/x/net/http/httpguts/guts.go
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
// Copyright 2018 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 httpguts provides functions implementing various details
|
||||||
|
// of the HTTP specification.
|
||||||
|
//
|
||||||
|
// This package is shared by the standard library (which vendors it)
|
||||||
|
// and x/net/http2. It comes with no API stability promise.
|
||||||
|
package httpguts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/textproto"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ValidTrailerHeader reports whether name is a valid header field name to appear
|
||||||
|
// in trailers.
|
||||||
|
// See RFC 7230, Section 4.1.2
|
||||||
|
func ValidTrailerHeader(name string) bool {
|
||||||
|
name = textproto.CanonicalMIMEHeaderKey(name)
|
||||||
|
if strings.HasPrefix(name, "If-") || badTrailer[name] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
var badTrailer = map[string]bool{
|
||||||
|
"Authorization": true,
|
||||||
|
"Cache-Control": true,
|
||||||
|
"Connection": true,
|
||||||
|
"Content-Encoding": true,
|
||||||
|
"Content-Length": true,
|
||||||
|
"Content-Range": true,
|
||||||
|
"Content-Type": true,
|
||||||
|
"Expect": true,
|
||||||
|
"Host": true,
|
||||||
|
"Keep-Alive": true,
|
||||||
|
"Max-Forwards": true,
|
||||||
|
"Pragma": true,
|
||||||
|
"Proxy-Authenticate": true,
|
||||||
|
"Proxy-Authorization": true,
|
||||||
|
"Proxy-Connection": true,
|
||||||
|
"Range": true,
|
||||||
|
"Realm": true,
|
||||||
|
"Te": true,
|
||||||
|
"Trailer": true,
|
||||||
|
"Transfer-Encoding": true,
|
||||||
|
"Www-Authenticate": true,
|
||||||
|
}
|
||||||
@@ -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"
|
||||||
2
vendor/golang.org/x/net/http2/ciphers.go
generated
vendored
2
vendor/golang.org/x/net/http2/ciphers.go
generated
vendored
@@ -5,7 +5,7 @@
|
|||||||
package http2
|
package http2
|
||||||
|
|
||||||
// A list of the possible cipher suite ids. Taken from
|
// A list of the possible cipher suite ids. Taken from
|
||||||
// http://www.iana.org/assignments/tls-parameters/tls-parameters.txt
|
// https://www.iana.org/assignments/tls-parameters/tls-parameters.txt
|
||||||
|
|
||||||
const (
|
const (
|
||||||
cipher_TLS_NULL_WITH_NULL_NULL uint16 = 0x0000
|
cipher_TLS_NULL_WITH_NULL_NULL uint16 = 0x0000
|
||||||
|
|||||||
28
vendor/golang.org/x/net/http2/client_conn_pool.go
generated
vendored
28
vendor/golang.org/x/net/http2/client_conn_pool.go
generated
vendored
@@ -52,9 +52,31 @@ const (
|
|||||||
noDialOnMiss = false
|
noDialOnMiss = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// shouldTraceGetConn reports whether getClientConn should call any
|
||||||
|
// ClientTrace.GetConn hook associated with the http.Request.
|
||||||
|
//
|
||||||
|
// This complexity is needed to avoid double calls of the GetConn hook
|
||||||
|
// during the back-and-forth between net/http and x/net/http2 (when the
|
||||||
|
// net/http.Transport is upgraded to also speak http2), as well as support
|
||||||
|
// the case where x/net/http2 is being used directly.
|
||||||
|
func (p *clientConnPool) shouldTraceGetConn(st clientConnIdleState) bool {
|
||||||
|
// If our Transport wasn't made via ConfigureTransport, always
|
||||||
|
// trace the GetConn hook if provided, because that means the
|
||||||
|
// http2 package is being used directly and it's the one
|
||||||
|
// dialing, as opposed to net/http.
|
||||||
|
if _, ok := p.t.ConnPool.(noDialClientConnPool); !ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Otherwise, only use the GetConn hook if this connection has
|
||||||
|
// been used previously for other requests. For fresh
|
||||||
|
// connections, the net/http package does the dialing.
|
||||||
|
return !st.freshConn
|
||||||
|
}
|
||||||
|
|
||||||
func (p *clientConnPool) getClientConn(req *http.Request, addr string, dialOnMiss bool) (*ClientConn, error) {
|
func (p *clientConnPool) getClientConn(req *http.Request, addr string, dialOnMiss bool) (*ClientConn, error) {
|
||||||
if isConnectionCloseRequest(req) && dialOnMiss {
|
if isConnectionCloseRequest(req) && dialOnMiss {
|
||||||
// It gets its own connection.
|
// It gets its own connection.
|
||||||
|
traceGetConn(req, addr)
|
||||||
const singleUse = true
|
const singleUse = true
|
||||||
cc, err := p.t.dialClientConn(addr, singleUse)
|
cc, err := p.t.dialClientConn(addr, singleUse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -64,7 +86,10 @@ func (p *clientConnPool) getClientConn(req *http.Request, addr string, dialOnMis
|
|||||||
}
|
}
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
for _, cc := range p.conns[addr] {
|
for _, cc := range p.conns[addr] {
|
||||||
if cc.CanTakeNewRequest() {
|
if st := cc.idleState(); st.canTakeNewRequest {
|
||||||
|
if p.shouldTraceGetConn(st) {
|
||||||
|
traceGetConn(req, addr)
|
||||||
|
}
|
||||||
p.mu.Unlock()
|
p.mu.Unlock()
|
||||||
return cc, nil
|
return cc, nil
|
||||||
}
|
}
|
||||||
@@ -73,6 +98,7 @@ func (p *clientConnPool) getClientConn(req *http.Request, addr string, dialOnMis
|
|||||||
p.mu.Unlock()
|
p.mu.Unlock()
|
||||||
return nil, ErrNoCachedConn
|
return nil, ErrNoCachedConn
|
||||||
}
|
}
|
||||||
|
traceGetConn(req, addr)
|
||||||
call := p.getStartDialLocked(addr)
|
call := p.getStartDialLocked(addr)
|
||||||
p.mu.Unlock()
|
p.mu.Unlock()
|
||||||
<-call.done
|
<-call.done
|
||||||
|
|||||||
80
vendor/golang.org/x/net/http2/configure_transport.go
generated
vendored
80
vendor/golang.org/x/net/http2/configure_transport.go
generated
vendored
@@ -1,80 +0,0 @@
|
|||||||
// Copyright 2015 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.
|
|
||||||
|
|
||||||
// +build go1.6
|
|
||||||
|
|
||||||
package http2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func configureTransport(t1 *http.Transport) (*Transport, error) {
|
|
||||||
connPool := new(clientConnPool)
|
|
||||||
t2 := &Transport{
|
|
||||||
ConnPool: noDialClientConnPool{connPool},
|
|
||||||
t1: t1,
|
|
||||||
}
|
|
||||||
connPool.t = t2
|
|
||||||
if err := registerHTTPSProtocol(t1, noDialH2RoundTripper{t2}); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if t1.TLSClientConfig == nil {
|
|
||||||
t1.TLSClientConfig = new(tls.Config)
|
|
||||||
}
|
|
||||||
if !strSliceContains(t1.TLSClientConfig.NextProtos, "h2") {
|
|
||||||
t1.TLSClientConfig.NextProtos = append([]string{"h2"}, t1.TLSClientConfig.NextProtos...)
|
|
||||||
}
|
|
||||||
if !strSliceContains(t1.TLSClientConfig.NextProtos, "http/1.1") {
|
|
||||||
t1.TLSClientConfig.NextProtos = append(t1.TLSClientConfig.NextProtos, "http/1.1")
|
|
||||||
}
|
|
||||||
upgradeFn := func(authority string, c *tls.Conn) http.RoundTripper {
|
|
||||||
addr := authorityAddr("https", authority)
|
|
||||||
if used, err := connPool.addConnIfNeeded(addr, t2, c); err != nil {
|
|
||||||
go c.Close()
|
|
||||||
return erringRoundTripper{err}
|
|
||||||
} else if !used {
|
|
||||||
// Turns out we don't need this c.
|
|
||||||
// For example, two goroutines made requests to the same host
|
|
||||||
// at the same time, both kicking off TCP dials. (since protocol
|
|
||||||
// was unknown)
|
|
||||||
go c.Close()
|
|
||||||
}
|
|
||||||
return t2
|
|
||||||
}
|
|
||||||
if m := t1.TLSNextProto; len(m) == 0 {
|
|
||||||
t1.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{
|
|
||||||
"h2": upgradeFn,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m["h2"] = upgradeFn
|
|
||||||
}
|
|
||||||
return t2, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// registerHTTPSProtocol calls Transport.RegisterProtocol but
|
|
||||||
// converting panics into errors.
|
|
||||||
func registerHTTPSProtocol(t *http.Transport, rt http.RoundTripper) (err error) {
|
|
||||||
defer func() {
|
|
||||||
if e := recover(); e != nil {
|
|
||||||
err = fmt.Errorf("%v", e)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
t.RegisterProtocol("https", rt)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// noDialH2RoundTripper is a RoundTripper which only tries to complete the request
|
|
||||||
// if there's already has a cached connection to the host.
|
|
||||||
type noDialH2RoundTripper struct{ t *Transport }
|
|
||||||
|
|
||||||
func (rt noDialH2RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
||||||
res, err := rt.t.RoundTrip(req)
|
|
||||||
if err == ErrNoCachedConn {
|
|
||||||
return nil, http.ErrSkipAltProtocol
|
|
||||||
}
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
10
vendor/golang.org/x/net/http2/flow.go
generated
vendored
10
vendor/golang.org/x/net/http2/flow.go
generated
vendored
@@ -41,10 +41,10 @@ func (f *flow) take(n int32) {
|
|||||||
// add adds n bytes (positive or negative) to the flow control window.
|
// add adds n bytes (positive or negative) to the flow control window.
|
||||||
// It returns false if the sum would exceed 2^31-1.
|
// It returns false if the sum would exceed 2^31-1.
|
||||||
func (f *flow) add(n int32) bool {
|
func (f *flow) add(n int32) bool {
|
||||||
remain := (1<<31 - 1) - f.n
|
sum := f.n + n
|
||||||
if n > remain {
|
if (sum > n) == (f.n > 0) {
|
||||||
return false
|
f.n = sum
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
f.n += n
|
return false
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|||||||
71
vendor/golang.org/x/net/http2/frame.go
generated
vendored
71
vendor/golang.org/x/net/http2/frame.go
generated
vendored
@@ -14,8 +14,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"golang.org/x/net/http/httpguts"
|
||||||
"golang.org/x/net/http2/hpack"
|
"golang.org/x/net/http2/hpack"
|
||||||
"golang.org/x/net/lex/httplex"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const frameHeaderLen = 9
|
const frameHeaderLen = 9
|
||||||
@@ -643,7 +643,7 @@ func (f *Framer) WriteData(streamID uint32, endStream bool, data []byte) error {
|
|||||||
return f.WriteDataPadded(streamID, endStream, data, nil)
|
return f.WriteDataPadded(streamID, endStream, data, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteData writes a DATA frame with optional padding.
|
// WriteDataPadded writes a DATA frame with optional padding.
|
||||||
//
|
//
|
||||||
// If pad is nil, the padding bit is not sent.
|
// If pad is nil, the padding bit is not sent.
|
||||||
// The length of pad must not exceed 255 bytes.
|
// The length of pad must not exceed 255 bytes.
|
||||||
@@ -733,32 +733,67 @@ func (f *SettingsFrame) IsAck() bool {
|
|||||||
return f.FrameHeader.Flags.Has(FlagSettingsAck)
|
return f.FrameHeader.Flags.Has(FlagSettingsAck)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *SettingsFrame) Value(s SettingID) (v uint32, ok bool) {
|
func (f *SettingsFrame) Value(id SettingID) (v uint32, ok bool) {
|
||||||
f.checkValid()
|
f.checkValid()
|
||||||
buf := f.p
|
for i := 0; i < f.NumSettings(); i++ {
|
||||||
for len(buf) > 0 {
|
if s := f.Setting(i); s.ID == id {
|
||||||
settingID := SettingID(binary.BigEndian.Uint16(buf[:2]))
|
return s.Val, true
|
||||||
if settingID == s {
|
|
||||||
return binary.BigEndian.Uint32(buf[2:6]), true
|
|
||||||
}
|
}
|
||||||
buf = buf[6:]
|
|
||||||
}
|
}
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setting returns the setting from the frame at the given 0-based index.
|
||||||
|
// The index must be >= 0 and less than f.NumSettings().
|
||||||
|
func (f *SettingsFrame) Setting(i int) Setting {
|
||||||
|
buf := f.p
|
||||||
|
return Setting{
|
||||||
|
ID: SettingID(binary.BigEndian.Uint16(buf[i*6 : i*6+2])),
|
||||||
|
Val: binary.BigEndian.Uint32(buf[i*6+2 : i*6+6]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *SettingsFrame) NumSettings() int { return len(f.p) / 6 }
|
||||||
|
|
||||||
|
// HasDuplicates reports whether f contains any duplicate setting IDs.
|
||||||
|
func (f *SettingsFrame) HasDuplicates() bool {
|
||||||
|
num := f.NumSettings()
|
||||||
|
if num == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// If it's small enough (the common case), just do the n^2
|
||||||
|
// thing and avoid a map allocation.
|
||||||
|
if num < 10 {
|
||||||
|
for i := 0; i < num; i++ {
|
||||||
|
idi := f.Setting(i).ID
|
||||||
|
for j := i + 1; j < num; j++ {
|
||||||
|
idj := f.Setting(j).ID
|
||||||
|
if idi == idj {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
seen := map[SettingID]bool{}
|
||||||
|
for i := 0; i < num; i++ {
|
||||||
|
id := f.Setting(i).ID
|
||||||
|
if seen[id] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
seen[id] = true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// ForeachSetting runs fn for each setting.
|
// ForeachSetting runs fn for each setting.
|
||||||
// It stops and returns the first error.
|
// It stops and returns the first error.
|
||||||
func (f *SettingsFrame) ForeachSetting(fn func(Setting) error) error {
|
func (f *SettingsFrame) ForeachSetting(fn func(Setting) error) error {
|
||||||
f.checkValid()
|
f.checkValid()
|
||||||
buf := f.p
|
for i := 0; i < f.NumSettings(); i++ {
|
||||||
for len(buf) > 0 {
|
if err := fn(f.Setting(i)); err != nil {
|
||||||
if err := fn(Setting{
|
|
||||||
SettingID(binary.BigEndian.Uint16(buf[:2])),
|
|
||||||
binary.BigEndian.Uint32(buf[2:6]),
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
buf = buf[6:]
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1442,7 +1477,7 @@ func (fr *Framer) maxHeaderStringLen() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// readMetaFrame returns 0 or more CONTINUATION frames from fr and
|
// readMetaFrame returns 0 or more CONTINUATION frames from fr and
|
||||||
// merge them into into the provided hf and returns a MetaHeadersFrame
|
// merge them into the provided hf and returns a MetaHeadersFrame
|
||||||
// with the decoded hpack values.
|
// with the decoded hpack values.
|
||||||
func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
|
func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
|
||||||
if fr.AllowIllegalReads {
|
if fr.AllowIllegalReads {
|
||||||
@@ -1462,7 +1497,7 @@ func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
|
|||||||
if VerboseLogs && fr.logReads {
|
if VerboseLogs && 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 = headerFieldValueError(hf.Value)
|
invalid = headerFieldValueError(hf.Value)
|
||||||
}
|
}
|
||||||
isPseudo := strings.HasPrefix(hf.Name, ":")
|
isPseudo := strings.HasPrefix(hf.Name, ":")
|
||||||
|
|||||||
29
vendor/golang.org/x/net/http2/go111.go
generated
vendored
Normal file
29
vendor/golang.org/x/net/http2/go111.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2018 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.
|
||||||
|
|
||||||
|
// +build go1.11
|
||||||
|
|
||||||
|
package http2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http/httptrace"
|
||||||
|
"net/textproto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func traceHasWroteHeaderField(trace *httptrace.ClientTrace) bool {
|
||||||
|
return trace != nil && trace.WroteHeaderField != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func traceWroteHeaderField(trace *httptrace.ClientTrace, k, v string) {
|
||||||
|
if trace != nil && trace.WroteHeaderField != nil {
|
||||||
|
trace.WroteHeaderField(k, []string{v})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func traceGot1xxResponseFunc(trace *httptrace.ClientTrace) func(int, textproto.MIMEHeader) error {
|
||||||
|
if trace != nil {
|
||||||
|
return trace.Got1xxResponse
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
16
vendor/golang.org/x/net/http2/go16.go
generated
vendored
16
vendor/golang.org/x/net/http2/go16.go
generated
vendored
@@ -1,16 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
// +build go1.6
|
|
||||||
|
|
||||||
package http2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func transportExpectContinueTimeout(t1 *http.Transport) time.Duration {
|
|
||||||
return t1.ExpectContinueTimeout
|
|
||||||
}
|
|
||||||
106
vendor/golang.org/x/net/http2/go17.go
generated
vendored
106
vendor/golang.org/x/net/http2/go17.go
generated
vendored
@@ -1,106 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
// +build go1.7
|
|
||||||
|
|
||||||
package http2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptrace"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type contextContext interface {
|
|
||||||
context.Context
|
|
||||||
}
|
|
||||||
|
|
||||||
func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx contextContext, cancel func()) {
|
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
|
||||||
ctx = context.WithValue(ctx, http.LocalAddrContextKey, c.LocalAddr())
|
|
||||||
if hs := opts.baseConfig(); hs != nil {
|
|
||||||
ctx = context.WithValue(ctx, http.ServerContextKey, hs)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) {
|
|
||||||
return context.WithCancel(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func requestWithContext(req *http.Request, ctx contextContext) *http.Request {
|
|
||||||
return req.WithContext(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
type clientTrace httptrace.ClientTrace
|
|
||||||
|
|
||||||
func reqContext(r *http.Request) context.Context { return r.Context() }
|
|
||||||
|
|
||||||
func (t *Transport) idleConnTimeout() time.Duration {
|
|
||||||
if t.t1 != nil {
|
|
||||||
return t.t1.IdleConnTimeout
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func setResponseUncompressed(res *http.Response) { res.Uncompressed = true }
|
|
||||||
|
|
||||||
func traceGotConn(req *http.Request, cc *ClientConn) {
|
|
||||||
trace := httptrace.ContextClientTrace(req.Context())
|
|
||||||
if trace == nil || trace.GotConn == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ci := httptrace.GotConnInfo{Conn: cc.tconn}
|
|
||||||
cc.mu.Lock()
|
|
||||||
ci.Reused = cc.nextStreamID > 1
|
|
||||||
ci.WasIdle = len(cc.streams) == 0 && ci.Reused
|
|
||||||
if ci.WasIdle && !cc.lastActive.IsZero() {
|
|
||||||
ci.IdleTime = time.Now().Sub(cc.lastActive)
|
|
||||||
}
|
|
||||||
cc.mu.Unlock()
|
|
||||||
|
|
||||||
trace.GotConn(ci)
|
|
||||||
}
|
|
||||||
|
|
||||||
func traceWroteHeaders(trace *clientTrace) {
|
|
||||||
if trace != nil && trace.WroteHeaders != nil {
|
|
||||||
trace.WroteHeaders()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func traceGot100Continue(trace *clientTrace) {
|
|
||||||
if trace != nil && trace.Got100Continue != nil {
|
|
||||||
trace.Got100Continue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func traceWait100Continue(trace *clientTrace) {
|
|
||||||
if trace != nil && trace.Wait100Continue != nil {
|
|
||||||
trace.Wait100Continue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func traceWroteRequest(trace *clientTrace, err error) {
|
|
||||||
if trace != nil && trace.WroteRequest != nil {
|
|
||||||
trace.WroteRequest(httptrace.WroteRequestInfo{Err: err})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func traceFirstResponseByte(trace *clientTrace) {
|
|
||||||
if trace != nil && trace.GotFirstResponseByte != nil {
|
|
||||||
trace.GotFirstResponseByte()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func requestTrace(req *http.Request) *clientTrace {
|
|
||||||
trace := httptrace.ContextClientTrace(req.Context())
|
|
||||||
return (*clientTrace)(trace)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ping sends a PING frame to the server and waits for the ack.
|
|
||||||
func (cc *ClientConn) Ping(ctx context.Context) error {
|
|
||||||
return cc.ping(ctx)
|
|
||||||
}
|
|
||||||
36
vendor/golang.org/x/net/http2/go17_not18.go
generated
vendored
36
vendor/golang.org/x/net/http2/go17_not18.go
generated
vendored
@@ -1,36 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
// +build go1.7,!go1.8
|
|
||||||
|
|
||||||
package http2
|
|
||||||
|
|
||||||
import "crypto/tls"
|
|
||||||
|
|
||||||
// temporary copy of Go 1.7's private tls.Config.clone:
|
|
||||||
func cloneTLSConfig(c *tls.Config) *tls.Config {
|
|
||||||
return &tls.Config{
|
|
||||||
Rand: c.Rand,
|
|
||||||
Time: c.Time,
|
|
||||||
Certificates: c.Certificates,
|
|
||||||
NameToCertificate: c.NameToCertificate,
|
|
||||||
GetCertificate: c.GetCertificate,
|
|
||||||
RootCAs: c.RootCAs,
|
|
||||||
NextProtos: c.NextProtos,
|
|
||||||
ServerName: c.ServerName,
|
|
||||||
ClientAuth: c.ClientAuth,
|
|
||||||
ClientCAs: c.ClientCAs,
|
|
||||||
InsecureSkipVerify: c.InsecureSkipVerify,
|
|
||||||
CipherSuites: c.CipherSuites,
|
|
||||||
PreferServerCipherSuites: c.PreferServerCipherSuites,
|
|
||||||
SessionTicketsDisabled: c.SessionTicketsDisabled,
|
|
||||||
SessionTicketKey: c.SessionTicketKey,
|
|
||||||
ClientSessionCache: c.ClientSessionCache,
|
|
||||||
MinVersion: c.MinVersion,
|
|
||||||
MaxVersion: c.MaxVersion,
|
|
||||||
CurvePreferences: c.CurvePreferences,
|
|
||||||
DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled,
|
|
||||||
Renegotiation: c.Renegotiation,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
56
vendor/golang.org/x/net/http2/go18.go
generated
vendored
56
vendor/golang.org/x/net/http2/go18.go
generated
vendored
@@ -1,56 +0,0 @@
|
|||||||
// Copyright 2015 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.
|
|
||||||
|
|
||||||
// +build go1.8
|
|
||||||
|
|
||||||
package http2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func cloneTLSConfig(c *tls.Config) *tls.Config {
|
|
||||||
c2 := c.Clone()
|
|
||||||
c2.GetClientCertificate = c.GetClientCertificate // golang.org/issue/19264
|
|
||||||
return c2
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ http.Pusher = (*responseWriter)(nil)
|
|
||||||
|
|
||||||
// Push implements http.Pusher.
|
|
||||||
func (w *responseWriter) Push(target string, opts *http.PushOptions) error {
|
|
||||||
internalOpts := pushOptions{}
|
|
||||||
if opts != nil {
|
|
||||||
internalOpts.Method = opts.Method
|
|
||||||
internalOpts.Header = opts.Header
|
|
||||||
}
|
|
||||||
return w.push(target, internalOpts)
|
|
||||||
}
|
|
||||||
|
|
||||||
func configureServer18(h1 *http.Server, h2 *Server) error {
|
|
||||||
if h2.IdleTimeout == 0 {
|
|
||||||
if h1.IdleTimeout != 0 {
|
|
||||||
h2.IdleTimeout = h1.IdleTimeout
|
|
||||||
} else {
|
|
||||||
h2.IdleTimeout = h1.ReadTimeout
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func shouldLogPanic(panicValue interface{}) bool {
|
|
||||||
return panicValue != nil && panicValue != http.ErrAbortHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
func reqGetBody(req *http.Request) func() (io.ReadCloser, error) {
|
|
||||||
return req.GetBody
|
|
||||||
}
|
|
||||||
|
|
||||||
func reqBodyIsNoBody(body io.ReadCloser) bool {
|
|
||||||
return body == http.NoBody
|
|
||||||
}
|
|
||||||
|
|
||||||
func go18httpNoBody() io.ReadCloser { return http.NoBody } // for tests only
|
|
||||||
16
vendor/golang.org/x/net/http2/go19.go
generated
vendored
16
vendor/golang.org/x/net/http2/go19.go
generated
vendored
@@ -1,16 +0,0 @@
|
|||||||
// Copyright 2015 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.
|
|
||||||
|
|
||||||
// +build go1.9
|
|
||||||
|
|
||||||
package http2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func configureServer19(s *http.Server, conf *Server) error {
|
|
||||||
s.RegisterOnShutdown(conf.state.startGracefulShutdown)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
20
vendor/golang.org/x/net/http2/headermap.go
generated
vendored
20
vendor/golang.org/x/net/http2/headermap.go
generated
vendored
@@ -7,15 +7,21 @@ package http2
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
commonLowerHeader = map[string]string{} // Go-Canonical-Case -> lower-case
|
commonBuildOnce sync.Once
|
||||||
commonCanonHeader = map[string]string{} // lower-case -> Go-Canonical-Case
|
commonLowerHeader map[string]string // Go-Canonical-Case -> lower-case
|
||||||
|
commonCanonHeader map[string]string // lower-case -> Go-Canonical-Case
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func buildCommonHeaderMapsOnce() {
|
||||||
for _, v := range []string{
|
commonBuildOnce.Do(buildCommonHeaderMaps)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildCommonHeaderMaps() {
|
||||||
|
common := []string{
|
||||||
"accept",
|
"accept",
|
||||||
"accept-charset",
|
"accept-charset",
|
||||||
"accept-encoding",
|
"accept-encoding",
|
||||||
@@ -63,7 +69,10 @@ func init() {
|
|||||||
"vary",
|
"vary",
|
||||||
"via",
|
"via",
|
||||||
"www-authenticate",
|
"www-authenticate",
|
||||||
} {
|
}
|
||||||
|
commonLowerHeader = make(map[string]string, len(common))
|
||||||
|
commonCanonHeader = make(map[string]string, len(common))
|
||||||
|
for _, v := range common {
|
||||||
chk := http.CanonicalHeaderKey(v)
|
chk := http.CanonicalHeaderKey(v)
|
||||||
commonLowerHeader[chk] = v
|
commonLowerHeader[chk] = v
|
||||||
commonCanonHeader[v] = chk
|
commonCanonHeader[v] = chk
|
||||||
@@ -71,6 +80,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func lowerHeader(v string) string {
|
func lowerHeader(v string) string {
|
||||||
|
buildCommonHeaderMapsOnce()
|
||||||
if s, ok := commonLowerHeader[v]; ok {
|
if s, ok := commonLowerHeader[v]; ok {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|||||||
2
vendor/golang.org/x/net/http2/hpack/encode.go
generated
vendored
2
vendor/golang.org/x/net/http2/hpack/encode.go
generated
vendored
@@ -206,7 +206,7 @@ func appendVarInt(dst []byte, n byte, i uint64) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// appendHpackString appends s, as encoded in "String Literal"
|
// appendHpackString appends s, as encoded in "String Literal"
|
||||||
// representation, to dst and returns the the extended buffer.
|
// representation, to dst and returns the extended buffer.
|
||||||
//
|
//
|
||||||
// s will be encoded in Huffman codes only when it produces strictly
|
// s will be encoded in Huffman codes only when it produces strictly
|
||||||
// shorter byte string.
|
// shorter byte string.
|
||||||
|
|||||||
14
vendor/golang.org/x/net/http2/hpack/hpack.go
generated
vendored
14
vendor/golang.org/x/net/http2/hpack/hpack.go
generated
vendored
@@ -92,6 +92,8 @@ type Decoder struct {
|
|||||||
// saveBuf is previous data passed to Write which we weren't able
|
// saveBuf is previous data passed to Write which we weren't able
|
||||||
// to fully parse before. Unlike buf, we own this data.
|
// to fully parse before. Unlike buf, we own this data.
|
||||||
saveBuf bytes.Buffer
|
saveBuf bytes.Buffer
|
||||||
|
|
||||||
|
firstField bool // processing the first field of the header block
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDecoder returns a new decoder with the provided maximum dynamic
|
// NewDecoder returns a new decoder with the provided maximum dynamic
|
||||||
@@ -101,6 +103,7 @@ func NewDecoder(maxDynamicTableSize uint32, emitFunc func(f HeaderField)) *Decod
|
|||||||
d := &Decoder{
|
d := &Decoder{
|
||||||
emit: emitFunc,
|
emit: emitFunc,
|
||||||
emitEnabled: true,
|
emitEnabled: true,
|
||||||
|
firstField: true,
|
||||||
}
|
}
|
||||||
d.dynTab.table.init()
|
d.dynTab.table.init()
|
||||||
d.dynTab.allowedMaxSize = maxDynamicTableSize
|
d.dynTab.allowedMaxSize = maxDynamicTableSize
|
||||||
@@ -226,11 +229,15 @@ func (d *Decoder) DecodeFull(p []byte) ([]HeaderField, error) {
|
|||||||
return hf, nil
|
return hf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close declares that the decoding is complete and resets the Decoder
|
||||||
|
// to be reused again for a new header block. If there is any remaining
|
||||||
|
// data in the decoder's buffer, Close returns an error.
|
||||||
func (d *Decoder) Close() error {
|
func (d *Decoder) Close() error {
|
||||||
if d.saveBuf.Len() > 0 {
|
if d.saveBuf.Len() > 0 {
|
||||||
d.saveBuf.Reset()
|
d.saveBuf.Reset()
|
||||||
return DecodingError{errors.New("truncated headers")}
|
return DecodingError{errors.New("truncated headers")}
|
||||||
}
|
}
|
||||||
|
d.firstField = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,6 +273,7 @@ func (d *Decoder) Write(p []byte) (n int, err error) {
|
|||||||
d.saveBuf.Write(d.buf)
|
d.saveBuf.Write(d.buf)
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
d.firstField = false
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -389,6 +397,12 @@ func (d *Decoder) callEmit(hf HeaderField) error {
|
|||||||
|
|
||||||
// (same invariants and behavior as parseHeaderFieldRepr)
|
// (same invariants and behavior as parseHeaderFieldRepr)
|
||||||
func (d *Decoder) parseDynamicTableSizeUpdate() error {
|
func (d *Decoder) parseDynamicTableSizeUpdate() error {
|
||||||
|
// RFC 7541, sec 4.2: This dynamic table size update MUST occur at the
|
||||||
|
// beginning of the first header block following the change to the dynamic table size.
|
||||||
|
if !d.firstField && d.dynTab.size > 0 {
|
||||||
|
return DecodingError{errors.New("dynamic table size update MUST occur at the beginning of a header block")}
|
||||||
|
}
|
||||||
|
|
||||||
buf := d.buf
|
buf := d.buf
|
||||||
size, buf, err := readVarInt(5, buf)
|
size, buf, err := readVarInt(5, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
20
vendor/golang.org/x/net/http2/hpack/huffman.go
generated
vendored
20
vendor/golang.org/x/net/http2/hpack/huffman.go
generated
vendored
@@ -47,6 +47,7 @@ var ErrInvalidHuffman = errors.New("hpack: invalid Huffman-encoded data")
|
|||||||
// If maxLen is greater than 0, attempts to write more to buf than
|
// If maxLen is greater than 0, attempts to write more to buf than
|
||||||
// maxLen bytes will return ErrStringLength.
|
// maxLen bytes will return ErrStringLength.
|
||||||
func huffmanDecode(buf *bytes.Buffer, maxLen int, v []byte) error {
|
func huffmanDecode(buf *bytes.Buffer, maxLen int, v []byte) error {
|
||||||
|
rootHuffmanNode := getRootHuffmanNode()
|
||||||
n := rootHuffmanNode
|
n := rootHuffmanNode
|
||||||
// cur is the bit buffer that has not been fed into n.
|
// cur is the bit buffer that has not been fed into n.
|
||||||
// cbits is the number of low order bits in cur that are valid.
|
// cbits is the number of low order bits in cur that are valid.
|
||||||
@@ -106,7 +107,7 @@ func huffmanDecode(buf *bytes.Buffer, maxLen int, v []byte) error {
|
|||||||
|
|
||||||
type node struct {
|
type node struct {
|
||||||
// children is non-nil for internal nodes
|
// children is non-nil for internal nodes
|
||||||
children []*node
|
children *[256]*node
|
||||||
|
|
||||||
// The following are only valid if children is nil:
|
// The following are only valid if children is nil:
|
||||||
codeLen uint8 // number of bits that led to the output of sym
|
codeLen uint8 // number of bits that led to the output of sym
|
||||||
@@ -114,22 +115,31 @@ type node struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newInternalNode() *node {
|
func newInternalNode() *node {
|
||||||
return &node{children: make([]*node, 256)}
|
return &node{children: new([256]*node)}
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootHuffmanNode = newInternalNode()
|
var (
|
||||||
|
buildRootOnce sync.Once
|
||||||
|
lazyRootHuffmanNode *node
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func getRootHuffmanNode() *node {
|
||||||
|
buildRootOnce.Do(buildRootHuffmanNode)
|
||||||
|
return lazyRootHuffmanNode
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildRootHuffmanNode() {
|
||||||
if len(huffmanCodes) != 256 {
|
if len(huffmanCodes) != 256 {
|
||||||
panic("unexpected size")
|
panic("unexpected size")
|
||||||
}
|
}
|
||||||
|
lazyRootHuffmanNode = newInternalNode()
|
||||||
for i, code := range huffmanCodes {
|
for i, code := range huffmanCodes {
|
||||||
addDecoderNode(byte(i), code, huffmanCodeLen[i])
|
addDecoderNode(byte(i), code, huffmanCodeLen[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addDecoderNode(sym byte, code uint32, codeLen uint8) {
|
func addDecoderNode(sym byte, code uint32, codeLen uint8) {
|
||||||
cur := rootHuffmanNode
|
cur := lazyRootHuffmanNode
|
||||||
for codeLen > 8 {
|
for codeLen > 8 {
|
||||||
codeLen -= 8
|
codeLen -= 8
|
||||||
i := uint8(code >> codeLen)
|
i := uint8(code >> codeLen)
|
||||||
|
|||||||
25
vendor/golang.org/x/net/http2/http2.go
generated
vendored
25
vendor/golang.org/x/net/http2/http2.go
generated
vendored
@@ -29,7 +29,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/net/lex/httplex"
|
"golang.org/x/net/http/httpguts"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -179,7 +179,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
|
||||||
@@ -191,7 +191,7 @@ func validWireHeaderFieldName(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' {
|
||||||
@@ -201,19 +201,12 @@ func validWireHeaderFieldName(v string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
var httpCodeStringCommon = map[int]string{} // n -> strconv.Itoa(n)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
for i := 100; i <= 999; i++ {
|
|
||||||
if v := http.StatusText(i); v != "" {
|
|
||||||
httpCodeStringCommon[i] = strconv.Itoa(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func httpCodeString(code int) string {
|
func httpCodeString(code int) string {
|
||||||
if s, ok := httpCodeStringCommon[code]; ok {
|
switch code {
|
||||||
return s
|
case 200:
|
||||||
|
return "200"
|
||||||
|
case 404:
|
||||||
|
return "404"
|
||||||
}
|
}
|
||||||
return strconv.Itoa(code)
|
return strconv.Itoa(code)
|
||||||
}
|
}
|
||||||
@@ -312,7 +305,7 @@ func mustUint31(v int32) uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// bodyAllowedForStatus reports whether a given response status code
|
// bodyAllowedForStatus reports whether a given response status code
|
||||||
// permits a body. See RFC 2616, section 4.4.
|
// permits a body. See RFC 7230, section 3.3.
|
||||||
func bodyAllowedForStatus(status int) bool {
|
func bodyAllowedForStatus(status int) bool {
|
||||||
switch {
|
switch {
|
||||||
case status >= 100 && status <= 199:
|
case status >= 100 && status <= 199:
|
||||||
|
|||||||
20
vendor/golang.org/x/net/http2/not_go111.go
generated
vendored
Normal file
20
vendor/golang.org/x/net/http2/not_go111.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2018 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.
|
||||||
|
|
||||||
|
// +build !go1.11
|
||||||
|
|
||||||
|
package http2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http/httptrace"
|
||||||
|
"net/textproto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func traceHasWroteHeaderField(trace *httptrace.ClientTrace) bool { return false }
|
||||||
|
|
||||||
|
func traceWroteHeaderField(trace *httptrace.ClientTrace, k, v string) {}
|
||||||
|
|
||||||
|
func traceGot1xxResponseFunc(trace *httptrace.ClientTrace) func(int, textproto.MIMEHeader) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
21
vendor/golang.org/x/net/http2/not_go16.go
generated
vendored
21
vendor/golang.org/x/net/http2/not_go16.go
generated
vendored
@@ -1,21 +0,0 @@
|
|||||||
// Copyright 2015 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.
|
|
||||||
|
|
||||||
// +build !go1.6
|
|
||||||
|
|
||||||
package http2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func configureTransport(t1 *http.Transport) (*Transport, error) {
|
|
||||||
return nil, errTransportVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
func transportExpectContinueTimeout(t1 *http.Transport) time.Duration {
|
|
||||||
return 0
|
|
||||||
|
|
||||||
}
|
|
||||||
87
vendor/golang.org/x/net/http2/not_go17.go
generated
vendored
87
vendor/golang.org/x/net/http2/not_go17.go
generated
vendored
@@ -1,87 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
// +build !go1.7
|
|
||||||
|
|
||||||
package http2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type contextContext interface {
|
|
||||||
Done() <-chan struct{}
|
|
||||||
Err() error
|
|
||||||
}
|
|
||||||
|
|
||||||
type fakeContext struct{}
|
|
||||||
|
|
||||||
func (fakeContext) Done() <-chan struct{} { return nil }
|
|
||||||
func (fakeContext) Err() error { panic("should not be called") }
|
|
||||||
|
|
||||||
func reqContext(r *http.Request) fakeContext {
|
|
||||||
return fakeContext{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setResponseUncompressed(res *http.Response) {
|
|
||||||
// Nothing.
|
|
||||||
}
|
|
||||||
|
|
||||||
type clientTrace struct{}
|
|
||||||
|
|
||||||
func requestTrace(*http.Request) *clientTrace { return nil }
|
|
||||||
func traceGotConn(*http.Request, *ClientConn) {}
|
|
||||||
func traceFirstResponseByte(*clientTrace) {}
|
|
||||||
func traceWroteHeaders(*clientTrace) {}
|
|
||||||
func traceWroteRequest(*clientTrace, error) {}
|
|
||||||
func traceGot100Continue(trace *clientTrace) {}
|
|
||||||
func traceWait100Continue(trace *clientTrace) {}
|
|
||||||
|
|
||||||
func nop() {}
|
|
||||||
|
|
||||||
func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx contextContext, cancel func()) {
|
|
||||||
return nil, nop
|
|
||||||
}
|
|
||||||
|
|
||||||
func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) {
|
|
||||||
return ctx, nop
|
|
||||||
}
|
|
||||||
|
|
||||||
func requestWithContext(req *http.Request, ctx contextContext) *http.Request {
|
|
||||||
return req
|
|
||||||
}
|
|
||||||
|
|
||||||
// temporary copy of Go 1.6's private tls.Config.clone:
|
|
||||||
func cloneTLSConfig(c *tls.Config) *tls.Config {
|
|
||||||
return &tls.Config{
|
|
||||||
Rand: c.Rand,
|
|
||||||
Time: c.Time,
|
|
||||||
Certificates: c.Certificates,
|
|
||||||
NameToCertificate: c.NameToCertificate,
|
|
||||||
GetCertificate: c.GetCertificate,
|
|
||||||
RootCAs: c.RootCAs,
|
|
||||||
NextProtos: c.NextProtos,
|
|
||||||
ServerName: c.ServerName,
|
|
||||||
ClientAuth: c.ClientAuth,
|
|
||||||
ClientCAs: c.ClientCAs,
|
|
||||||
InsecureSkipVerify: c.InsecureSkipVerify,
|
|
||||||
CipherSuites: c.CipherSuites,
|
|
||||||
PreferServerCipherSuites: c.PreferServerCipherSuites,
|
|
||||||
SessionTicketsDisabled: c.SessionTicketsDisabled,
|
|
||||||
SessionTicketKey: c.SessionTicketKey,
|
|
||||||
ClientSessionCache: c.ClientSessionCache,
|
|
||||||
MinVersion: c.MinVersion,
|
|
||||||
MaxVersion: c.MaxVersion,
|
|
||||||
CurvePreferences: c.CurvePreferences,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cc *ClientConn) Ping(ctx contextContext) error {
|
|
||||||
return cc.ping(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Transport) idleConnTimeout() time.Duration { return 0 }
|
|
||||||
29
vendor/golang.org/x/net/http2/not_go18.go
generated
vendored
29
vendor/golang.org/x/net/http2/not_go18.go
generated
vendored
@@ -1,29 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
// +build !go1.8
|
|
||||||
|
|
||||||
package http2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func configureServer18(h1 *http.Server, h2 *Server) error {
|
|
||||||
// No IdleTimeout to sync prior to Go 1.8.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func shouldLogPanic(panicValue interface{}) bool {
|
|
||||||
return panicValue != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func reqGetBody(req *http.Request) func() (io.ReadCloser, error) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func reqBodyIsNoBody(io.ReadCloser) bool { return false }
|
|
||||||
|
|
||||||
func go18httpNoBody() io.ReadCloser { return nil } // for tests only
|
|
||||||
16
vendor/golang.org/x/net/http2/not_go19.go
generated
vendored
16
vendor/golang.org/x/net/http2/not_go19.go
generated
vendored
@@ -1,16 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
// +build !go1.9
|
|
||||||
|
|
||||||
package http2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func configureServer19(s *http.Server, conf *Server) error {
|
|
||||||
// not supported prior to go1.9
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
212
vendor/golang.org/x/net/http2/server.go
generated
vendored
212
vendor/golang.org/x/net/http2/server.go
generated
vendored
@@ -28,6 +28,7 @@ package http2
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -46,6 +47,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/http/httpguts"
|
||||||
"golang.org/x/net/http2/hpack"
|
"golang.org/x/net/http2/hpack"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -208,24 +210,29 @@ func ConfigureServer(s *http.Server, conf *Server) error {
|
|||||||
conf = new(Server)
|
conf = new(Server)
|
||||||
}
|
}
|
||||||
conf.state = &serverInternalState{activeConns: make(map[*serverConn]struct{})}
|
conf.state = &serverInternalState{activeConns: make(map[*serverConn]struct{})}
|
||||||
if err := configureServer18(s, conf); err != nil {
|
if h1, h2 := s, conf; h2.IdleTimeout == 0 {
|
||||||
return err
|
if h1.IdleTimeout != 0 {
|
||||||
}
|
h2.IdleTimeout = h1.IdleTimeout
|
||||||
if err := configureServer19(s, conf); err != nil {
|
} else {
|
||||||
return err
|
h2.IdleTimeout = h1.ReadTimeout
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
s.RegisterOnShutdown(conf.state.startGracefulShutdown)
|
||||||
|
|
||||||
if s.TLSConfig == nil {
|
if s.TLSConfig == nil {
|
||||||
s.TLSConfig = new(tls.Config)
|
s.TLSConfig = new(tls.Config)
|
||||||
} else if s.TLSConfig.CipherSuites != nil {
|
} else if s.TLSConfig.CipherSuites != nil {
|
||||||
// If they already provided a CipherSuite list, return
|
// If they already provided a CipherSuite list, return
|
||||||
// an error if it has a bad order or is missing
|
// an error if it has a bad order or is missing
|
||||||
// ECDHE_RSA_WITH_AES_128_GCM_SHA256.
|
// ECDHE_RSA_WITH_AES_128_GCM_SHA256 or ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.
|
||||||
const requiredCipher = tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
|
|
||||||
haveRequired := false
|
haveRequired := false
|
||||||
sawBad := false
|
sawBad := false
|
||||||
for i, cs := range s.TLSConfig.CipherSuites {
|
for i, cs := range s.TLSConfig.CipherSuites {
|
||||||
if cs == requiredCipher {
|
switch cs {
|
||||||
|
case tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||||
|
// Alternative MTI cipher to not discourage ECDSA-only servers.
|
||||||
|
// See http://golang.org/cl/30721 for further information.
|
||||||
|
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:
|
||||||
haveRequired = true
|
haveRequired = true
|
||||||
}
|
}
|
||||||
if isBadCipher(cs) {
|
if isBadCipher(cs) {
|
||||||
@@ -235,7 +242,7 @@ func ConfigureServer(s *http.Server, conf *Server) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !haveRequired {
|
if !haveRequired {
|
||||||
return fmt.Errorf("http2: TLSConfig.CipherSuites is missing HTTP/2-required TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256")
|
return fmt.Errorf("http2: TLSConfig.CipherSuites is missing an HTTP/2-required AES_128_GCM_SHA256 cipher.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,7 +410,7 @@ func (s *Server) ServeConn(c net.Conn, opts *ServeConnOpts) {
|
|||||||
// addresses during development.
|
// addresses during development.
|
||||||
//
|
//
|
||||||
// TODO: optionally enforce? Or enforce at the time we receive
|
// TODO: optionally enforce? Or enforce at the time we receive
|
||||||
// a new request, and verify the the ServerName matches the :authority?
|
// a new request, and verify the ServerName matches the :authority?
|
||||||
// But that precludes proxy situations, perhaps.
|
// But that precludes proxy situations, perhaps.
|
||||||
//
|
//
|
||||||
// So for now, do nothing here again.
|
// So for now, do nothing here again.
|
||||||
@@ -431,6 +438,15 @@ func (s *Server) ServeConn(c net.Conn, opts *ServeConnOpts) {
|
|||||||
sc.serve()
|
sc.serve()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx context.Context, cancel func()) {
|
||||||
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
|
ctx = context.WithValue(ctx, http.LocalAddrContextKey, c.LocalAddr())
|
||||||
|
if hs := opts.baseConfig(); hs != nil {
|
||||||
|
ctx = context.WithValue(ctx, http.ServerContextKey, hs)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (sc *serverConn) rejectConn(err ErrCode, debug string) {
|
func (sc *serverConn) rejectConn(err ErrCode, debug string) {
|
||||||
sc.vlogf("http2: server rejecting conn: %v, %s", err, debug)
|
sc.vlogf("http2: server rejecting conn: %v, %s", err, debug)
|
||||||
// ignoring errors. hanging up anyway.
|
// ignoring errors. hanging up anyway.
|
||||||
@@ -446,7 +462,7 @@ type serverConn struct {
|
|||||||
conn net.Conn
|
conn net.Conn
|
||||||
bw *bufferedWriter // writing to conn
|
bw *bufferedWriter // writing to conn
|
||||||
handler http.Handler
|
handler http.Handler
|
||||||
baseCtx contextContext
|
baseCtx context.Context
|
||||||
framer *Framer
|
framer *Framer
|
||||||
doneServing chan struct{} // closed when serverConn.serve ends
|
doneServing chan struct{} // closed when serverConn.serve ends
|
||||||
readFrameCh chan readFrameResult // written by serverConn.readFrames
|
readFrameCh chan readFrameResult // written by serverConn.readFrames
|
||||||
@@ -526,7 +542,7 @@ type stream struct {
|
|||||||
id uint32
|
id uint32
|
||||||
body *pipe // non-nil if expecting DATA frames
|
body *pipe // non-nil if expecting DATA frames
|
||||||
cw closeWaiter // closed wait stream transitions to closed state
|
cw closeWaiter // closed wait stream transitions to closed state
|
||||||
ctx contextContext
|
ctx context.Context
|
||||||
cancelCtx func()
|
cancelCtx func()
|
||||||
|
|
||||||
// owned by serverConn's serve loop:
|
// owned by serverConn's serve loop:
|
||||||
@@ -649,7 +665,7 @@ func (sc *serverConn) condlogf(err error, format string, args ...interface{}) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err == io.EOF || err == io.ErrUnexpectedEOF || isClosedConnError(err) {
|
if err == io.EOF || err == io.ErrUnexpectedEOF || isClosedConnError(err) || err == errPrefaceTimeout {
|
||||||
// Boring, expected errors.
|
// Boring, expected errors.
|
||||||
sc.vlogf(format, args...)
|
sc.vlogf(format, args...)
|
||||||
} else {
|
} else {
|
||||||
@@ -659,6 +675,7 @@ func (sc *serverConn) condlogf(err error, format string, args ...interface{}) {
|
|||||||
|
|
||||||
func (sc *serverConn) canonicalHeader(v string) string {
|
func (sc *serverConn) canonicalHeader(v string) string {
|
||||||
sc.serveG.check()
|
sc.serveG.check()
|
||||||
|
buildCommonHeaderMapsOnce()
|
||||||
cv, ok := commonCanonHeader[v]
|
cv, ok := commonCanonHeader[v]
|
||||||
if ok {
|
if ok {
|
||||||
return cv
|
return cv
|
||||||
@@ -853,8 +870,13 @@ func (sc *serverConn) serve() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sc.inGoAway && sc.curOpenStreams() == 0 && !sc.needToSendGoAway && !sc.writingFrame {
|
// Start the shutdown timer after sending a GOAWAY. When sending GOAWAY
|
||||||
return
|
// with no error code (graceful shutdown), don't start the timer until
|
||||||
|
// all open streams have been completed.
|
||||||
|
sentGoAway := sc.inGoAway && !sc.needToSendGoAway && !sc.writingFrame
|
||||||
|
gracefulShutdownComplete := sc.goAwayCode == ErrCodeNo && sc.curOpenStreams() == 0
|
||||||
|
if sentGoAway && sc.shutdownTimer == nil && (sc.goAwayCode != ErrCodeNo || gracefulShutdownComplete) {
|
||||||
|
sc.shutDownIn(goAwayTimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -889,8 +911,11 @@ func (sc *serverConn) sendServeMsg(msg interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// readPreface reads the ClientPreface greeting from the peer
|
var errPrefaceTimeout = errors.New("timeout waiting for client preface")
|
||||||
// or returns an error on timeout or an invalid greeting.
|
|
||||||
|
// readPreface reads the ClientPreface greeting from the peer or
|
||||||
|
// returns errPrefaceTimeout on timeout, or an error if the greeting
|
||||||
|
// is invalid.
|
||||||
func (sc *serverConn) readPreface() error {
|
func (sc *serverConn) readPreface() error {
|
||||||
errc := make(chan error, 1)
|
errc := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
@@ -908,7 +933,7 @@ func (sc *serverConn) readPreface() error {
|
|||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
select {
|
select {
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
return errors.New("timeout waiting for client preface")
|
return errPrefaceTimeout
|
||||||
case err := <-errc:
|
case err := <-errc:
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if VerboseLogs {
|
if VerboseLogs {
|
||||||
@@ -1097,7 +1122,7 @@ func (sc *serverConn) startFrameWrite(wr FrameWriteRequest) {
|
|||||||
|
|
||||||
// errHandlerPanicked is the error given to any callers blocked in a read from
|
// errHandlerPanicked is the error given to any callers blocked in a read from
|
||||||
// Request.Body when the main goroutine panics. Since most handlers read in the
|
// Request.Body when the main goroutine panics. Since most handlers read in the
|
||||||
// the main ServeHTTP goroutine, this will show up rarely.
|
// main ServeHTTP goroutine, this will show up rarely.
|
||||||
var errHandlerPanicked = errors.New("http2: handler panicked")
|
var errHandlerPanicked = errors.New("http2: handler panicked")
|
||||||
|
|
||||||
// wroteFrame is called on the serve goroutine with the result of
|
// wroteFrame is called on the serve goroutine with the result of
|
||||||
@@ -1218,30 +1243,31 @@ func (sc *serverConn) startGracefulShutdown() {
|
|||||||
sc.shutdownOnce.Do(func() { sc.sendServeMsg(gracefulShutdownMsg) })
|
sc.shutdownOnce.Do(func() { sc.sendServeMsg(gracefulShutdownMsg) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// After sending GOAWAY, the connection will close after goAwayTimeout.
|
||||||
|
// If we close the connection immediately after sending GOAWAY, there may
|
||||||
|
// be unsent data in our kernel receive buffer, which will cause the kernel
|
||||||
|
// to send a TCP RST on close() instead of a FIN. This RST will abort the
|
||||||
|
// connection immediately, whether or not the client had received the GOAWAY.
|
||||||
|
//
|
||||||
|
// Ideally we should delay for at least 1 RTT + epsilon so the client has
|
||||||
|
// a chance to read the GOAWAY and stop sending messages. Measuring RTT
|
||||||
|
// is hard, so we approximate with 1 second. See golang.org/issue/18701.
|
||||||
|
//
|
||||||
|
// This is a var so it can be shorter in tests, where all requests uses the
|
||||||
|
// loopback interface making the expected RTT very small.
|
||||||
|
//
|
||||||
|
// TODO: configurable?
|
||||||
|
var goAwayTimeout = 1 * time.Second
|
||||||
|
|
||||||
func (sc *serverConn) startGracefulShutdownInternal() {
|
func (sc *serverConn) startGracefulShutdownInternal() {
|
||||||
sc.goAwayIn(ErrCodeNo, 0)
|
sc.goAway(ErrCodeNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *serverConn) goAway(code ErrCode) {
|
func (sc *serverConn) goAway(code ErrCode) {
|
||||||
sc.serveG.check()
|
|
||||||
var forceCloseIn time.Duration
|
|
||||||
if code != ErrCodeNo {
|
|
||||||
forceCloseIn = 250 * time.Millisecond
|
|
||||||
} else {
|
|
||||||
// TODO: configurable
|
|
||||||
forceCloseIn = 1 * time.Second
|
|
||||||
}
|
|
||||||
sc.goAwayIn(code, forceCloseIn)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sc *serverConn) goAwayIn(code ErrCode, forceCloseIn time.Duration) {
|
|
||||||
sc.serveG.check()
|
sc.serveG.check()
|
||||||
if sc.inGoAway {
|
if sc.inGoAway {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if forceCloseIn != 0 {
|
|
||||||
sc.shutDownIn(forceCloseIn)
|
|
||||||
}
|
|
||||||
sc.inGoAway = true
|
sc.inGoAway = true
|
||||||
sc.needToSendGoAway = true
|
sc.needToSendGoAway = true
|
||||||
sc.goAwayCode = code
|
sc.goAwayCode = code
|
||||||
@@ -1474,6 +1500,12 @@ func (sc *serverConn) processSettings(f *SettingsFrame) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if f.NumSettings() > 100 || f.HasDuplicates() {
|
||||||
|
// This isn't actually in the spec, but hang up on
|
||||||
|
// suspiciously large settings frames or those with
|
||||||
|
// duplicate entries.
|
||||||
|
return ConnectionError(ErrCodeProtocol)
|
||||||
|
}
|
||||||
if err := f.ForeachSetting(sc.processSetting); err != nil {
|
if err := f.ForeachSetting(sc.processSetting); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1595,7 +1627,10 @@ func (sc *serverConn) processData(f *DataFrame) error {
|
|||||||
// Sender sending more than they'd declared?
|
// Sender sending more than they'd declared?
|
||||||
if st.declBodyBytes != -1 && st.bodyBytes+int64(len(data)) > st.declBodyBytes {
|
if st.declBodyBytes != -1 && st.bodyBytes+int64(len(data)) > st.declBodyBytes {
|
||||||
st.body.CloseWithError(fmt.Errorf("sender tried to send more than declared Content-Length of %d bytes", st.declBodyBytes))
|
st.body.CloseWithError(fmt.Errorf("sender tried to send more than declared Content-Length of %d bytes", st.declBodyBytes))
|
||||||
return streamError(id, ErrCodeStreamClosed)
|
// RFC 7540, sec 8.1.2.6: A request or response is also malformed if the
|
||||||
|
// value of a content-length header field does not equal the sum of the
|
||||||
|
// DATA frame payload lengths that form the body.
|
||||||
|
return streamError(id, ErrCodeProtocol)
|
||||||
}
|
}
|
||||||
if f.Length > 0 {
|
if f.Length > 0 {
|
||||||
// Check whether the client has flow control quota.
|
// Check whether the client has flow control quota.
|
||||||
@@ -1705,6 +1740,13 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
|
|||||||
// processing this frame.
|
// processing this frame.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// RFC 7540, sec 5.1: If an endpoint receives additional frames, other than
|
||||||
|
// WINDOW_UPDATE, PRIORITY, or RST_STREAM, for a stream that is in
|
||||||
|
// this state, it MUST respond with a stream error (Section 5.4.2) of
|
||||||
|
// type STREAM_CLOSED.
|
||||||
|
if st.state == stateHalfClosedRemote {
|
||||||
|
return streamError(id, ErrCodeStreamClosed)
|
||||||
|
}
|
||||||
return st.processTrailerHeaders(f)
|
return st.processTrailerHeaders(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1805,7 +1847,7 @@ func (st *stream) processTrailerHeaders(f *MetaHeadersFrame) error {
|
|||||||
if st.trailer != nil {
|
if st.trailer != nil {
|
||||||
for _, hf := range f.RegularFields() {
|
for _, hf := range f.RegularFields() {
|
||||||
key := sc.canonicalHeader(hf.Name)
|
key := sc.canonicalHeader(hf.Name)
|
||||||
if !ValidTrailerHeader(key) {
|
if !httpguts.ValidTrailerHeader(key) {
|
||||||
// TODO: send more details to the peer somehow. But http2 has
|
// TODO: send more details to the peer somehow. But http2 has
|
||||||
// no way to send debug data at a stream level. Discuss with
|
// no way to send debug data at a stream level. Discuss with
|
||||||
// HTTP folk.
|
// HTTP folk.
|
||||||
@@ -1846,7 +1888,7 @@ func (sc *serverConn) newStream(id, pusherID uint32, state streamState) *stream
|
|||||||
panic("internal error: cannot create stream with id 0")
|
panic("internal error: cannot create stream with id 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancelCtx := contextWithCancel(sc.baseCtx)
|
ctx, cancelCtx := context.WithCancel(sc.baseCtx)
|
||||||
st := &stream{
|
st := &stream{
|
||||||
sc: sc,
|
sc: sc,
|
||||||
id: id,
|
id: id,
|
||||||
@@ -2012,7 +2054,7 @@ func (sc *serverConn) newWriterAndRequestNoBody(st *stream, rp requestParam) (*r
|
|||||||
Body: body,
|
Body: body,
|
||||||
Trailer: trailer,
|
Trailer: trailer,
|
||||||
}
|
}
|
||||||
req = requestWithContext(req, st.ctx)
|
req = req.WithContext(st.ctx)
|
||||||
|
|
||||||
rws := responseWriterStatePool.Get().(*responseWriterState)
|
rws := responseWriterStatePool.Get().(*responseWriterState)
|
||||||
bwSave := rws.bw
|
bwSave := rws.bw
|
||||||
@@ -2040,7 +2082,7 @@ func (sc *serverConn) runHandler(rw *responseWriter, req *http.Request, handler
|
|||||||
stream: rw.rws.stream,
|
stream: rw.rws.stream,
|
||||||
})
|
})
|
||||||
// Same as net/http:
|
// Same as net/http:
|
||||||
if shouldLogPanic(e) {
|
if e != nil && e != http.ErrAbortHandler {
|
||||||
const size = 64 << 10
|
const size = 64 << 10
|
||||||
buf := make([]byte, size)
|
buf := make([]byte, size)
|
||||||
buf = buf[:runtime.Stack(buf, false)]
|
buf = buf[:runtime.Stack(buf, false)]
|
||||||
@@ -2272,8 +2314,8 @@ func (rws *responseWriterState) hasTrailers() bool { return len(rws.trailers) !=
|
|||||||
// written in the trailers at the end of the response.
|
// written in the trailers at the end of the response.
|
||||||
func (rws *responseWriterState) declareTrailer(k string) {
|
func (rws *responseWriterState) declareTrailer(k string) {
|
||||||
k = http.CanonicalHeaderKey(k)
|
k = http.CanonicalHeaderKey(k)
|
||||||
if !ValidTrailerHeader(k) {
|
if !httpguts.ValidTrailerHeader(k) {
|
||||||
// Forbidden by RFC 2616 14.40.
|
// Forbidden by RFC 7230, section 4.1.2.
|
||||||
rws.conn.logf("ignoring invalid trailer %q", k)
|
rws.conn.logf("ignoring invalid trailer %q", k)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -2310,7 +2352,7 @@ func (rws *responseWriterState) writeChunk(p []byte) (n int, err error) {
|
|||||||
clen = strconv.Itoa(len(p))
|
clen = strconv.Itoa(len(p))
|
||||||
}
|
}
|
||||||
_, hasContentType := rws.snapHeader["Content-Type"]
|
_, hasContentType := rws.snapHeader["Content-Type"]
|
||||||
if !hasContentType && bodyAllowedForStatus(rws.status) {
|
if !hasContentType && bodyAllowedForStatus(rws.status) && len(p) > 0 {
|
||||||
ctype = http.DetectContentType(p)
|
ctype = http.DetectContentType(p)
|
||||||
}
|
}
|
||||||
var date string
|
var date string
|
||||||
@@ -2323,6 +2365,19 @@ func (rws *responseWriterState) writeChunk(p []byte) (n int, err error) {
|
|||||||
foreachHeaderElement(v, rws.declareTrailer)
|
foreachHeaderElement(v, rws.declareTrailer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "Connection" headers aren't allowed in HTTP/2 (RFC 7540, 8.1.2.2),
|
||||||
|
// but respect "Connection" == "close" to mean sending a GOAWAY and tearing
|
||||||
|
// down the TCP connection when idle, like we do for HTTP/1.
|
||||||
|
// TODO: remove more Connection-specific header fields here, in addition
|
||||||
|
// to "Connection".
|
||||||
|
if _, ok := rws.snapHeader["Connection"]; ok {
|
||||||
|
v := rws.snapHeader.Get("Connection")
|
||||||
|
delete(rws.snapHeader, "Connection")
|
||||||
|
if v == "close" {
|
||||||
|
rws.conn.startGracefulShutdown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
endStream := (rws.handlerDone && !rws.hasTrailers() && len(p) == 0) || isHeadResp
|
endStream := (rws.handlerDone && !rws.hasTrailers() && len(p) == 0) || isHeadResp
|
||||||
err = rws.conn.writeHeaders(rws.stream, &writeResHeaders{
|
err = rws.conn.writeHeaders(rws.stream, &writeResHeaders{
|
||||||
streamID: rws.stream.id,
|
streamID: rws.stream.id,
|
||||||
@@ -2394,7 +2449,7 @@ const TrailerPrefix = "Trailer:"
|
|||||||
// after the header has already been flushed. Because the Go
|
// after the header has already been flushed. Because the Go
|
||||||
// ResponseWriter interface has no way to set Trailers (only the
|
// ResponseWriter interface has no way to set Trailers (only the
|
||||||
// Header), and because we didn't want to expand the ResponseWriter
|
// Header), and because we didn't want to expand the ResponseWriter
|
||||||
// interface, and because nobody used trailers, and because RFC 2616
|
// interface, and because nobody used trailers, and because RFC 7230
|
||||||
// says you SHOULD (but not must) predeclare any trailers in the
|
// says you SHOULD (but not must) predeclare any trailers in the
|
||||||
// header, the official ResponseWriter rules said trailers in Go must
|
// header, the official ResponseWriter rules said trailers in Go must
|
||||||
// be predeclared, and then we reuse the same ResponseWriter.Header()
|
// be predeclared, and then we reuse the same ResponseWriter.Header()
|
||||||
@@ -2478,6 +2533,24 @@ func (w *responseWriter) Header() http.Header {
|
|||||||
return rws.handlerHeader
|
return rws.handlerHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkWriteHeaderCode is a copy of net/http's checkWriteHeaderCode.
|
||||||
|
func checkWriteHeaderCode(code int) {
|
||||||
|
// Issue 22880: require valid WriteHeader status codes.
|
||||||
|
// For now we only enforce that it's three digits.
|
||||||
|
// In the future we might block things over 599 (600 and above aren't defined
|
||||||
|
// at http://httpwg.org/specs/rfc7231.html#status.codes)
|
||||||
|
// and we might block under 200 (once we have more mature 1xx support).
|
||||||
|
// But for now any three digits.
|
||||||
|
//
|
||||||
|
// We used to send "HTTP/1.1 000 0" on the wire in responses but there's
|
||||||
|
// no equivalent bogus thing we can realistically send in HTTP/2,
|
||||||
|
// so we'll consistently panic instead and help people find their bugs
|
||||||
|
// early. (We can't return an error from WriteHeader even if we wanted to.)
|
||||||
|
if code < 100 || code > 999 {
|
||||||
|
panic(fmt.Sprintf("invalid WriteHeader code %v", code))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w *responseWriter) WriteHeader(code int) {
|
func (w *responseWriter) WriteHeader(code int) {
|
||||||
rws := w.rws
|
rws := w.rws
|
||||||
if rws == nil {
|
if rws == nil {
|
||||||
@@ -2488,6 +2561,7 @@ func (w *responseWriter) WriteHeader(code int) {
|
|||||||
|
|
||||||
func (rws *responseWriterState) writeHeader(code int) {
|
func (rws *responseWriterState) writeHeader(code int) {
|
||||||
if !rws.wroteHeader {
|
if !rws.wroteHeader {
|
||||||
|
checkWriteHeaderCode(code)
|
||||||
rws.wroteHeader = true
|
rws.wroteHeader = true
|
||||||
rws.status = code
|
rws.status = code
|
||||||
if len(rws.handlerHeader) > 0 {
|
if len(rws.handlerHeader) > 0 {
|
||||||
@@ -2570,14 +2644,9 @@ var (
|
|||||||
ErrPushLimitReached = errors.New("http2: push would exceed peer's SETTINGS_MAX_CONCURRENT_STREAMS")
|
ErrPushLimitReached = errors.New("http2: push would exceed peer's SETTINGS_MAX_CONCURRENT_STREAMS")
|
||||||
)
|
)
|
||||||
|
|
||||||
// pushOptions is the internal version of http.PushOptions, which we
|
var _ http.Pusher = (*responseWriter)(nil)
|
||||||
// cannot include here because it's only defined in Go 1.8 and later.
|
|
||||||
type pushOptions struct {
|
|
||||||
Method string
|
|
||||||
Header http.Header
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *responseWriter) push(target string, opts pushOptions) error {
|
func (w *responseWriter) Push(target string, opts *http.PushOptions) error {
|
||||||
st := w.rws.stream
|
st := w.rws.stream
|
||||||
sc := st.sc
|
sc := st.sc
|
||||||
sc.serveG.checkNotOn()
|
sc.serveG.checkNotOn()
|
||||||
@@ -2588,6 +2657,10 @@ func (w *responseWriter) push(target string, opts pushOptions) error {
|
|||||||
return ErrRecursivePush
|
return ErrRecursivePush
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts == nil {
|
||||||
|
opts = new(http.PushOptions)
|
||||||
|
}
|
||||||
|
|
||||||
// Default options.
|
// Default options.
|
||||||
if opts.Method == "" {
|
if opts.Method == "" {
|
||||||
opts.Method = "GET"
|
opts.Method = "GET"
|
||||||
@@ -2759,7 +2832,7 @@ func (sc *serverConn) startPush(msg *startPushRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// foreachHeaderElement splits v according to the "#rule" construction
|
// foreachHeaderElement splits v according to the "#rule" construction
|
||||||
// in RFC 2616 section 2.1 and calls fn for each non-empty element.
|
// in RFC 7230 section 7 and calls fn for each non-empty element.
|
||||||
func foreachHeaderElement(v string, fn func(string)) {
|
func foreachHeaderElement(v string, fn func(string)) {
|
||||||
v = textproto.TrimString(v)
|
v = textproto.TrimString(v)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
@@ -2807,41 +2880,6 @@ func new400Handler(err error) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidTrailerHeader reports whether name is a valid header field name to appear
|
|
||||||
// in trailers.
|
|
||||||
// See: http://tools.ietf.org/html/rfc7230#section-4.1.2
|
|
||||||
func ValidTrailerHeader(name string) bool {
|
|
||||||
name = http.CanonicalHeaderKey(name)
|
|
||||||
if strings.HasPrefix(name, "If-") || badTrailer[name] {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
var badTrailer = map[string]bool{
|
|
||||||
"Authorization": true,
|
|
||||||
"Cache-Control": true,
|
|
||||||
"Connection": true,
|
|
||||||
"Content-Encoding": true,
|
|
||||||
"Content-Length": true,
|
|
||||||
"Content-Range": true,
|
|
||||||
"Content-Type": true,
|
|
||||||
"Expect": true,
|
|
||||||
"Host": true,
|
|
||||||
"Keep-Alive": true,
|
|
||||||
"Max-Forwards": true,
|
|
||||||
"Pragma": true,
|
|
||||||
"Proxy-Authenticate": true,
|
|
||||||
"Proxy-Authorization": true,
|
|
||||||
"Proxy-Connection": true,
|
|
||||||
"Range": true,
|
|
||||||
"Realm": true,
|
|
||||||
"Te": true,
|
|
||||||
"Trailer": true,
|
|
||||||
"Transfer-Encoding": true,
|
|
||||||
"Www-Authenticate": true,
|
|
||||||
}
|
|
||||||
|
|
||||||
// h1ServerKeepAlivesDisabled reports whether hs has its keep-alives
|
// h1ServerKeepAlivesDisabled reports whether hs has its keep-alives
|
||||||
// disabled. See comments on h1ServerShutdownChan above for why
|
// disabled. See comments on h1ServerShutdownChan above for why
|
||||||
// the code is written this way.
|
// the code is written this way.
|
||||||
|
|||||||
772
vendor/golang.org/x/net/http2/transport.go
generated
vendored
772
vendor/golang.org/x/net/http2/transport.go
generated
vendored
File diff suppressed because it is too large
Load Diff
15
vendor/golang.org/x/net/http2/write.go
generated
vendored
15
vendor/golang.org/x/net/http2/write.go
generated
vendored
@@ -10,10 +10,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
|
||||||
|
|
||||||
|
"golang.org/x/net/http/httpguts"
|
||||||
"golang.org/x/net/http2/hpack"
|
"golang.org/x/net/http2/hpack"
|
||||||
"golang.org/x/net/lex/httplex"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// writeFramer is implemented by any type that is used to write frames.
|
// writeFramer is implemented by any type that is used to write frames.
|
||||||
@@ -90,11 +89,7 @@ type writeGoAway struct {
|
|||||||
|
|
||||||
func (p *writeGoAway) writeFrame(ctx writeContext) error {
|
func (p *writeGoAway) writeFrame(ctx writeContext) error {
|
||||||
err := ctx.Framer().WriteGoAway(p.maxStreamID, p.code, nil)
|
err := ctx.Framer().WriteGoAway(p.maxStreamID, p.code, nil)
|
||||||
if p.code != 0 {
|
ctx.Flush() // ignore error: we're hanging up on them anyway
|
||||||
ctx.Flush() // ignore error: we're hanging up on them anyway
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
ctx.CloseConn()
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +199,7 @@ func (w *writeResHeaders) staysWithinBuffer(max int) bool {
|
|||||||
// TODO: this is a common one. It'd be nice to return true
|
// TODO: this is a common one. It'd be nice to return true
|
||||||
// here and get into the fast path if we could be clever and
|
// here and get into the fast path if we could be clever and
|
||||||
// calculate the size fast enough, or at least a conservative
|
// calculate the size fast enough, or at least a conservative
|
||||||
// uppper bound that usually fires. (Maybe if w.h and
|
// upper bound that usually fires. (Maybe if w.h and
|
||||||
// w.trailers are nil, so we don't need to enumerate it.)
|
// w.trailers are nil, so we don't need to enumerate it.)
|
||||||
// Otherwise I'm afraid that just calculating the length to
|
// Otherwise I'm afraid that just calculating the length to
|
||||||
// answer this question would be slower than the ~2µs benefit.
|
// answer this question would be slower than the ~2µs benefit.
|
||||||
@@ -334,7 +329,7 @@ func (wu writeWindowUpdate) writeFrame(ctx writeContext) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// encodeHeaders encodes an http.Header. If keys is not nil, then (k, h[k])
|
// encodeHeaders encodes an http.Header. If keys is not nil, then (k, h[k])
|
||||||
// is encoded only only if k is in keys.
|
// is encoded only if k is in keys.
|
||||||
func encodeHeaders(enc *hpack.Encoder, h http.Header, keys []string) {
|
func encodeHeaders(enc *hpack.Encoder, h http.Header, keys []string) {
|
||||||
if keys == nil {
|
if keys == nil {
|
||||||
sorter := sorterPool.Get().(*sorter)
|
sorter := sorterPool.Get().(*sorter)
|
||||||
@@ -355,7 +350,7 @@ func encodeHeaders(enc *hpack.Encoder, h http.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
|
||||||
|
|||||||
126
vendor/golang.org/x/net/idna/idna.go
generated
vendored
126
vendor/golang.org/x/net/idna/idna.go
generated
vendored
@@ -21,6 +21,7 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"golang.org/x/text/secure/bidirule"
|
"golang.org/x/text/secure/bidirule"
|
||||||
|
"golang.org/x/text/unicode/bidi"
|
||||||
"golang.org/x/text/unicode/norm"
|
"golang.org/x/text/unicode/norm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ func VerifyDNSLength(verify bool) Option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveLeadingDots removes leading label separators. Leading runes that map to
|
// RemoveLeadingDots removes leading label separators. Leading runes that map to
|
||||||
// dots, such as U+3002, are removed as well.
|
// dots, such as U+3002 IDEOGRAPHIC FULL STOP, are removed as well.
|
||||||
//
|
//
|
||||||
// This is the behavior suggested by the UTS #46 and is adopted by some
|
// This is the behavior suggested by the UTS #46 and is adopted by some
|
||||||
// browsers.
|
// browsers.
|
||||||
@@ -92,7 +93,7 @@ func ValidateLabels(enable bool) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StrictDomainName limits the set of permissable ASCII characters to those
|
// StrictDomainName limits the set of permissible ASCII characters to those
|
||||||
// allowed in domain names as defined in RFC 1034 (A-Z, a-z, 0-9 and the
|
// allowed in domain names as defined in RFC 1034 (A-Z, a-z, 0-9 and the
|
||||||
// hyphen). This is set by default for MapForLookup and ValidateForRegistration.
|
// hyphen). This is set by default for MapForLookup and ValidateForRegistration.
|
||||||
//
|
//
|
||||||
@@ -142,7 +143,6 @@ func MapForLookup() Option {
|
|||||||
o.mapping = validateAndMap
|
o.mapping = validateAndMap
|
||||||
StrictDomainName(true)(o)
|
StrictDomainName(true)(o)
|
||||||
ValidateLabels(true)(o)
|
ValidateLabels(true)(o)
|
||||||
RemoveLeadingDots(true)(o)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,14 +160,14 @@ type options struct {
|
|||||||
|
|
||||||
// mapping implements a validation and mapping step as defined in RFC 5895
|
// mapping implements a validation and mapping step as defined in RFC 5895
|
||||||
// or UTS 46, tailored to, for example, domain registration or lookup.
|
// or UTS 46, tailored to, for example, domain registration or lookup.
|
||||||
mapping func(p *Profile, s string) (string, error)
|
mapping func(p *Profile, s string) (mapped string, isBidi bool, err error)
|
||||||
|
|
||||||
// bidirule, if specified, checks whether s conforms to the Bidi Rule
|
// bidirule, if specified, checks whether s conforms to the Bidi Rule
|
||||||
// defined in RFC 5893.
|
// defined in RFC 5893.
|
||||||
bidirule func(s string) bool
|
bidirule func(s string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Profile defines the configuration of a IDNA mapper.
|
// A Profile defines the configuration of an IDNA mapper.
|
||||||
type Profile struct {
|
type Profile struct {
|
||||||
options
|
options
|
||||||
}
|
}
|
||||||
@@ -251,23 +251,21 @@ var (
|
|||||||
|
|
||||||
punycode = &Profile{}
|
punycode = &Profile{}
|
||||||
lookup = &Profile{options{
|
lookup = &Profile{options{
|
||||||
transitional: true,
|
transitional: true,
|
||||||
useSTD3Rules: true,
|
useSTD3Rules: true,
|
||||||
validateLabels: true,
|
validateLabels: true,
|
||||||
removeLeadingDots: true,
|
trie: trie,
|
||||||
trie: trie,
|
fromPuny: validateFromPunycode,
|
||||||
fromPuny: validateFromPunycode,
|
mapping: validateAndMap,
|
||||||
mapping: validateAndMap,
|
bidirule: bidirule.ValidString,
|
||||||
bidirule: bidirule.ValidString,
|
|
||||||
}}
|
}}
|
||||||
display = &Profile{options{
|
display = &Profile{options{
|
||||||
useSTD3Rules: true,
|
useSTD3Rules: true,
|
||||||
validateLabels: true,
|
validateLabels: true,
|
||||||
removeLeadingDots: true,
|
trie: trie,
|
||||||
trie: trie,
|
fromPuny: validateFromPunycode,
|
||||||
fromPuny: validateFromPunycode,
|
mapping: validateAndMap,
|
||||||
mapping: validateAndMap,
|
bidirule: bidirule.ValidString,
|
||||||
bidirule: bidirule.ValidString,
|
|
||||||
}}
|
}}
|
||||||
registration = &Profile{options{
|
registration = &Profile{options{
|
||||||
useSTD3Rules: true,
|
useSTD3Rules: true,
|
||||||
@@ -302,14 +300,16 @@ func (e runeError) Error() string {
|
|||||||
// see http://www.unicode.org/reports/tr46.
|
// see http://www.unicode.org/reports/tr46.
|
||||||
func (p *Profile) process(s string, toASCII bool) (string, error) {
|
func (p *Profile) process(s string, toASCII bool) (string, error) {
|
||||||
var err error
|
var err error
|
||||||
|
var isBidi bool
|
||||||
if p.mapping != nil {
|
if p.mapping != nil {
|
||||||
s, err = p.mapping(p, s)
|
s, isBidi, err = p.mapping(p, s)
|
||||||
}
|
}
|
||||||
// Remove leading empty labels.
|
// Remove leading empty labels.
|
||||||
if p.removeLeadingDots {
|
if p.removeLeadingDots {
|
||||||
for ; len(s) > 0 && s[0] == '.'; s = s[1:] {
|
for ; len(s) > 0 && s[0] == '.'; s = s[1:] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: allow for a quick check of the tables data.
|
||||||
// It seems like we should only create this error on ToASCII, but the
|
// It seems like we should only create this error on ToASCII, but the
|
||||||
// UTS 46 conformance tests suggests we should always check this.
|
// UTS 46 conformance tests suggests we should always check this.
|
||||||
if err == nil && p.verifyDNSLength && s == "" {
|
if err == nil && p.verifyDNSLength && s == "" {
|
||||||
@@ -335,6 +335,7 @@ func (p *Profile) process(s string, toASCII bool) (string, error) {
|
|||||||
// Spec says keep the old label.
|
// Spec says keep the old label.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
isBidi = isBidi || bidirule.DirectionString(u) != bidi.LeftToRight
|
||||||
labels.set(u)
|
labels.set(u)
|
||||||
if err == nil && p.validateLabels {
|
if err == nil && p.validateLabels {
|
||||||
err = p.fromPuny(p, u)
|
err = p.fromPuny(p, u)
|
||||||
@@ -349,6 +350,14 @@ func (p *Profile) process(s string, toASCII bool) (string, error) {
|
|||||||
err = p.validateLabel(label)
|
err = p.validateLabel(label)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if isBidi && p.bidirule != nil && err == nil {
|
||||||
|
for labels.reset(); !labels.done(); labels.next() {
|
||||||
|
if !p.bidirule(labels.label()) {
|
||||||
|
err = &labelError{s, "B"}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if toASCII {
|
if toASCII {
|
||||||
for labels.reset(); !labels.done(); labels.next() {
|
for labels.reset(); !labels.done(); labels.next() {
|
||||||
label := labels.label()
|
label := labels.label()
|
||||||
@@ -380,16 +389,26 @@ func (p *Profile) process(s string, toASCII bool) (string, error) {
|
|||||||
return s, err
|
return s, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func normalize(p *Profile, s string) (string, error) {
|
func normalize(p *Profile, s string) (mapped string, isBidi bool, err error) {
|
||||||
return norm.NFC.String(s), nil
|
// TODO: consider first doing a quick check to see if any of these checks
|
||||||
|
// need to be done. This will make it slower in the general case, but
|
||||||
|
// faster in the common case.
|
||||||
|
mapped = norm.NFC.String(s)
|
||||||
|
isBidi = bidirule.DirectionString(mapped) == bidi.RightToLeft
|
||||||
|
return mapped, isBidi, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateRegistration(p *Profile, s string) (string, error) {
|
func validateRegistration(p *Profile, s string) (idem string, bidi bool, err error) {
|
||||||
|
// TODO: filter need for normalization in loop below.
|
||||||
if !norm.NFC.IsNormalString(s) {
|
if !norm.NFC.IsNormalString(s) {
|
||||||
return s, &labelError{s, "V1"}
|
return s, false, &labelError{s, "V1"}
|
||||||
}
|
}
|
||||||
for i := 0; i < len(s); {
|
for i := 0; i < len(s); {
|
||||||
v, sz := trie.lookupString(s[i:])
|
v, sz := trie.lookupString(s[i:])
|
||||||
|
if sz == 0 {
|
||||||
|
return s, bidi, runeError(utf8.RuneError)
|
||||||
|
}
|
||||||
|
bidi = bidi || info(v).isBidi(s[i:])
|
||||||
// Copy bytes not copied so far.
|
// Copy bytes not copied so far.
|
||||||
switch p.simplify(info(v).category()) {
|
switch p.simplify(info(v).category()) {
|
||||||
// TODO: handle the NV8 defined in the Unicode idna data set to allow
|
// TODO: handle the NV8 defined in the Unicode idna data set to allow
|
||||||
@@ -397,21 +416,50 @@ func validateRegistration(p *Profile, s string) (string, error) {
|
|||||||
case valid, deviation:
|
case valid, deviation:
|
||||||
case disallowed, mapped, unknown, ignored:
|
case disallowed, mapped, unknown, ignored:
|
||||||
r, _ := utf8.DecodeRuneInString(s[i:])
|
r, _ := utf8.DecodeRuneInString(s[i:])
|
||||||
return s, runeError(r)
|
return s, bidi, runeError(r)
|
||||||
}
|
}
|
||||||
i += sz
|
i += sz
|
||||||
}
|
}
|
||||||
return s, nil
|
return s, bidi, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateAndMap(p *Profile, s string) (string, error) {
|
func (c info) isBidi(s string) bool {
|
||||||
|
if !c.isMapped() {
|
||||||
|
return c&attributesMask == rtl
|
||||||
|
}
|
||||||
|
// TODO: also store bidi info for mapped data. This is possible, but a bit
|
||||||
|
// cumbersome and not for the common case.
|
||||||
|
p, _ := bidi.LookupString(s)
|
||||||
|
switch p.Class() {
|
||||||
|
case bidi.R, bidi.AL, bidi.AN:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateAndMap(p *Profile, s string) (vm string, bidi bool, err error) {
|
||||||
var (
|
var (
|
||||||
err error
|
b []byte
|
||||||
b []byte
|
k int
|
||||||
k int
|
|
||||||
)
|
)
|
||||||
|
// combinedInfoBits contains the or-ed bits of all runes. We use this
|
||||||
|
// to derive the mayNeedNorm bit later. This may trigger normalization
|
||||||
|
// overeagerly, but it will not do so in the common case. The end result
|
||||||
|
// is another 10% saving on BenchmarkProfile for the common case.
|
||||||
|
var combinedInfoBits info
|
||||||
for i := 0; i < len(s); {
|
for i := 0; i < len(s); {
|
||||||
v, sz := trie.lookupString(s[i:])
|
v, sz := trie.lookupString(s[i:])
|
||||||
|
if sz == 0 {
|
||||||
|
b = append(b, s[k:i]...)
|
||||||
|
b = append(b, "\ufffd"...)
|
||||||
|
k = len(s)
|
||||||
|
if err == nil {
|
||||||
|
err = runeError(utf8.RuneError)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
combinedInfoBits |= info(v)
|
||||||
|
bidi = bidi || info(v).isBidi(s[i:])
|
||||||
start := i
|
start := i
|
||||||
i += sz
|
i += sz
|
||||||
// Copy bytes not copied so far.
|
// Copy bytes not copied so far.
|
||||||
@@ -438,7 +486,9 @@ func validateAndMap(p *Profile, s string) (string, error) {
|
|||||||
}
|
}
|
||||||
if k == 0 {
|
if k == 0 {
|
||||||
// No changes so far.
|
// No changes so far.
|
||||||
s = norm.NFC.String(s)
|
if combinedInfoBits&mayNeedNorm != 0 {
|
||||||
|
s = norm.NFC.String(s)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
b = append(b, s[k:]...)
|
b = append(b, s[k:]...)
|
||||||
if norm.NFC.QuickSpan(b) != len(b) {
|
if norm.NFC.QuickSpan(b) != len(b) {
|
||||||
@@ -447,7 +497,7 @@ func validateAndMap(p *Profile, s string) (string, error) {
|
|||||||
// TODO: the punycode converters require strings as input.
|
// TODO: the punycode converters require strings as input.
|
||||||
s = string(b)
|
s = string(b)
|
||||||
}
|
}
|
||||||
return s, err
|
return s, bidi, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// A labelIter allows iterating over domain name labels.
|
// A labelIter allows iterating over domain name labels.
|
||||||
@@ -542,8 +592,13 @@ func validateFromPunycode(p *Profile, s string) error {
|
|||||||
if !norm.NFC.IsNormalString(s) {
|
if !norm.NFC.IsNormalString(s) {
|
||||||
return &labelError{s, "V1"}
|
return &labelError{s, "V1"}
|
||||||
}
|
}
|
||||||
|
// TODO: detect whether string may have to be normalized in the following
|
||||||
|
// loop.
|
||||||
for i := 0; i < len(s); {
|
for i := 0; i < len(s); {
|
||||||
v, sz := trie.lookupString(s[i:])
|
v, sz := trie.lookupString(s[i:])
|
||||||
|
if sz == 0 {
|
||||||
|
return runeError(utf8.RuneError)
|
||||||
|
}
|
||||||
if c := p.simplify(info(v).category()); c != valid && c != deviation {
|
if c := p.simplify(info(v).category()); c != valid && c != deviation {
|
||||||
return &labelError{s, "V6"}
|
return &labelError{s, "V6"}
|
||||||
}
|
}
|
||||||
@@ -616,16 +671,13 @@ var joinStates = [][numJoinTypes]joinState{
|
|||||||
|
|
||||||
// validateLabel validates the criteria from Section 4.1. Item 1, 4, and 6 are
|
// validateLabel validates the criteria from Section 4.1. Item 1, 4, and 6 are
|
||||||
// already implicitly satisfied by the overall implementation.
|
// already implicitly satisfied by the overall implementation.
|
||||||
func (p *Profile) validateLabel(s string) error {
|
func (p *Profile) validateLabel(s string) (err error) {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
if p.verifyDNSLength {
|
if p.verifyDNSLength {
|
||||||
return &labelError{s, "A4"}
|
return &labelError{s, "A4"}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if p.bidirule != nil && !p.bidirule(s) {
|
|
||||||
return &labelError{s, "B"}
|
|
||||||
}
|
|
||||||
if !p.validateLabels {
|
if !p.validateLabels {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
4396
vendor/golang.org/x/net/idna/tables.go
generated
vendored
4396
vendor/golang.org/x/net/idna/tables.go
generated
vendored
File diff suppressed because it is too large
Load Diff
17
vendor/golang.org/x/net/idna/trieval.go
generated
vendored
17
vendor/golang.org/x/net/idna/trieval.go
generated
vendored
@@ -26,9 +26,9 @@ package idna
|
|||||||
// 15..3 index into xor or mapping table
|
// 15..3 index into xor or mapping table
|
||||||
// }
|
// }
|
||||||
// } else {
|
// } else {
|
||||||
// 15..13 unused
|
// 15..14 unused
|
||||||
// 12 modifier (including virama)
|
// 13 mayNeedNorm
|
||||||
// 11 virama modifier
|
// 12..11 attributes
|
||||||
// 10..8 joining type
|
// 10..8 joining type
|
||||||
// 7..3 category type
|
// 7..3 category type
|
||||||
// }
|
// }
|
||||||
@@ -49,15 +49,20 @@ const (
|
|||||||
joinShift = 8
|
joinShift = 8
|
||||||
joinMask = 0x07
|
joinMask = 0x07
|
||||||
|
|
||||||
viramaModifier = 0x0800
|
// Attributes
|
||||||
|
attributesMask = 0x1800
|
||||||
|
viramaModifier = 0x1800
|
||||||
modifier = 0x1000
|
modifier = 0x1000
|
||||||
|
rtl = 0x0800
|
||||||
|
|
||||||
|
mayNeedNorm = 0x2000
|
||||||
)
|
)
|
||||||
|
|
||||||
// A category corresponds to a category defined in the IDNA mapping table.
|
// A category corresponds to a category defined in the IDNA mapping table.
|
||||||
type category uint16
|
type category uint16
|
||||||
|
|
||||||
const (
|
const (
|
||||||
unknown category = 0 // not defined currently in unicode.
|
unknown category = 0 // not currently defined in unicode.
|
||||||
mapped category = 1
|
mapped category = 1
|
||||||
disallowedSTD3Mapped category = 2
|
disallowedSTD3Mapped category = 2
|
||||||
deviation category = 3
|
deviation category = 3
|
||||||
@@ -110,5 +115,5 @@ func (c info) isModifier() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c info) isViramaModifier() bool {
|
func (c info) isViramaModifier() bool {
|
||||||
return c&(viramaModifier|catSmallMask) == viramaModifier
|
return c&(attributesMask|catSmallMask) == viramaModifier
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user