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 Jul 14, 2023
1 parent 4a5e99d commit 7347798
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions client/rpc/api.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package rpc

import (
"context"
"errors"
"fmt"
"net"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -90,11 +92,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
}

Check warning on line 103 in client/rpc/api.go

View check run for this annotation

Codecov / codecov/patch

client/rpc/api.go#L102-L103

Added lines #L102 - L103 were not covered by tests
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)

Check warning on line 113 in client/rpc/api.go

View check run for this annotation

Codecov / codecov/patch

client/rpc/api.go#L105-L113

Added lines #L105 - L113 were not covered by tests
}

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

return NewApiWithClient(a, c)
Expand Down

0 comments on commit 7347798

Please sign in to comment.