b0: remove hardcoded timeouts in blossom client.

see nostr:nevent1qvzqqqqqqypzqmjxss3dld622uu8q25gywum9qtg4w4cv4064jmg20xsac2aam5nqyd8wumn8ghj7urewfsk66ty9enxjct5dfskvtnrdakj7qpqrfcfcq52gfv6znm8hkdpa3rlxad72zl6ah4haaneqzdxwmnamg3sk2sztg
This commit is contained in:
fiatjaf
2025-11-04 08:26:08 -03:00
parent b87bc0ede4
commit 38a6ca92b9
2 changed files with 12 additions and 9 deletions

View File

@@ -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,

View File

@@ -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)
}