Make Gateway.NoFetch apply to API too
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Jan 4, 2019 at 03:06 UTC
7efffc3579b5ca100d29e68c9b39bfaac65b0152
2 files changed
+16
-2
cmd/ipfs/daemon.go
+4
-1
@@ -560,13 +560,16 @@ func serveHTTPGateway(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, e
560
listeners = append(listeners, gwLis)
561
}
562
563
+ cmdctx := *cctx
564
+ cmdctx.Gateway = true
565
+
566
var opts = []corehttp.ServeOption{
567
corehttp.MetricsCollectionOption("gateway"),
568
corehttp.IPNSHostnameOption(),
569
corehttp.GatewayOption(writable, "/ipfs", "/ipns"),
570
corehttp.VersionOption(),
571
corehttp.CheckVersionOption(),
569
- corehttp.CommandsROOption(*cctx),
572
+ corehttp.CommandsROOption(cmdctx),
573
}
574
575
if cfg.Experimental.P2pHttpProxy {
commands/context.go
+12
-1
@@ -9,6 +9,7 @@ import (
9
core "github.com/ipfs/go-ipfs/core"
10
coreapi "github.com/ipfs/go-ipfs/core/coreapi"
11
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
12
+ options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
13
loader "github.com/ipfs/go-ipfs/plugin/loader"
14
15
config "gx/ipfs/QmRd5T3VmYoX6jaNoZovFRQcwWHJqHgTVQTs1Qz92ELJ7C/go-ipfs-config"
@@ -29,6 +30,7 @@ type Context struct {
30
config *config.Config
31
LoadConfig func(path string) (*config.Config, error)
32
33
+ Gateway bool
34
api coreiface.CoreAPI
35
node *core.IpfsNode
36
ConstructNode func() (*core.IpfsNode, error)
@@ -68,7 +70,16 @@ func (c *Context) GetAPI() (coreiface.CoreAPI, error) {
70
if err != nil {
71
return nil, err
72
}
71
- c.api, err = coreapi.NewCoreAPI(n)
73
+ offline := false
74
+ if c.Gateway {
75
+ cfg, err := c.GetConfig()
76
+ if err != nil {
77
+ return nil, err
78
+ }
79
+ offline = cfg.Gateway.NoFetch
80
+ }
81
+
82
+ c.api, err = coreapi.NewCoreAPI(n, options.Api.Offline(offline))
83
if err != nil {
84
return nil, err
85
}