fix unsafe dereference

This commit is contained in:
Niko Storni 2021-05-21 21:06:59 +02:00
parent df881e16b5
commit 9670bc14f8

View file

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"io" "io"
"io/ioutil" "io/ioutil"
"net"
"net/http" "net/http"
"sync" "sync"
"time" "time"
@ -140,14 +141,20 @@ func putBuffer(buf *bytes.Buffer) {
// getClient gets an http client that's customized to be more performant when dealing with blobs of 2MB in size (most of our blobs) // getClient gets an http client that's customized to be more performant when dealing with blobs of 2MB in size (most of our blobs)
func getClient() *http.Client { func getClient() *http.Client {
// Customize the Transport to have larger connection pool // Customize the Transport to have larger connection pool
defaultRoundTripper := http.DefaultTransport defaultTransport := &http.Transport{
defaultTransportPointer := defaultRoundTripper.(*http.Transport) DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
defaultTransport := *defaultTransportPointer // dereference it to get a copy of the struct that the pointer points to KeepAlive: 30 * time.Second,
defaultTransport.MaxIdleConns = 100 }).DialContext,
defaultTransport.DisableCompression = true ForceAttemptHTTP2: true,
defaultTransport.MaxIdleConnsPerHost = 100 MaxIdleConns: 100,
defaultTransport.ReadBufferSize = stream.MaxBlobSize + 1024*10 //add an extra few KBs to make sure it fits the extra information IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
return &http.Client{Transport: &defaultTransport} ExpectContinueTimeout: 1 * time.Second,
DisableCompression: true,
MaxIdleConnsPerHost: 100,
ReadBufferSize: stream.MaxBlobSize + 1024*10, //add an extra few KBs to make sure it fits the extra information
}
return &http.Client{Transport: defaultTransport}
} }