mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2026-10-19 16:14:39 +00:00
fix (sdk): http client edge case
before this, when using the gateway we'd be creating new sockets everytime, making it possible to consume all the available sockets in the os when we should be reusing those as much as possible
This commit is contained in:
+14
-2
@@ -1,18 +1,30 @@
|
||||
package sdk
|
||||
|
||||
import "net/url"
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
. "github.com/mickael-kerjean/filestash/server/common"
|
||||
)
|
||||
|
||||
type Filestash struct {
|
||||
Token string
|
||||
URL string
|
||||
Insecure bool
|
||||
Storage string
|
||||
Client *http.Client
|
||||
}
|
||||
|
||||
func NewClient() Filestash {
|
||||
baseURL, _ := url.Parse(localURL())
|
||||
insecure := baseURL.Hostname() == "localhost" || baseURL.Hostname() == "127.0.0.1"
|
||||
opts := []HTTPClientOption{WithoutTimeout}
|
||||
if insecure {
|
||||
opts = append(opts, WithInsecure)
|
||||
}
|
||||
return Filestash{
|
||||
URL: baseURL.String(),
|
||||
Insecure: (baseURL.Hostname() == "localhost" || baseURL.Hostname() == "127.0.0.1"),
|
||||
Insecure: insecure,
|
||||
Client: HTTPClient(opts...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,7 @@ func (this Filestash) request(method string, url string, body io.Reader) (io.Rea
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", this.Token))
|
||||
req.Header.Set("X-Requested-With", "XmlHttpRequest")
|
||||
|
||||
opts := []HTTPClientOption{WithoutTimeout}
|
||||
if this.Insecure {
|
||||
opts = append(opts, WithInsecure)
|
||||
}
|
||||
resp, err := HTTPClient(opts...).Do(req)
|
||||
resp, err := this.Client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user