@@ -10,6 +10,7 @@ import (
10
10
"fmt"
11
11
"io"
12
12
"log"
13
+ "net"
13
14
"net/http"
14
15
"net/url"
15
16
"strconv"
@@ -34,15 +35,17 @@ const (
34
35
// Rackspace UK https://lon.auth.api.rackspacecloud.com/v1.0
35
36
// Memset Memstore UK https://auth.storage.memset.com/v1.0
36
37
type Connection struct {
37
- UserName string // UserName for api
38
- ApiKey string // Key for api access
39
- AuthUrl string // Auth URL
40
- Retries int // Retries on error (default is 3)
41
- UserAgent string // Http User agent (default goswift/1.0)
42
- storageUrl string
43
- authToken string
44
- tr * http.Transport
45
- client * http.Client
38
+ UserName string // UserName for api
39
+ ApiKey string // Key for api access
40
+ AuthUrl string // Auth URL
41
+ Retries int // Retries on error (default is 3)
42
+ UserAgent string // Http User agent (default goswift/1.0)
43
+ ConnectTimeout time.Duration // Connect channel timeout (default 10s)
44
+ Timeout time.Duration // Data channel timeout (default 60s) NOT IMPLEMENTED
45
+ storageUrl string
46
+ authToken string
47
+ tr * http.Transport
48
+ client * http.Client
46
49
}
47
50
48
51
// Error - all errors generated by this package are of this type. Other error
@@ -149,10 +152,31 @@ func (c *Connection) Authenticate() (err error) {
149
152
if c .Retries == 0 {
150
153
c .Retries = DefaultRetries
151
154
}
155
+ if c .ConnectTimeout == 0 {
156
+ c .ConnectTimeout = 10 * time .Second
157
+ }
158
+ if c .Timeout == 0 {
159
+ c .Timeout = 60 * time .Second
160
+ }
152
161
if c .tr == nil {
153
162
c .tr = & http.Transport {
154
- // TLSClientConfig: &tls.Config{RootCAs: pool},
155
- // DisableCompression: true,
163
+ // TLSClientConfig: &tls.Config{RootCAs: pool},
164
+ // DisableCompression: true,
165
+
166
+ // Dial with deadline
167
+ //
168
+ // FIXME not sure how this plays with connection pooling
169
+ Dial : func (network , addr string ) (net.Conn , error ) {
170
+ conn , err := net .DialTimeout (network , addr , c .ConnectTimeout )
171
+ if err != nil {
172
+ return nil , err
173
+ }
174
+ // FIXME Need to continuously bump this
175
+ // deadline forwards but can't figure
176
+ // out how to get the net.Conn out of the Request
177
+ // conn.SetDeadline(time.Now().Add(c.Timeout))
178
+ return conn , nil
179
+ },
156
180
}
157
181
}
158
182
if c .client == nil {
0 commit comments