diff --git a/nipb0/blossom/client.go b/nipb0/blossom/client.go index 201945d..fc878d3 100644 --- a/nipb0/blossom/client.go +++ b/nipb0/blossom/client.go @@ -30,16 +30,13 @@ func NewClient(mediaserver string, signer nostr.Signer) *Client { // createHTTPClient creates a properly configured HTTP client func createHTTPClient() *fasthttp.Client { - readTimeout, _ := time.ParseDuration("10s") - writeTimeout, _ := time.ParseDuration("10s") - maxIdleConnDuration, _ := time.ParseDuration("1h") return &fasthttp.Client{ - ReadTimeout: readTimeout, - WriteTimeout: writeTimeout, - MaxIdleConnDuration: maxIdleConnDuration, - NoDefaultUserAgentHeader: true, // Don't send: User-Agent: fasthttp - DisableHeaderNamesNormalizing: true, // If you set the case on your headers correctly you can enable this + MaxIdleConnDuration: time.Hour, + DisableHeaderNamesNormalizing: true, // because our headers are properly constructed DisablePathNormalizing: true, + + Name: "nl-b", // user-agent + // increase DNS cache time to an hour instead of default minute Dial: (&fasthttp.TCPDialer{ Concurrency: 4096, diff --git a/nipb0/blossom/http.go b/nipb0/blossom/http.go index c31e5ee..0551aeb 100644 --- a/nipb0/blossom/http.go +++ b/nipb0/blossom/http.go @@ -46,7 +46,13 @@ func (c *Client) httpCall( req.SetBodyStream(body, int(contentSize)) } - err := c.httpClient.Do(req, resp) + var err error + if deadline, ok := ctx.Deadline(); ok { + err = c.httpClient.DoDeadline(req, resp, deadline) + } else { + err = c.httpClient.Do(req, resp) + } + if err != nil { return fmt.Errorf("failed to call %s: %w\n", url, err) }