gateway: fix --writable flag :|
License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>
Lars Gierth committed
Sep 11, 2016 at 05:51 UTC
fc8e6de6a9232830b4219adbf1bbd7a1073f668a
6 files changed
+25
-16
cmd/ipfs/daemon.go
+5
-5
@@ -409,9 +409,9 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
409
if err != nil {
410
return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccessKwd, err), nil
411
}
412
- gatewayOpt := corehttp.GatewayOption(corehttp.WebUIPaths...)
412
+ gatewayOpt := corehttp.GatewayOption(false, corehttp.WebUIPaths...)
413
if unrestricted {
414
- gatewayOpt = corehttp.GatewayOption("/ipfs", "/ipns")
414
+ gatewayOpt = corehttp.GatewayOption(true, "/ipfs", "/ipns")
415
}
416
417
var opts = []corehttp.ServeOption{
@@ -480,8 +480,8 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
480
if err != nil {
481
return fmt.Errorf("serveHTTPGateway: req.Option(%s) failed: %s", writableKwd, err), nil
482
}
483
- if writableOptionFound {
484
- cfg.Gateway.Writable = writable
483
+ if !writableOptionFound {
484
+ writable = cfg.Gateway.Writable
485
}
486
487
gwLis, err := manet.Listen(gatewayMaddr)
@@ -502,7 +502,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
502
corehttp.CommandsROOption(*req.InvocContext()),
503
corehttp.VersionOption(),
504
corehttp.IPNSHostnameOption(),
505
- corehttp.GatewayOption("/ipfs", "/ipns"),
505
+ corehttp.GatewayOption(writable, "/ipfs", "/ipns"),
506
}
507
508
if len(cfg.Gateway.RootRedirect) > 0 {
cmd/ipfswatch/main.go
+1
-7
@@ -81,16 +81,10 @@ func run(ipfsPath, watchPath string) error {
81
}
82
defer node.Close()
83
84
- cfg, err := node.Repo.Config()
85
- if err != nil {
86
- return err
87
- }
88
- cfg.Gateway.Writable = true
89
-
84
if *http {
85
addr := "/ip4/127.0.0.1/tcp/5001"
86
var opts = []corehttp.ServeOption{
93
- corehttp.GatewayOption("/ipfs", "/ipns"),
87
+ corehttp.GatewayOption(true, "/ipfs", "/ipns"),
88
corehttp.WebUIOption,
89
corehttp.CommandsOption(cmdCtx(node, ipfsPath)),
90
}
core/corehttp/gateway.go
+2
-2
@@ -16,7 +16,7 @@ type GatewayConfig struct {
16
PathPrefixes []string
17
}
18
19
-func GatewayOption(paths ...string) ServeOption {
19
+func GatewayOption(writable bool, paths ...string) ServeOption {
20
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
21
cfg, err := n.Repo.Config()
22
if err != nil {
@@ -25,7 +25,7 @@ func GatewayOption(paths ...string) ServeOption {
25
26
gateway := newGatewayHandler(n, GatewayConfig{
27
Headers: cfg.Gateway.HTTPHeaders,
28
- Writable: cfg.Gateway.Writable,
28
+ Writable: writable,
29
PathPrefixes: cfg.Gateway.PathPrefixes,
30
})
31
core/corehttp/gateway_test.go
+1
-1
@@ -104,7 +104,7 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core
104
ts.Listener,
105
VersionOption(),
106
IPNSHostnameOption(),
107
- GatewayOption("/ipfs", "/ipns"),
107
+ GatewayOption(false, "/ipfs", "/ipns"),
108
)
109
if err != nil {
110
t.Fatal(err)
test/sharness/t0111-gateway-writeable.sh
+15
@@ -9,7 +9,22 @@ test_description="Test HTTP Gateway (Writable)"
9
. lib/test-lib.sh
10
11
test_init_ipfs
12
+
13
+test_launch_ipfs_daemon --writable
14
+test_expect_success "ipfs daemon --writable overrides config" '
15
+ curl -v -X POST http://$GWAY_ADDR/ipfs/ 2> outfile &&
16
+ grep "HTTP/1.1 201 Created" outfile &&
17
+ grep "Location: /ipfs/QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH" outfile
18
+'
19
+test_kill_ipfs_daemon
20
+
21
test_config_ipfs_gateway_writable
22
+test_launch_ipfs_daemon --writable=false
23
+test_expect_success "ipfs daemon --writable=false overrides Writable=true config" '
24
+ curl -v -X POST http://$GWAY_ADDR/ipfs/ 2> outfile &&
25
+ grep "HTTP/1.1 405 Method Not Allowed" outfile
26
+'
27
+test_kill_ipfs_daemon
28
test_launch_ipfs_daemon
29
30
port=$GWAY_PORT
test/supernode_client/main.go
+1
-1
@@ -109,7 +109,7 @@ func run() error {
109
110
opts := []corehttp.ServeOption{
111
corehttp.CommandsOption(cmdCtx(node, repoPath)),
112
- corehttp.GatewayOption(),
112
+ corehttp.GatewayOption(false),
113
}
114
115
if *cat {