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:
MickaelK
2026-04-22 14:32:29 +10:00
parent f47ff6cfc3
commit 463ac34ab1
2 changed files with 15 additions and 7 deletions
+14 -2
View File
@@ -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...),
}
}
+1 -5
View File
@@ -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
}