-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log HTTP calls in reproxy and bootstrap
Splitting out [] into smaller changes. Log HTTP calls - primarily useful since we make HTTP calls to get token expiry for token we get from creds exchange. Test: Unit tests Bug: b/300945159 Change-Id: Ie9d1f846696f277231daf7a54d0a16a71d122029 GitOrigin-RevId: e38f7f5961e574ab25830feeb7cef8b7981d22db
- Loading branch information
1 parent
b1509ba
commit 1420fc9
Showing
6 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "loghttp", | ||
srcs = ["loghttp.go"], | ||
importpath = "github.com/bazelbuild/reclient/internal/pkg/loghttp", | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"@com_github_golang_glog//:go_default_library", | ||
"@com_github_google_uuid//:uuid", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package loghttp | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httputil" | ||
|
||
log "github.com/golang/glog" | ||
"github.com/google/uuid" | ||
) | ||
|
||
// Register wraps http.DefaultTransport with logging of the requests and responses. | ||
func Register() { | ||
http.DefaultTransport = &glogTransport{base: http.DefaultTransport} | ||
} | ||
|
||
type glogTransport struct { | ||
base http.RoundTripper | ||
} | ||
|
||
func (g *glogTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
reqid := uuid.New().String() | ||
if reqStr, err := httputil.DumpRequest(req, true); err == nil { | ||
log.Infof("%v: HTTP Request: %v", reqid, string(reqStr)) | ||
} else { | ||
log.Infof("%v: HTTP Request: %v", reqid, req) | ||
} | ||
resp, err := g.base.RoundTrip(req) | ||
if err != nil { | ||
log.Infof("%v: HTTP Error: %v", reqid, err) | ||
return nil, err | ||
} | ||
if respStr, err := httputil.DumpResponse(resp, true); err == nil { | ||
log.Infof("%v: HTTP Response: %v", reqid, string(respStr)) | ||
} else { | ||
log.Infof("%v: HTTP Response: %v", reqid, resp) | ||
} | ||
return resp, nil | ||
} |