Skip to content

Commit

Permalink
Add http(s) scheme to core.Resolver
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
  • Loading branch information
rht committed Jan 15, 2016
1 parent a28e02b commit 2c5eedc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/pathresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package core

import (
"errors"
"net/http"
"strings"

context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/ipfs/go-ipfs/importer"
"github.com/ipfs/go-ipfs/importer/chunk"

merkledag "github.com/ipfs/go-ipfs/merkledag"
path "github.com/ipfs/go-ipfs/path"
Expand Down Expand Up @@ -50,6 +53,17 @@ func Resolve(ctx context.Context, n *IpfsNode, p path.Path) (*merkledag.Node, er
if err != nil {
return nil, err
}
} else if strings.HasPrefix(p.String(), "/http/") || strings.HasPrefix(p.String(), "/https/") {
// resolve https paths
url := p.String()[1:] // string the first '/'
url = strings.Replace(url, "/", "://", 1)
// TODO: wire ctx
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return importer.BuildDagFromReader(n.DAG, chunk.DefaultSplitter(resp.Body))
}

// ok, we have an ipfs path now (or what we'll treat as one)
Expand Down

0 comments on commit 2c5eedc

Please sign in to comment.