blossom: fasthttp dialer to respect proxy environment variables.
This commit is contained in:
+13
-5
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
"github.com/valyala/fasthttp/fasthttpproxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client represents a Blossom client for interacting with a media server
|
// Client represents a Blossom client for interacting with a media server
|
||||||
@@ -28,6 +29,17 @@ func NewClient(mediaserver string, signer nostr.Signer) *Client {
|
|||||||
|
|
||||||
// createHTTPClient creates a properly configured HTTP client
|
// createHTTPClient creates a properly configured HTTP client
|
||||||
func createHTTPClient() *fasthttp.Client {
|
func createHTTPClient() *fasthttp.Client {
|
||||||
|
d := fasthttpproxy.Dialer{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
ConnectTimeout: 10 * time.Second,
|
||||||
|
TCPDialer: fasthttp.TCPDialer{
|
||||||
|
// increase DNS cache time to an hour instead of default minute
|
||||||
|
Concurrency: 4096,
|
||||||
|
DNSCacheDuration: time.Hour,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
dialFunc, _ := d.GetDialFunc(true)
|
||||||
|
|
||||||
return &fasthttp.Client{
|
return &fasthttp.Client{
|
||||||
MaxIdleConnDuration: time.Hour,
|
MaxIdleConnDuration: time.Hour,
|
||||||
DisableHeaderNamesNormalizing: true, // because our headers are properly constructed
|
DisableHeaderNamesNormalizing: true, // because our headers are properly constructed
|
||||||
@@ -35,11 +47,7 @@ func createHTTPClient() *fasthttp.Client {
|
|||||||
|
|
||||||
Name: "nl-b", // user-agent
|
Name: "nl-b", // user-agent
|
||||||
|
|
||||||
// increase DNS cache time to an hour instead of default minute
|
Dial: dialFunc,
|
||||||
Dial: (&fasthttp.TCPDialer{
|
|
||||||
Concurrency: 4096,
|
|
||||||
DNSCacheDuration: time.Hour,
|
|
||||||
}).Dial,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user