Update vendor directory

This commit is contained in:
Nick Craig-Wood 2017-01-02 16:12:05 +00:00
parent 5b8b379feb
commit 1cad759306
69 changed files with 4846 additions and 897 deletions

View file

@ -139,3 +139,4 @@ Contributors
- Sam Gunaratne <samgzeit@gmail.com>
- Richard Scothern <richard.scothern@gmail.com>
- Michel Couillard <couillard.michel@voxlog.ca>
- Christopher Waldon <ckwaldon@us.ibm.com>

22
vendor/github.com/ncw/swift/expect_continue.go generated vendored Normal file
View file

@ -0,0 +1,22 @@
// Show that we can use `Expect: 100-continue` in go versions >= 1.6
//
// +build go1.6
package swift
import (
"net/http"
"time"
)
// DisableExpectContinue indicates whether this version of go supports
// expect continue.
const DisableExpectContinue = false
// SetExpectContinueTimeout sets ExpectContinueTimeout in the
// transport to the default value if not set.
func SetExpectContinueTimeout(transport *http.Transport, t time.Duration) {
if transport.ExpectContinueTimeout == 0 {
transport.ExpectContinueTimeout = t
}
}

20
vendor/github.com/ncw/swift/expect_continue_pre1_6.go generated vendored Normal file
View file

@ -0,0 +1,20 @@
// Show that we can't use `Expect: 100-continue` in go versions < 1.6
//
// +build !go1.6
package swift
import (
"net/http"
"time"
)
// DisableExpectContinue indicates whether this version of go supports
// expect continue.
const DisableExpectContinue = true
// SetExpectContinueTimeout sets ExpectContinueTimeout in the
// transport to the default value if not set.
func SetExpectContinueTimeout(transport *http.Transport, t time.Duration) {
// can't do anything so ignore
}

67
vendor/github.com/ncw/swift/swift.go generated vendored
View file

