1 回答

TA貢獻1856條經驗 獲得超17個贊
來自的請求無法
google/oauth2
被 追蹤httptrace
。您ClientWrapper
傳遞的 withcontext.WithValue
將在這里被忽略,并且 oauth2 有它自己的 http.Client,它只是使用from context.Value的Transport
方法。*http.Client
來自 androidpublisher 的請求可以通過 httptrace 跟蹤,如下所示:
ctx := httptrace.WithClientTrace(context.Background(), clientWrapperTrace)r, err := c.VerifyProduct(ctx, packageName, productID, token)
如果您只想計算請求,我認為覆蓋
http.Client.Transport
是一種簡單的方法。
type TraceTransport struct {
}
func (t *TraceTransport) RoundTrip(req *http.Request) (*http.Response, error) {
fmt.Printf("RoundTrip hook %v\n", req.URL)
return http.DefaultTransport.RoundTrip(req)
}
func NewClientTrace(jsonKey []byte) (*Client, error) {
cli := &http.Client{Transport: &TraceTransport{}}
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, cli)
// ...
service, err := androidpublisher.NewService(ctx, option.WithHTTPClient(conf.Client(ctx)))
// ....
}
- 1 回答
- 0 關注
- 242 瀏覽
添加回答
舉報