From c009ff453d4e0afb575bf667b47cbdb2f16191c7 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 11:39:37 -0700 Subject: [PATCH 01/13] trace http calls in DoHTTP() --- hawser/client.go | 7 +------ hawser/http.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/hawser/client.go b/hawser/client.go index eee4f2d6..88d84962 100644 --- a/hawser/client.go +++ b/hawser/client.go @@ -194,7 +194,6 @@ func callOptions(filehash string) (int, *WrappedError) { if wErr != nil { return 0, wErr } - tracerx.Printf("api_options_status: %d", res.StatusCode) return res.StatusCode, nil } @@ -240,8 +239,7 @@ func callPut(filehash, filename string, cb CopyCallback) *WrappedError { fmt.Printf("Sending %s\n", filename) tracerx.Printf("api_put: %s %s", oid, filename) - res, wErr := doRequest(req, creds) - tracerx.Printf("api_put_status: %d", res.StatusCode) + _, wErr := doRequest(req, creds) return wErr } @@ -296,7 +294,6 @@ func callExternalPut(filehash, filename string, obj *objectResource, cb CopyCall if err != nil { return Errorf(err, "Error attempting to PUT %s", filename) } - tracerx.Printf("external_put_status: %d", res.StatusCode) saveCredentials(creds, res) // Run the verify callback @@ -323,7 +320,6 @@ func callExternalPut(filehash, filename string, obj *objectResource, cb CopyCall if err != nil { return Errorf(err, "Error attempting to verify %s", filename) } - tracerx.Printf("verify_status: %d", verifyRes.StatusCode) saveCredentials(verifyCreds, verifyRes) return nil @@ -358,7 +354,6 @@ func callPost(filehash, filename string) (*objectResource, int, *WrappedError) { if wErr != nil { return nil, 0, wErr } - tracerx.Printf("api_post_status: %d", res.StatusCode) if res.StatusCode == 202 { obj := &objectResource{} diff --git a/hawser/http.go b/hawser/http.go index 5967f2f0..2c3bcccd 100644 --- a/hawser/http.go +++ b/hawser/http.go @@ -2,17 +2,27 @@ package hawser import ( "crypto/tls" + "github.com/rubyist/tracerx" "net/http" "os" ) func DoHTTP(c *Configuration, req *http.Request) (*http.Response, error) { + var res *http.Response + var err error + + tracerx.Printf("HTTP: %s %s", req.Method, req.URL.String()) + switch req.Method { case "GET", "HEAD": - return c.RedirectingHttpClient().Do(req) + res, err = c.RedirectingHttpClient().Do(req) default: - return c.HttpClient().Do(req) + res, err = c.HttpClient().Do(req) } + + tracerx.Printf("HTTP: %d", res.StatusCode) + + return res, err } func (c *Configuration) HttpClient() *http.Client { From a916c9527637e7483f04a5356e5f55f5b928d78b Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 11:46:42 -0700 Subject: [PATCH 02/13] rename doRequest so it's clear why you'd use it --- hawser/client.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hawser/client.go b/hawser/client.go index 88d84962..777ee43a 100644 --- a/hawser/client.go +++ b/hawser/client.go @@ -38,7 +38,7 @@ func Download(oidPath string) (io.ReadCloser, int64, *WrappedError) { } req.Header.Set("Accept", gitMediaType) - res, wErr := doRequest(req, creds) + res, wErr := doHTTPWithCreds(req, creds) if wErr != nil { return nil, 0, wErr @@ -190,7 +190,7 @@ func callOptions(filehash string) (int, *WrappedError) { return 0, Errorf(err, "Unable to build OPTIONS request for %s", oid) } - res, wErr := doRequest(req, creds) + res, wErr := doHTTPWithCreds(req, creds) if wErr != nil { return 0, wErr } @@ -239,7 +239,7 @@ func callPut(filehash, filename string, cb CopyCallback) *WrappedError { fmt.Printf("Sending %s\n", filename) tracerx.Printf("api_put: %s %s", oid, filename) - _, wErr := doRequest(req, creds) + _, wErr := doHTTPWithCreds(req, creds) return wErr } @@ -350,7 +350,7 @@ func callPost(filehash, filename string) (*objectResource, int, *WrappedError) { req.Header.Set("Accept", gitMediaMetaType) tracerx.Printf("api_post: %s %s", oid, filename) - res, wErr := doRequest(req, creds) + res, wErr := doHTTPWithCreds(req, creds) if wErr != nil { return nil, 0, wErr } @@ -399,7 +399,9 @@ func validateMediaHeader(contentType string, reader io.Reader) (bool, int, *Wrap return true, headerSize, nil } -func doRequest(req *http.Request, creds Creds) (*http.Response, *WrappedError) { +// Wraps DoHTTP(), and saves or removes credentials from the git credential +// store based on the response. +func doHTTPWithCreds(req *http.Request, creds Creds) (*http.Response, *WrappedError) { res, err := DoHTTP(Config, req) var wErr *WrappedError From b8ad7ba5c654d9412d95b2249a6de990fa68dfd6 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 11:49:21 -0700 Subject: [PATCH 03/13] httpTransportFor() is only used once --- hawser/http.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/hawser/http.go b/hawser/http.go index 2c3bcccd..3a04da1f 100644 --- a/hawser/http.go +++ b/hawser/http.go @@ -39,18 +39,12 @@ func (c *Configuration) HttpClient() *http.Client { func (c *Configuration) RedirectingHttpClient() *http.Client { if c.redirectingHttpClient == nil { - c.redirectingHttpClient = &http.Client{ - Transport: httpTransportFor(c), + tr := &http.Transport{} + sslVerify, _ := c.GitConfig("http.sslverify") + if sslVerify == "false" || len(os.Getenv("GIT_SSL_NO_VERIFY")) > 0 { + tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} } + c.redirectingHttpClient = &http.Client{Transport: tr} } return c.redirectingHttpClient } - -func httpTransportFor(c *Configuration) *http.Transport { - tr := &http.Transport{} - sslVerify, _ := c.GitConfig("http.sslverify") - if len(os.Getenv("GIT_SSL_NO_VERIFY")) > 0 || sslVerify == "false" { - tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} - } - return tr -} From 6e3b35ace5d4dfd00367b9faa5641360a8faf085 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 12:49:15 -0700 Subject: [PATCH 04/13] implement part of curl verbose --- hawser/config.go | 21 ++++++++------- hawser/http.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 11 deletions(-) diff --git a/hawser/config.go b/hawser/config.go index a3c97b4a..c74155df 100644 --- a/hawser/config.go +++ b/hawser/config.go @@ -17,6 +17,7 @@ type Configuration struct { remotes []string httpClient *http.Client redirectingHttpClient *http.Client + isTracingHttp bool } var ( @@ -69,24 +70,18 @@ func (c *Configuration) RemoteEndpoint(remote string) string { } func (c *Configuration) Remotes() []string { - if c.remotes == nil { - c.loadGitConfig() - } + c.loadGitConfig() return c.remotes } func (c *Configuration) GitConfig(key string) (string, bool) { - if c.gitConfig == nil { - c.loadGitConfig() - } + c.loadGitConfig() value, ok := c.gitConfig[strings.ToLower(key)] return value, ok } func (c *Configuration) SetConfig(key, value string) { - if c.gitConfig == nil { - c.loadGitConfig() - } + c.loadGitConfig() c.gitConfig[key] = value } @@ -107,6 +102,14 @@ type AltConfig struct { } func (c *Configuration) loadGitConfig() { + if c.gitConfig != nil { + return + } + + if len(os.Getenv("GIT_CURL_VERBOSE")) > 0 || len(os.Getenv("GIT_HTTP_VERBOSE")) > 0 { + c.isTracingHttp = true + } + uniqRemotes := make(map[string]bool) c.gitConfig = make(map[string]string) diff --git a/hawser/http.go b/hawser/http.go index 3a04da1f..8381f2f3 100644 --- a/hawser/http.go +++ b/hawser/http.go @@ -2,16 +2,19 @@ package hawser import ( "crypto/tls" + "fmt" "github.com/rubyist/tracerx" + "io" "net/http" "os" + "strings" ) func DoHTTP(c *Configuration, req *http.Request) (*http.Response, error) { var res *http.Response var err error - tracerx.Printf("HTTP: %s %s", req.Method, req.URL.String()) + traceHttpRequest(c, req) switch req.Method { case "GET", "HEAD": @@ -20,7 +23,7 @@ func DoHTTP(c *Configuration, req *http.Request) (*http.Response, error) { res, err = c.HttpClient().Do(req) } - tracerx.Printf("HTTP: %d", res.StatusCode) + traceHttpResponse(c, res) return res, err } @@ -48,3 +51,64 @@ func (c *Configuration) RedirectingHttpClient() *http.Client { } return c.redirectingHttpClient } + +var tracedTypes = []string{"json", "text", "xml", "html"} + +func traceHttpRequest(c *Configuration, req *http.Request) { + tracerx.Printf("HTTP: %s %s", req.Method, req.URL.String()) + + c.loadGitConfig() + if c.isTracingHttp == false { + return + } + + fmt.Println(">", req.Method, req.URL.RequestURI(), req.Proto) + for key, _ := range req.Header { + fmt.Printf("> %s: %s\n", key, req.Header.Get(key)) + } +} + +func traceHttpResponse(c *Configuration, res *http.Response) { + tracerx.Printf("HTTP: %d", res.StatusCode) + + c.loadGitConfig() + if c.isTracingHttp == false { + return + } + + fmt.Println("<", res.Proto, res.Status) + for key, _ := range res.Header { + fmt.Printf("< %s: %s\n", key, res.Header.Get(key)) + } + + traceBody := false + ctype := strings.ToLower(strings.SplitN(res.Header.Get("Content-Type"), ";", 2)[0]) + for _, tracedType := range tracedTypes { + if strings.Contains(ctype, tracedType) { + traceBody = true + } + } + + if traceBody { + fmt.Println() + res.Body = newTracedBody(res.Body) + } +} + +type tracedBody struct { + body io.ReadCloser +} + +func (r *tracedBody) Read(p []byte) (int, error) { + n, err := r.body.Read(p) + fmt.Println(string(p[0:n])) + return n, err +} + +func (r *tracedBody) Close() error { + return r.body.Close() +} + +func newTracedBody(body io.ReadCloser) *tracedBody { + return &tracedBody{body} +} From abcb4bac696dd48e2d93a23beb9253667387c9aa Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 12:59:52 -0700 Subject: [PATCH 05/13] add a Configuration constructor --- hawser/config.go | 14 +++++++++----- hawser/http.go | 2 -- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/hawser/config.go b/hawser/config.go index c74155df..32274ac6 100644 --- a/hawser/config.go +++ b/hawser/config.go @@ -21,12 +21,20 @@ type Configuration struct { } var ( - Config = &Configuration{CurrentRemote: defaultRemote} + Config = NewConfig() RedirectError = fmt.Errorf("Unexpected redirection") httpPrefixRe = regexp.MustCompile("\\Ahttps?://") defaultRemote = "origin" ) +func NewConfig() *Configuration { + c := &Configuration{CurrentRemote: defaultRemote} + if len(os.Getenv("GIT_CURL_VERBOSE")) > 0 || len(os.Getenv("GIT_HTTP_VERBOSE")) > 0 { + c.isTracingHttp = true + } + return c +} + func (c *Configuration) Endpoint() string { if url, ok := c.GitConfig("hawser.url"); ok { return url @@ -106,10 +114,6 @@ func (c *Configuration) loadGitConfig() { return } - if len(os.Getenv("GIT_CURL_VERBOSE")) > 0 || len(os.Getenv("GIT_HTTP_VERBOSE")) > 0 { - c.isTracingHttp = true - } - uniqRemotes := make(map[string]bool) c.gitConfig = make(map[string]string) diff --git a/hawser/http.go b/hawser/http.go index 8381f2f3..2ed3ad39 100644 --- a/hawser/http.go +++ b/hawser/http.go @@ -57,7 +57,6 @@ var tracedTypes = []string{"json", "text", "xml", "html"} func traceHttpRequest(c *Configuration, req *http.Request) { tracerx.Printf("HTTP: %s %s", req.Method, req.URL.String()) - c.loadGitConfig() if c.isTracingHttp == false { return } @@ -71,7 +70,6 @@ func traceHttpRequest(c *Configuration, req *http.Request) { func traceHttpResponse(c *Configuration, res *http.Response) { tracerx.Printf("HTTP: %d", res.StatusCode) - c.loadGitConfig() if c.isTracingHttp == false { return } From bba0738092c15122477e9abdbf8f0ff2b376891d Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 13:04:00 -0700 Subject: [PATCH 06/13] let the commands package tell the hawser package where to send output --- commands/commands.go | 1 + hawser/config.go | 7 ++++++- hawser/http.go | 17 +++++++++-------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index 2e271bfc..ffb17784 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -163,5 +163,6 @@ type ErrorWithStack interface { } func init() { + hawser.Config.OutputWriter = OutputWriter log.SetOutput(ErrorWriter) } diff --git a/hawser/config.go b/hawser/config.go index 32274ac6..c13fe94a 100644 --- a/hawser/config.go +++ b/hawser/config.go @@ -3,6 +3,7 @@ package hawser import ( "fmt" "github.com/hawser/git-hawser/git" + "io" "net/http" "net/url" "os" @@ -13,6 +14,7 @@ import ( type Configuration struct { CurrentRemote string + OutputWriter io.Writer gitConfig map[string]string remotes []string httpClient *http.Client @@ -28,7 +30,10 @@ var ( ) func NewConfig() *Configuration { - c := &Configuration{CurrentRemote: defaultRemote} + c := &Configuration{ + CurrentRemote: defaultRemote, + OutputWriter: os.Stdout, + } if len(os.Getenv("GIT_CURL_VERBOSE")) > 0 || len(os.Getenv("GIT_HTTP_VERBOSE")) > 0 { c.isTracingHttp = true } diff --git a/hawser/http.go b/hawser/http.go index 2ed3ad39..68494563 100644 --- a/hawser/http.go +++ b/hawser/http.go @@ -74,9 +74,9 @@ func traceHttpResponse(c *Configuration, res *http.Response) { return } - fmt.Println("<", res.Proto, res.Status) + fmt.Fprintf(c.OutputWriter, "< %s %s\n", res.Proto, res.Status) for key, _ := range res.Header { - fmt.Printf("< %s: %s\n", key, res.Header.Get(key)) + fmt.Fprintf(c.OutputWriter, "< %s: %s\n", key, res.Header.Get(key)) } traceBody := false @@ -88,18 +88,19 @@ func traceHttpResponse(c *Configuration, res *http.Response) { } if traceBody { - fmt.Println() - res.Body = newTracedBody(res.Body) + fmt.Fprintf(c.OutputWriter, "\n") + res.Body = newTracedBody(res.Body, c.OutputWriter) } } type tracedBody struct { - body io.ReadCloser + body io.ReadCloser + output io.Writer } func (r *tracedBody) Read(p []byte) (int, error) { n, err := r.body.Read(p) - fmt.Println(string(p[0:n])) + fmt.Fprintf(r.output, "%s\n", string(p[0:n])) return n, err } @@ -107,6 +108,6 @@ func (r *tracedBody) Close() error { return r.body.Close() } -func newTracedBody(body io.ReadCloser) *tracedBody { - return &tracedBody{body} +func newTracedBody(body io.ReadCloser, output io.Writer) *tracedBody { + return &tracedBody{body, output} } From 2ca960faa7812e21c880518e410e4f4809ade260 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 13:06:41 -0700 Subject: [PATCH 07/13] lets write curl verbose to stderr --- commands/commands.go | 1 - hawser/config.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index ffb17784..2e271bfc 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -163,6 +163,5 @@ type ErrorWithStack interface { } func init() { - hawser.Config.OutputWriter = OutputWriter log.SetOutput(ErrorWriter) } diff --git a/hawser/config.go b/hawser/config.go index c13fe94a..41c33688 100644 --- a/hawser/config.go +++ b/hawser/config.go @@ -32,7 +32,7 @@ var ( func NewConfig() *Configuration { c := &Configuration{ CurrentRemote: defaultRemote, - OutputWriter: os.Stdout, + OutputWriter: os.Stderr, } if len(os.Getenv("GIT_CURL_VERBOSE")) > 0 || len(os.Getenv("GIT_HTTP_VERBOSE")) > 0 { c.isTracingHttp = true From 57e6538bf3a21481e749635bff87d9c46d4f15d4 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 13:15:04 -0700 Subject: [PATCH 08/13] missed some output --- hawser/http.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hawser/http.go b/hawser/http.go index 68494563..a651bfe4 100644 --- a/hawser/http.go +++ b/hawser/http.go @@ -61,9 +61,9 @@ func traceHttpRequest(c *Configuration, req *http.Request) { return } - fmt.Println(">", req.Method, req.URL.RequestURI(), req.Proto) + fmt.Fprintf(c.OutputWriter, "> %s %s %s\n", req.Method, req.URL.RequestURI(), req.Proto) for key, _ := range req.Header { - fmt.Printf("> %s: %s\n", key, req.Header.Get(key)) + fmt.Fprintf(c.OutputWriter, "> %s: %s\n", key, req.Header.Get(key)) } } From 5847f6b469f9a2e613a5b076e7636d617423e351 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 14:04:07 -0700 Subject: [PATCH 09/13] dont need to tweak where curl traces go --- hawser/http.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hawser/http.go b/hawser/http.go index a651bfe4..036220ff 100644 --- a/hawser/http.go +++ b/hawser/http.go @@ -61,9 +61,9 @@ func traceHttpRequest(c *Configuration, req *http.Request) { return } - fmt.Fprintf(c.OutputWriter, "> %s %s %s\n", req.Method, req.URL.RequestURI(), req.Proto) + fmt.Fprintf(os.Stderr, "> %s %s %s\n", req.Method, req.URL.RequestURI(), req.Proto) for key, _ := range req.Header { - fmt.Fprintf(c.OutputWriter, "> %s: %s\n", key, req.Header.Get(key)) + fmt.Fprintf(os.Stderr, "> %s: %s\n", key, req.Header.Get(key)) } } @@ -74,9 +74,9 @@ func traceHttpResponse(c *Configuration, res *http.Response) { return } - fmt.Fprintf(c.OutputWriter, "< %s %s\n", res.Proto, res.Status) + fmt.Fprintf(os.Stderr, "< %s %s\n", res.Proto, res.Status) for key, _ := range res.Header { - fmt.Fprintf(c.OutputWriter, "< %s: %s\n", key, res.Header.Get(key)) + fmt.Fprintf(os.Stderr, "< %s: %s\n", key, res.Header.Get(key)) } traceBody := false @@ -88,19 +88,18 @@ func traceHttpResponse(c *Configuration, res *http.Response) { } if traceBody { - fmt.Fprintf(c.OutputWriter, "\n") - res.Body = newTracedBody(res.Body, c.OutputWriter) + fmt.Fprintf(os.Stderr, "\n") + res.Body = newTracedBody(res.Body) } } type tracedBody struct { - body io.ReadCloser - output io.Writer + body io.ReadCloser } func (r *tracedBody) Read(p []byte) (int, error) { n, err := r.body.Read(p) - fmt.Fprintf(r.output, "%s\n", string(p[0:n])) + fmt.Fprintf(os.Stderr, "%s\n", string(p[0:n])) return n, err } @@ -108,6 +107,6 @@ func (r *tracedBody) Close() error { return r.body.Close() } -func newTracedBody(body io.ReadCloser, output io.Writer) *tracedBody { - return &tracedBody{body, output} +func newTracedBody(body io.ReadCloser) *tracedBody { + return &tracedBody{body} } From cda5bab8c9c95f7234c0f8e88e25e99fcbf56f2a Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 14:10:17 -0700 Subject: [PATCH 10/13] dont bother supporting GIT_HTTP_VERBOSE --- hawser/config.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/hawser/config.go b/hawser/config.go index 41c33688..34edb555 100644 --- a/hawser/config.go +++ b/hawser/config.go @@ -3,7 +3,6 @@ package hawser import ( "fmt" "github.com/hawser/git-hawser/git" - "io" "net/http" "net/url" "os" @@ -14,7 +13,6 @@ import ( type Configuration struct { CurrentRemote string - OutputWriter io.Writer gitConfig map[string]string remotes []string httpClient *http.Client @@ -32,10 +30,7 @@ var ( func NewConfig() *Configuration { c := &Configuration{ CurrentRemote: defaultRemote, - OutputWriter: os.Stderr, - } - if len(os.Getenv("GIT_CURL_VERBOSE")) > 0 || len(os.Getenv("GIT_HTTP_VERBOSE")) > 0 { - c.isTracingHttp = true + isTracingHttp: len(os.Getenv("GIT_CURL_VERBOSE")) > 0, } return c } From d298867d481e2579597c549f334831575b3949ca Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 14:18:02 -0700 Subject: [PATCH 11/13] count how many bytes are uploaded --- hawser/http.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/hawser/http.go b/hawser/http.go index 036220ff..0102658d 100644 --- a/hawser/http.go +++ b/hawser/http.go @@ -14,6 +14,12 @@ func DoHTTP(c *Configuration, req *http.Request) (*http.Response, error) { var res *http.Response var err error + var counter *countingBody + if req.Body != nil { + counter = newCountingBody(req.Body) + req.Body = counter + } + traceHttpRequest(c, req) switch req.Method { @@ -23,7 +29,7 @@ func DoHTTP(c *Configuration, req *http.Request) (*http.Response, error) { res, err = c.HttpClient().Do(req) } - traceHttpResponse(c, res) + traceHttpResponse(c, res, counter) return res, err } @@ -67,13 +73,18 @@ func traceHttpRequest(c *Configuration, req *http.Request) { } } -func traceHttpResponse(c *Configuration, res *http.Response) { +func traceHttpResponse(c *Configuration, res *http.Response, counter *countingBody) { tracerx.Printf("HTTP: %d", res.StatusCode) if c.isTracingHttp == false { return } + if counter != nil { + fmt.Fprintf(os.Stderr, "* upload sent off: %d bytes\n", counter.Size) + } + fmt.Fprintf(os.Stderr, "\n") + fmt.Fprintf(os.Stderr, "< %s %s\n", res.Proto, res.Status) for key, _ := range res.Header { fmt.Fprintf(os.Stderr, "< %s: %s\n", key, res.Header.Get(key)) @@ -93,6 +104,25 @@ func traceHttpResponse(c *Configuration, res *http.Response) { } } +type countingBody struct { + body io.ReadCloser + Size int64 +} + +func (r *countingBody) Read(p []byte) (int, error) { + n, err := r.body.Read(p) + r.Size += int64(n) + return n, err +} + +func (r *countingBody) Close() error { + return r.body.Close() +} + +func newCountingBody(body io.ReadCloser) *countingBody { + return &countingBody{body, 0} +} + type tracedBody struct { body io.ReadCloser } From 0ad03b3864979479e5d0e599abffd2f28a9b13fb Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 14:19:53 -0700 Subject: [PATCH 12/13] extra linebreak for readability --- hawser/http.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hawser/http.go b/hawser/http.go index 0102658d..fb6948de 100644 --- a/hawser/http.go +++ b/hawser/http.go @@ -102,6 +102,8 @@ func traceHttpResponse(c *Configuration, res *http.Response, counter *countingBo fmt.Fprintf(os.Stderr, "\n") res.Body = newTracedBody(res.Body) } + + fmt.Fprintf(os.Stderr, "\n") } type countingBody struct { From d4a1b5554aa316bd208dc47c603a7b871beb48e5 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Mar 2015 14:21:25 -0700 Subject: [PATCH 13/13] dead function --- hawser/config.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/hawser/config.go b/hawser/config.go index 34edb555..2f753546 100644 --- a/hawser/config.go +++ b/hawser/config.go @@ -155,10 +155,3 @@ func (c *Configuration) loadGitConfig() { c.remotes = append(c.remotes, remote) } } - -func configFileExists(filename string) bool { - if _, err := os.Stat(filename); err == nil { - return true - } - return false -}