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"
"io"
"io/ioutil"
"net"
"net/http"
"sync"
"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)
func getClient() *http.Client {
// Customize the Transport to have larger connection pool
defaultRoundTripper := http.DefaultTransport
defaultTransportPointer := defaultRoundTripper.(*http.Transport)
defaultTransport := *defaultTransportPointer // dereference it to get a copy of the struct that the pointer points to
defaultTransport.MaxIdleConns = 100
defaultTransport.DisableCompression = true
defaultTransport.MaxIdleConnsPerHost = 100
defaultTransport.ReadBufferSize = stream.MaxBlobSize + 1024*10 //add an extra few KBs to make sure it fits the extra information
return &http.Client{Transport: &defaultTransport}
defaultTransport := &http.Transport{
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
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}
}