2018-01-13 00:30:54 +08:00
|
|
|
// Package fshttp contains the common http parts of the config, Transport and Client
|
|
|
|
package fshttp
|
2016-09-11 02:17:43 +08:00
|
|
|
|
|
|
|
import (
|
2016-11-02 23:53:43 +08:00
|
|
|
"bytes"
|
2018-04-07 02:13:27 +08:00
|
|
|
"context"
|
2016-09-11 02:17:43 +08:00
|
|
|
"crypto/tls"
|
2019-02-11 21:09:32 +08:00
|
|
|
"crypto/x509"
|
2016-09-11 02:17:43 +08:00
|
|
|
"net"
|
|
|
|
"net/http"
|
2019-01-12 01:35:29 +08:00
|
|
|
"net/http/cookiejar"
|
2016-09-11 02:17:43 +08:00
|
|
|
"net/http/httputil"
|
2022-08-20 22:38:02 +08:00
|
|
|
"os"
|
2016-09-11 02:17:43 +08:00
|
|
|
"sync"
|
|
|
|
"time"
|
2017-07-13 12:11:24 +08:00
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fs"
|
2021-01-06 20:06:00 +08:00
|
|
|
"github.com/rclone/rclone/fs/accounting"
|
2020-06-05 19:15:07 +08:00
|
|
|
"github.com/rclone/rclone/lib/structs"
|
2019-01-12 01:35:29 +08:00
|
|
|
"golang.org/x/net/publicsuffix"
|
2016-09-11 02:17:43 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
separatorReq = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
|
|
|
|
separatorResp = "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-01-12 01:35:29 +08:00
|
|
|
transport http.RoundTripper
|
2019-03-09 04:33:22 +08:00
|
|
|
noTransport = new(sync.Once)
|
2019-01-12 01:35:29 +08:00
|
|
|
cookieJar, _ = cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
|
2020-12-15 03:10:11 +08:00
|
|
|
logMutex sync.Mutex
|
2024-05-24 17:45:10 +08:00
|
|
|
|
|
|
|
// UnixSocketConfig describes the option to configure the path to a unix domain socket to connect to
|
|
|
|
UnixSocketConfig = fs.Option{
|
|
|
|
Name: "unix_socket",
|
|
|
|
Help: "Path to a unix domain socket to dial to, instead of opening a TCP connection directly",
|
|
|
|
Advanced: true,
|
|
|
|
Default: "",
|
|
|
|
}
|
2016-09-11 02:17:43 +08:00
|
|
|
)
|
|
|
|
|
2019-03-09 04:33:22 +08:00
|
|
|
// ResetTransport resets the existing transport, allowing it to take new settings.
|
|
|
|
// Should only be used for testing.
|
|
|
|
func ResetTransport() {
|
|
|
|
noTransport = new(sync.Once)
|
|
|
|
}
|
|
|
|
|
2019-10-16 18:21:26 +08:00
|
|
|
// NewTransportCustom returns an http.RoundTripper with the correct timeouts.
|
|
|
|
// The customize function is called if set to give the caller an opportunity to
|
|
|
|
// customize any defaults in the Transport.
|
2020-11-13 23:24:43 +08:00
|
|
|
func NewTransportCustom(ctx context.Context, customize func(*http.Transport)) http.RoundTripper {
|
|
|
|
ci := fs.GetConfig(ctx)
|
2019-10-16 18:21:26 +08:00
|
|
|
// Start with a sensible set of defaults then override.
|
|
|
|
// This also means we get new stuff when it gets added to go
|
|
|
|
t := new(http.Transport)
|
2020-06-05 19:15:07 +08:00
|
|
|
structs.SetDefaults(t, http.DefaultTransport.(*http.Transport))
|
2019-10-16 18:21:26 +08:00
|
|
|
t.Proxy = http.ProxyFromEnvironment
|
|
|
|
t.MaxIdleConnsPerHost = 2 * (ci.Checkers + ci.Transfers + 1)
|
|
|
|
t.MaxIdleConns = 2 * t.MaxIdleConnsPerHost
|
|
|
|
t.TLSHandshakeTimeout = ci.ConnectTimeout
|
|
|
|
t.ResponseHeaderTimeout = ci.Timeout
|
2022-05-30 17:14:37 +08:00
|
|
|
t.DisableKeepAlives = ci.DisableHTTPKeepAlives
|
2019-10-16 18:21:26 +08:00
|
|
|
|
|
|
|
// TLS Config
|
|
|
|
t.TLSClientConfig = &tls.Config{
|
|
|
|
InsecureSkipVerify: ci.InsecureSkipVerify,
|
|
|
|
}
|
2019-02-11 21:09:32 +08:00
|
|
|
|
2019-10-16 18:21:26 +08:00
|
|
|
// Load client certs
|
|
|
|
if ci.ClientCert != "" || ci.ClientKey != "" {
|
|
|
|
if ci.ClientCert == "" || ci.ClientKey == "" {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "Both --client-cert and --client-key must be set")
|
2019-02-11 21:09:32 +08:00
|
|
|
}
|
2019-10-16 18:21:26 +08:00
|
|
|
cert, err := tls.LoadX509KeyPair(ci.ClientCert, ci.ClientKey)
|
|
|
|
if err != nil {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "Failed to load --client-cert/--client-key pair: %v", err)
|
2019-02-11 21:09:32 +08:00
|
|
|
}
|
2023-10-25 13:01:42 +08:00
|
|
|
if cert.Leaf == nil {
|
|
|
|
// Leaf is always the first certificate
|
|
|
|
cert.Leaf, err = x509.ParseCertificate(cert.Certificate[0])
|
|
|
|
if err != nil {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "Failed to parse the certificate")
|
2023-10-25 13:01:42 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-16 18:21:26 +08:00
|
|
|
t.TLSClientConfig.Certificates = []tls.Certificate{cert}
|
|
|
|
}
|
2019-02-11 21:09:32 +08:00
|
|
|
|
2023-01-11 15:59:51 +08:00
|
|
|
// Load CA certs
|
|
|
|
if len(ci.CaCert) != 0 {
|
|
|
|
|
2019-10-16 18:21:26 +08:00
|
|
|
caCertPool := x509.NewCertPool()
|
2023-01-11 15:59:51 +08:00
|
|
|
|
|
|
|
for _, cert := range ci.CaCert {
|
|
|
|
caCert, err := os.ReadFile(cert)
|
|
|
|
if err != nil {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "Failed to read --ca-cert file %q : %v", cert, err)
|
2023-01-11 15:59:51 +08:00
|
|
|
}
|
|
|
|
ok := caCertPool.AppendCertsFromPEM(caCert)
|
|
|
|
if !ok {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "Failed to add certificates from --ca-cert file %q", cert)
|
2023-01-11 15:59:51 +08:00
|
|
|
}
|
2018-04-07 03:33:51 +08:00
|
|
|
}
|
2019-10-16 18:21:26 +08:00
|
|
|
t.TLSClientConfig.RootCAs = caCertPool
|
|
|
|
}
|
|
|
|
|
|
|
|
t.DisableCompression = ci.NoGzip
|
2023-11-25 01:53:33 +08:00
|
|
|
t.DialContext = func(reqCtx context.Context, network, addr string) (net.Conn, error) {
|
|
|
|
return NewDialer(ctx).DialContext(reqCtx, network, addr)
|
2019-10-16 18:21:26 +08:00
|
|
|
}
|
|
|
|
t.IdleConnTimeout = 60 * time.Second
|
2020-01-09 22:00:46 +08:00
|
|
|
t.ExpectContinueTimeout = ci.ExpectContinueTimeout
|
2019-10-16 18:21:26 +08:00
|
|
|
|
2020-01-22 00:34:29 +08:00
|
|
|
if ci.Dump&(fs.DumpHeaders|fs.DumpBodies|fs.DumpAuth|fs.DumpRequests|fs.DumpResponses) != 0 {
|
|
|
|
fs.Debugf(nil, "You have specified to dump information. Please be noted that the "+
|
|
|
|
"Accept-Encoding as shown may not be correct in the request and the response may not show "+
|
|
|
|
"Content-Encoding if the go standard libraries auto gzip encoding was in effect. In this case"+
|
|
|
|
" the body of the request will be gunzipped before showing it.")
|
|
|
|
}
|
|
|
|
|
2021-04-20 00:00:07 +08:00
|
|
|
if ci.DisableHTTP2 {
|
|
|
|
t.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{}
|
|
|
|
}
|
|
|
|
|
2019-10-16 18:21:26 +08:00
|
|
|
// customize the transport if required
|
|
|
|
if customize != nil {
|
|
|
|
customize(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrap that http.Transport in our own transport
|
|
|
|
return newTransport(ci, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTransport returns an http.RoundTripper with the correct timeouts
|
2020-11-13 23:24:43 +08:00
|
|
|
func NewTransport(ctx context.Context) http.RoundTripper {
|
2019-10-16 18:21:26 +08:00
|
|
|
(*noTransport).Do(func() {
|
2020-11-13 23:24:43 +08:00
|
|
|
transport = NewTransportCustom(ctx, nil)
|
2016-09-11 02:17:43 +08:00
|
|
|
})
|
|
|
|
return transport
|
|
|
|
}
|
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
// NewClient returns an http.Client with the correct timeouts
|
2020-11-13 23:24:43 +08:00
|
|
|
func NewClient(ctx context.Context) *http.Client {
|
2024-05-24 17:45:10 +08:00
|
|
|
return NewClientCustom(ctx, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewClientCustom returns an http.Client with the correct timeouts.
|
|
|
|
// It allows customizing the transport, using NewTransportCustom.
|
|
|
|
func NewClientCustom(ctx context.Context, customize func(*http.Transport)) *http.Client {
|
2020-11-13 23:24:43 +08:00
|
|
|
ci := fs.GetConfig(ctx)
|
2019-10-16 18:21:26 +08:00
|
|
|
client := &http.Client{
|
2024-05-24 17:45:10 +08:00
|
|
|
Transport: NewTransportCustom(ctx, customize),
|
2016-09-11 02:17:43 +08:00
|
|
|
}
|
2019-01-12 01:35:29 +08:00
|
|
|
if ci.Cookie {
|
2019-10-16 18:21:26 +08:00
|
|
|
client.Jar = cookieJar
|
2019-01-12 01:35:29 +08:00
|
|
|
}
|
2019-10-16 18:21:26 +08:00
|
|
|
return client
|
2016-09-11 02:17:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-24 17:45:10 +08:00
|
|
|
// NewClientWithUnixSocket returns an http.Client with the correct timeout.
|
|
|
|
// It internally uses NewClientCustom with a custom dialer connecting to
|
|
|
|
// the specified unix domain socket.
|
|
|
|
func NewClientWithUnixSocket(ctx context.Context, path string) *http.Client {
|
|
|
|
return NewClientCustom(ctx, func(t *http.Transport) {
|
|
|
|
t.DialContext = func(reqCtx context.Context, network, addr string) (net.Conn, error) {
|
|
|
|
return NewDialer(ctx).DialContext(reqCtx, "unix", path)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-20 18:39:20 +08:00
|
|
|
// Transport is our http Transport which wraps an http.Transport
|
2016-09-11 02:17:43 +08:00
|
|
|
// * Sets the User Agent
|
|
|
|
// * Does logging
|
2021-09-06 22:42:23 +08:00
|
|
|
// * Updates metrics
|
2016-09-11 02:17:43 +08:00
|
|
|
type Transport struct {
|
|
|
|
*http.Transport
|
2018-01-13 00:30:54 +08:00
|
|
|
dump fs.DumpFlags
|
2017-11-24 17:07:56 +08:00
|
|
|
filterRequest func(req *http.Request)
|
2018-01-13 00:30:54 +08:00
|
|
|
userAgent string
|
2020-04-23 22:24:21 +08:00
|
|
|
headers []*fs.HTTPOption
|
2021-09-06 22:42:23 +08:00
|
|
|
metrics *Metrics
|
2023-10-25 13:01:42 +08:00
|
|
|
// Filename of the client cert in case we need to reload it
|
|
|
|
clientCert string
|
|
|
|
clientKey string
|
|
|
|
// Mutex for serializing attempts at reloading the certificates
|
|
|
|
reloadMutex sync.Mutex
|
2016-09-11 02:17:43 +08:00
|
|
|
}
|
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
// newTransport wraps the http.Transport passed in and logs all
|
2016-09-11 02:17:43 +08:00
|
|
|
// roundtrips including the body if logBody is set.
|
2018-01-13 00:30:54 +08:00
|
|
|
func newTransport(ci *fs.ConfigInfo, transport *http.Transport) *Transport {
|
2016-09-11 02:17:43 +08:00
|
|
|
return &Transport{
|
2023-10-25 13:01:42 +08:00
|
|
|
Transport: transport,
|
|
|
|
dump: ci.Dump,
|
|
|
|
userAgent: ci.UserAgent,
|
|
|
|
headers: ci.Headers,
|
|
|
|
metrics: DefaultMetrics,
|
|
|
|
clientCert: ci.ClientCert,
|
|
|
|
clientKey: ci.ClientKey,
|
2016-09-11 02:17:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-24 17:07:56 +08:00
|
|
|
// SetRequestFilter sets a filter to be used on each request
|
|
|
|
func (t *Transport) SetRequestFilter(f func(req *http.Request)) {
|
|
|
|
t.filterRequest = f
|
|
|
|
}
|
|
|
|
|
2016-10-31 03:16:27 +08:00
|
|
|
// A mutex to protect this map
|
|
|
|
var checkedHostMu sync.RWMutex
|
|
|
|
|
2016-10-08 21:00:50 +08:00
|
|
|
// A map of servers we have checked for time
|
|
|
|
var checkedHost = make(map[string]struct{}, 1)
|
|
|
|
|
|
|
|
// Check the server time is the same as ours, once for each server
|
|
|
|
func checkServerTime(req *http.Request, resp *http.Response) {
|
|
|
|
host := req.URL.Host
|
|
|
|
if req.Host != "" {
|
|
|
|
host = req.Host
|
|
|
|
}
|
2016-10-31 03:16:27 +08:00
|
|
|
checkedHostMu.RLock()
|
|
|
|
_, ok := checkedHost[host]
|
|
|
|
checkedHostMu.RUnlock()
|
|
|
|
if ok {
|
2016-10-08 21:00:50 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
dateString := resp.Header.Get("Date")
|
|
|
|
if dateString == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
date, err := http.ParseTime(dateString)
|
|
|
|
if err != nil {
|
2018-01-13 00:30:54 +08:00
|
|
|
fs.Debugf(nil, "Couldn't parse Date: from server %s: %q: %v", host, dateString, err)
|
2016-10-08 21:00:50 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
dt := time.Since(date)
|
|
|
|
const window = 5 * 60 * time.Second
|
|
|
|
if dt > window || dt < -window {
|
2018-01-13 00:30:54 +08:00
|
|
|
fs.Logf(nil, "Time may be set wrong - time from %q is %v different from this computer", host, dt)
|
2016-10-08 21:00:50 +08:00
|
|
|
}
|
2016-10-31 03:16:27 +08:00
|
|
|
checkedHostMu.Lock()
|
2016-10-08 21:00:50 +08:00
|
|
|
checkedHost[host] = struct{}{}
|
2016-10-31 03:16:27 +08:00
|
|
|
checkedHostMu.Unlock()
|
2016-10-08 21:00:50 +08:00
|
|
|
}
|
|
|
|
|
2017-11-21 20:14:52 +08:00
|
|
|
// cleanAuth gets rid of one authBuf header within the first 4k
|
|
|
|
func cleanAuth(buf, authBuf []byte) []byte {
|
2016-11-02 23:53:43 +08:00
|
|
|
// Find how much buffer to check
|
|
|
|
n := 4096
|
|
|
|
if len(buf) < n {
|
|
|
|
n = len(buf)
|
|
|
|
}
|
|
|
|
// See if there is an Authorization: header
|
|
|
|
i := bytes.Index(buf[:n], authBuf)
|
|
|
|
if i < 0 {
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
i += len(authBuf)
|
|
|
|
// Overwrite the next 4 chars with 'X'
|
|
|
|
for j := 0; i < len(buf) && j < 4; j++ {
|
|
|
|
if buf[i] == '\n' {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
buf[i] = 'X'
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
// Snip out to the next '\n'
|
|
|
|
j := bytes.IndexByte(buf[i:], '\n')
|
|
|
|
if j < 0 {
|
|
|
|
return buf[:i]
|
|
|
|
}
|
|
|
|
n = copy(buf[i:], buf[i+j:])
|
|
|
|
return buf[:i+n]
|
|
|
|
}
|
|
|
|
|
2017-11-21 20:14:52 +08:00
|
|
|
var authBufs = [][]byte{
|
|
|
|
[]byte("Authorization: "),
|
|
|
|
[]byte("X-Auth-Token: "),
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanAuths gets rid of all the possible Auth headers
|
|
|
|
func cleanAuths(buf []byte) []byte {
|
|
|
|
for _, authBuf := range authBufs {
|
|
|
|
buf = cleanAuth(buf, authBuf)
|
|
|
|
}
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2023-10-25 13:01:42 +08:00
|
|
|
var expireWindow = 30 * time.Second
|
|
|
|
|
|
|
|
func isCertificateExpired(cc *tls.Config) bool {
|
|
|
|
return len(cc.Certificates) > 0 && cc.Certificates[0].Leaf != nil && time.Until(cc.Certificates[0].Leaf.NotAfter) < expireWindow
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Transport) reloadCertificates() {
|
|
|
|
t.reloadMutex.Lock()
|
|
|
|
defer t.reloadMutex.Unlock()
|
|
|
|
// Check that the certificate is expired before trying to reload it
|
|
|
|
// it might have been reloaded while we were waiting to lock the mutex
|
|
|
|
if !isCertificateExpired(t.TLSClientConfig) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cert, err := tls.LoadX509KeyPair(t.clientCert, t.clientKey)
|
|
|
|
if err != nil {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "Failed to load --client-cert/--client-key pair: %v", err)
|
2023-10-25 13:01:42 +08:00
|
|
|
}
|
|
|
|
// Check if we need to parse the certificate again, we need it
|
|
|
|
// for checking the expiration date
|
|
|
|
if cert.Leaf == nil {
|
|
|
|
// Leaf is always the first certificate
|
|
|
|
cert.Leaf, err = x509.ParseCertificate(cert.Certificate[0])
|
|
|
|
if err != nil {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "Failed to parse the certificate")
|
2023-10-25 13:01:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
t.TLSClientConfig.Certificates = []tls.Certificate{cert}
|
|
|
|
}
|
|
|
|
|
2016-09-11 02:17:43 +08:00
|
|
|
// RoundTrip implements the RoundTripper interface.
|
|
|
|
func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
|
2023-10-25 13:01:42 +08:00
|
|
|
// Check if certificates are being used and the certificates are expired
|
|
|
|
if isCertificateExpired(t.TLSClientConfig) {
|
|
|
|
t.reloadCertificates()
|
|
|
|
}
|
|
|
|
|
2021-01-06 20:06:00 +08:00
|
|
|
// Limit transactions per second if required
|
|
|
|
accounting.LimitTPS(req.Context())
|
2016-09-11 02:17:43 +08:00
|
|
|
// Force user agent
|
2018-01-13 00:30:54 +08:00
|
|
|
req.Header.Set("User-Agent", t.userAgent)
|
2020-04-23 22:24:21 +08:00
|
|
|
// Set user defined headers
|
|
|
|
for _, option := range t.headers {
|
|
|
|
req.Header.Set(option.Key, option.Value)
|
|
|
|
}
|
2017-11-24 17:07:56 +08:00
|
|
|
// Filter the request if required
|
|
|
|
if t.filterRequest != nil {
|
|
|
|
t.filterRequest(req)
|
|
|
|
}
|
2017-02-09 19:01:20 +08:00
|
|
|
// Logf request
|
2018-01-13 00:30:54 +08:00
|
|
|
if t.dump&(fs.DumpHeaders|fs.DumpBodies|fs.DumpAuth|fs.DumpRequests|fs.DumpResponses) != 0 {
|
|
|
|
buf, _ := httputil.DumpRequestOut(req, t.dump&(fs.DumpBodies|fs.DumpRequests) != 0)
|
|
|
|
if t.dump&fs.DumpAuth == 0 {
|
2017-11-21 20:14:52 +08:00
|
|
|
buf = cleanAuths(buf)
|
2016-11-02 23:53:43 +08:00
|
|
|
}
|
2020-12-15 03:10:11 +08:00
|
|
|
logMutex.Lock()
|
2018-01-13 00:30:54 +08:00
|
|
|
fs.Debugf(nil, "%s", separatorReq)
|
|
|
|
fs.Debugf(nil, "%s (req %p)", "HTTP REQUEST", req)
|
|
|
|
fs.Debugf(nil, "%s", string(buf))
|
|
|
|
fs.Debugf(nil, "%s", separatorReq)
|
2020-12-15 03:10:11 +08:00
|
|
|
logMutex.Unlock()
|
2016-09-11 02:17:43 +08:00
|
|
|
}
|
|
|
|
// Do round trip
|
|
|
|
resp, err = t.Transport.RoundTrip(req)
|
2017-02-09 19:01:20 +08:00
|
|
|
// Logf response
|
2018-01-13 00:30:54 +08:00
|
|
|
if t.dump&(fs.DumpHeaders|fs.DumpBodies|fs.DumpAuth|fs.DumpRequests|fs.DumpResponses) != 0 {
|
2020-12-15 03:10:11 +08:00
|
|
|
logMutex.Lock()
|
2018-01-13 00:30:54 +08:00
|
|
|
fs.Debugf(nil, "%s", separatorResp)
|
|
|
|
fs.Debugf(nil, "%s (req %p)", "HTTP RESPONSE", req)
|
2016-09-11 02:17:43 +08:00
|
|
|
if err != nil {
|
2018-01-13 00:30:54 +08:00
|
|
|
fs.Debugf(nil, "Error: %v", err)
|
2016-09-11 02:17:43 +08:00
|
|
|
} else {
|
2018-01-13 00:30:54 +08:00
|
|
|
buf, _ := httputil.DumpResponse(resp, t.dump&(fs.DumpBodies|fs.DumpResponses) != 0)
|
|
|
|
fs.Debugf(nil, "%s", string(buf))
|
2016-09-11 02:17:43 +08:00
|
|
|
}
|
2018-01-13 00:30:54 +08:00
|
|
|
fs.Debugf(nil, "%s", separatorResp)
|
2020-12-15 03:10:11 +08:00
|
|
|
logMutex.Unlock()
|
2016-09-11 02:17:43 +08:00
|
|
|
}
|
2021-09-06 22:42:23 +08:00
|
|
|
// Update metrics
|
|
|
|
t.metrics.onResponse(req, resp)
|
|
|
|
|
2016-10-08 21:00:50 +08:00
|
|
|
if err == nil {
|
|
|
|
checkServerTime(req, resp)
|
|
|
|
}
|
2016-09-11 02:17:43 +08:00
|
|
|
return resp, err
|
|
|
|
}
|