HTTP trace code vet'ed

This commit is contained in:
Anand Babu (AB) Periasamy
2015-03-11 01:24:39 -07:00
parent 09f72d6f2b
commit 2dcf5a0390
3 changed files with 22 additions and 13 deletions
+12 -7
View File
@@ -30,12 +30,15 @@ import (
// NewClient - get new client
func getNewClient(c *cli.Context) (*s3.Client, error) {
switch c.GlobalString("verbose") {
case "trace":
case "quiet":
case "":
fmt.Printf("Error: No value specified for --verbose=[quiet|trace]\n")
os.Exit(1)
if c.GlobalBool("verbose") {
fmt.Printf("Error: No value specified for --verbose=[quiet|trace]\n")
os.Exit(1)
}
default:
fmt.Printf("Error: Invalid value specified for --verbose=[%s]\n", c.GlobalString("verbose"))
os.Exit(1)
@@ -46,15 +49,17 @@ func getNewClient(c *cli.Context) (*s3.Client, error) {
fatal(err.Error())
}
var trace s3Trace
if c.GlobalString("verbose") == "trace" {
traceTransport := s3.RoundTripTrace{trace, http.DefaultTransport}
traceTransport := s3.RoundTripTrace{
Trace: s3Trace{BodyTraceFlag: false, RequestTransportFlag: true, Writer: nil},
Transport: http.DefaultTransport,
}
s3client := s3.GetNewClient(&config.S3.Auth, traceTransport)
return s3client, nil
} else {
s3client := s3.GetNewClient(&config.S3.Auth, nil)
return s3client, nil
}
s3client := s3.GetNewClient(&config.S3.Auth, nil)
return s3client, nil
}
func parseOptions(c *cli.Context) (fsoptions *fsOptions, err error) {
+4 -3
View File
@@ -84,12 +84,13 @@ type listBucketResults struct {
CommonPrefixes []*Prefix
}
// Client is an Amazon S3 client.
// Client holds Amazon S3 client credentials and flags.
type Client struct {
*Auth
Transport http.RoundTripper // or nil for the default
*Auth // AWS auth credentials
Transport http.RoundTripper // or nil for the default behavior
}
// GetNewClient returns an initialized S3.Client structure.
func GetNewClient(auth *Auth, transport http.RoundTripper) *Client {
return &Client{
Auth: auth,
+6 -3
View File
@@ -21,16 +21,19 @@ import (
"net/http"
)
type HttpTracer interface {
// HTTPTracer provides callback hook mechanism for HTTP transport.
type HTTPTracer interface {
Request(req *http.Request)
Response(res *http.Response)
}
// RoundTripTrace interposes HTTP transport requests and respsonses using HTTPTracer hooks
type RoundTripTrace struct {
Trace HttpTracer
Transport http.RoundTripper
Trace HTTPTracer // User provides callback methods
Transport http.RoundTripper // HTTP transport that needs to be intercepted
}
// RoundTrip executes user provided request and response hooks for each HTTP call.
func (t RoundTripTrace) RoundTrip(req *http.Request) (res *http.Response, err error) {
if t.Trace != nil {
t.Trace.Request(req)