Skip to content

Commit

Permalink
fix: Unix domain socket maddrs used with NewApi
Browse files Browse the repository at this point in the history
  • Loading branch information
djdv committed Mar 12, 2024
1 parent e22f47a commit 23ca62a
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions client/rpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -98,11 +99,29 @@ func ApiAddr(ipfspath string) (ma.Multiaddr, error) {

// NewApi constructs HttpApi with specified endpoint.
func NewApi(a ma.Multiaddr) (*HttpApi, error) {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DisableKeepAlives: true,
}

network, address, err := manet.DialArgs(a)
if err != nil {
return nil, err
}
if network == "unix" {
transport.DialContext = func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", address)
}
c := &http.Client{
Transport: transport,
}
// This will create an API client which
// makes requests to `http://unix`.
return NewURLApiWithClient(network, c)
}

c := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DisableKeepAlives: true,
},
Transport: transport,
}

return NewApiWithClient(a, c)
Expand Down

0 comments on commit 23ca62a

Please sign in to comment.