Skip to content

Commit 0b12787

Browse files
authored
fix revproxy client scheme (textileio#581)
- Fix using `--ipfsrevproxy` with HTTPS DNS endpoint.
1 parent 5c8ca10 commit 0b12787

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

api/client/ffs.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,17 +804,18 @@ func newDecoratedIPFSAPI(proxyAddr, ffsToken string) (*httpapi.HttpApi, error) {
804804
if len(ipport) != 2 {
805805
return nil, fmt.Errorf("ipfs addr is invalid")
806806
}
807-
cm, err := multiaddr.NewComponent("ip4", ipport[0])
807+
cm, err := multiaddr.NewComponent("dns4", ipport[0])
808808
if err != nil {
809809
return nil, err
810810
}
811811
cp, err := multiaddr.NewComponent("tcp", ipport[1])
812812
if err != nil {
813813
return nil, err
814814
}
815+
useHTTPS := ipport[1] == "443"
815816
ipfsMaddr := cm.Encapsulate(cp)
816817
customClient := http.DefaultClient
817-
customClient.Transport = newFFSHeaderDecorator(ffsToken)
818+
customClient.Transport = newFFSHeaderDecorator(ffsToken, useHTTPS)
818819
ipfs, err := httpapi.NewApiWithClient(ipfsMaddr, customClient)
819820
if err != nil {
820821
return nil, err
@@ -824,16 +825,21 @@ func newDecoratedIPFSAPI(proxyAddr, ffsToken string) (*httpapi.HttpApi, error) {
824825

825826
type ffsHeaderDecorator struct {
826827
ffsToken string
828+
useHTTPS bool
827829
}
828830

829-
func newFFSHeaderDecorator(ffsToken string) *ffsHeaderDecorator {
831+
func newFFSHeaderDecorator(ffsToken string, useHTTPS bool) *ffsHeaderDecorator {
830832
return &ffsHeaderDecorator{
831833
ffsToken: ffsToken,
834+
useHTTPS: useHTTPS,
832835
}
833836
}
834837

835838
func (fhd ffsHeaderDecorator) RoundTrip(req *http.Request) (*http.Response, error) {
836839
req.Header["x-ipfs-ffs-auth"] = []string{fhd.ffsToken}
840+
if fhd.useHTTPS {
841+
req.URL.Scheme = "https"
842+
}
837843

838844
return http.DefaultTransport.RoundTrip(req)
839845
}

cli-docs/pow/pow_ffs_get.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pow ffs get [cid] [output file path] [flags]
1515
```
1616
-f, --folder Indicates that the retrieved Cid is a folder
1717
-h, --help help for get
18-
--ipfsrevproxy string Powergate IPFS reverse proxy multiaddr (default "127.0.0.1:6002")
18+
--ipfsrevproxy string Powergate IPFS reverse proxy DNS address. If port 443, is assumed is a HTTPS endpoint. (default "localhost:6002")
1919
-t, --token string token of the request
2020
```
2121

cmd/pow/cmd/ffs_get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
func init() {
1717
ffsGetCmd.Flags().StringP("token", "t", "", "token of the request")
18-
ffsGetCmd.Flags().String("ipfsrevproxy", "127.0.0.1:6002", "Powergate IPFS reverse proxy multiaddr")
18+
ffsGetCmd.Flags().String("ipfsrevproxy", "localhost:6002", "Powergate IPFS reverse proxy DNS address. If port 443, is assumed is a HTTPS endpoint.")
1919
ffsGetCmd.Flags().BoolP("folder", "f", false, "Indicates that the retrieved Cid is a folder")
2020
ffsCmd.AddCommand(ffsGetCmd)
2121
}

0 commit comments

Comments
 (0)