Make Gateway.NoFetch apply to API too

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
Łukasz Magiera 2019-01-04 03:06:23 +01:00
parent 6cee21d39a
commit 7efffc3579
2 changed files with 16 additions and 2 deletions

View File

@ -560,13 +560,16 @@ func serveHTTPGateway(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, e
listeners = append(listeners, gwLis)
}
cmdctx := *cctx
cmdctx.Gateway = true
var opts = []corehttp.ServeOption{
corehttp.MetricsCollectionOption("gateway"),
corehttp.IPNSHostnameOption(),
corehttp.GatewayOption(writable, "/ipfs", "/ipns"),
corehttp.VersionOption(),
corehttp.CheckVersionOption(),
corehttp.CommandsROOption(*cctx),
corehttp.CommandsROOption(cmdctx),
}
if cfg.Experimental.P2pHttpProxy {

View File

@ -9,6 +9,7 @@ import (
core "github.com/ipfs/go-ipfs/core"
coreapi "github.com/ipfs/go-ipfs/core/coreapi"
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
loader "github.com/ipfs/go-ipfs/plugin/loader"
config "gx/ipfs/QmRd5T3VmYoX6jaNoZovFRQcwWHJqHgTVQTs1Qz92ELJ7C/go-ipfs-config"
@ -29,6 +30,7 @@ type Context struct {
config *config.Config
LoadConfig func(path string) (*config.Config, error)
Gateway bool
api coreiface.CoreAPI
node *core.IpfsNode
ConstructNode func() (*core.IpfsNode, error)
@ -68,7 +70,16 @@ func (c *Context) GetAPI() (coreiface.CoreAPI, error) {
if err != nil {
return nil, err
}
c.api, err = coreapi.NewCoreAPI(n)
offline := false
if c.Gateway {
cfg, err := c.GetConfig()
if err != nil {
return nil, err
}
offline = cfg.Gateway.NoFetch
}
c.api, err = coreapi.NewCoreAPI(n, options.Api.Offline(offline))
if err != nil {
return nil, err
}