@ -102,6 +102,13 @@ type Connection struct {
TenantDomainId string // Id of the tenant's domain (v3 auth only), only needed if it differs the from user domain
TrustId string // Id of the trust (v3 auth only)
Transport http.RoundTripper `json:"-" xml:"-"` // Optional specialised http.Transport (eg. for Google Appengine)
// If set then we won't send `Expect: 100-continue` headers.
// This is automatically disabled on go < 1.6 which doesn't
// support it and if a 417 error is received. Note that if
// you are using a custom Transport and you wish the `Expect:
// 100-continue` mechanism to work, you'll need to set
// ExpectContinueTimeout to a non-zero value.
DisableExpectContinue bool
// These are filled in after Authenticate is called as are the defaults for above
StorageUrl string
AuthToken string
@ -149,6 +156,7 @@ var (
TimeoutError = newError(408, "Timeout when reading or writing data")
Forbidden = newError(403, "Operation forbidden")
TooLargeObject = newError(413, "Too Large Object")
RetryNeeded = newError(401, "Retry needed after token expired")
// Mappings for authentication errors
authErrorMap = errorMap{
@ -254,12 +262,17 @@ func (c *Connection) setDefaults() {
c.Timeout = 60 * time.Second
}
if c.Transport == nil {
c.Transport = &http.Transport{
tr := &http.Transport{
// TLSClientConfig: &tls.Config{RootCAs: pool},
// DisableCompression: true,
Proxy: http.ProxyFromEnvironment,
MaxIdleConnsPerHost: 2048,
}
// If using ExpectContinue make sure it is set in the transport
if !c.DisableExpectContinue {
SetExpectContinueTimeout(tr, 5*time.Second)
}
c.Transport = tr
}
if c.client == nil {
c.client = &http.Client{
@ -463,6 +476,13 @@ func (c *Connection) Call(targetUrl string, p RequestOpts) (resp *http.Response,
if retries == 0 {
retries = c.Retries
}
reader := p.Body
var wdReader *watchdogReader
timer := time.NewTimer(c.ConnectTimeout)
if reader != nil {
wdReader = newWatchdogReader(reader, c.Timeout, timer)
reader = wdReader
}
var req *http.Request
for {
var authToken string
@ -483,11 +503,6 @@ func (c *Connection) Call(targetUrl string, p RequestOpts) (resp *http.Response,
if p.Parameters != nil {
URL.RawQuery = p.Parameters.Encode()
}
timer := time.NewTimer(c.ConnectTimeout)
reader := p.Body
if reader != nil {
reader = newWatchdogReader(reader, c.Timeout, timer)
}
req, err = http.NewRequest(p.Operation, URL.String(), reader)
if err != nil {
return
@ -508,6 +523,12 @@ func (c *Connection) Call(targetUrl string, p RequestOpts) (resp *http.Response,
}
req.Header.Add("User-Agent", c.UserAgent)
req.Header.Add("X-Auth-Token", authToken)
// Use `Expect: 100-continue` if body set and not disabled
usingExpectContinue := false
if !DisableExpectContinue && !c.DisableExpectContinue && p.Body != nil {
req.Header.Set("Expect", "100-continue")
usingExpectContinue = true
}
resp, err = c.doTimeoutRequest(timer, req)
if err != nil {
if (p.Operation == "HEAD" || p.Operation == "GET") && retries > 0 {
@ -516,14 +537,27 @@ func (c *Connection) Call(targetUrl string, p RequestOpts) (resp *http.Response,
}
return nil, nil, err
}
// Check to see if token has expired
if resp.StatusCode == 401 && retries > 0 {
_ = resp.Body.Close()
if retries <= 0 {
break
}
if resp.StatusCode == 417 && usingExpectContinue {
// Disable `Expect: 100-continue` if get 417 error in response
c.DisableExpectContinue = true
} else if resp.StatusCode == 401 {
// Token has expired
c.UnAuthenticate()
retries--
// If we were reading from a reader and we
// can't reset it, then fail here, otherwise
// retry.
if wdReader != nil && !wdReader.Reset() {
return resp, headers, RetryNeeded
}
} else {
break
}
// Retry
_ = resp.Body.Close()
retries--
}
if err = c.parseHeaders(resp, p.ErrorMap); err != nil {
@ -1141,6 +1175,19 @@ func (file *ObjectCreateFile) Close() error {
return nil
}
// Headers returns the response headers from the created object if the upload
// has been completed. The Close() method must be called on an ObjectCreateFile
// before this method.
func (file *ObjectCreateFile) Headers() (Headers, error) {
// error out if upload is not complete.
select {
case <-file.done:
default:
return nil, fmt.Errorf("Cannot get metadata, object upload failed or has not yet completed.")
}
return file.headers, nil
}
// Check it satisfies the interface
var _ io.WriteCloser = &ObjectCreateFile{}

View file

@ -7,12 +7,18 @@ import (
// An io.Reader which resets a watchdog timer whenever data is read
type watchdogReader struct {
timeout time.Duration
reader io.Reader
timer *time.Timer
timeout time.Duration
reader io.Reader
timer *time.Timer
bytes int64
replayFirst bool
readFirst bool
first byte
}
// Returns a new reader which will kick the watchdog timer whenever data is read
//
// It also has a 1 byte buffer which can be reset with the Reset() method.
func newWatchdogReader(reader io.Reader, timeout time.Duration, timer *time.Timer) *watchdogReader {
return &watchdogReader{
timeout: timeout,
@ -23,12 +29,43 @@ func newWatchdogReader(reader io.Reader, timeout time.Duration, timer *time.Time
// Read reads up to len(p) bytes into p
func (t *watchdogReader) Read(p []byte) (n int, err error) {
if len(p) == 0 {
return 0, nil
}
// FIXME limit the amount of data read in one chunk so as to not exceed the timeout?
resetTimer(t.timer, t.timeout)
n, err = t.reader.Read(p)
if t.replayFirst {
p[0] = t.first
t.replayFirst = false
n = 1
err = nil
} else {
n, err = t.reader.Read(p)
if !t.readFirst && n > 0 {
t.first = p[0]
t.readFirst = true
}
t.bytes += int64(n)
}
resetTimer(t.timer, t.timeout)
return
}
// Resets the buffer if only 1 byte read
//
// Returns true if successful
func (t *watchdogReader) Reset() bool {
switch t.bytes {
case 0:
t.replayFirst = false
return true
case 1:
t.replayFirst = true
return true
default:
return false
}
}
// Check it satisfies the interface
var _ io.Reader = &watchdogReader{}