Skip to content

Commit

Permalink
gateway: fix --writable flag :|
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Lars Gierth <larsg@systemli.org>
  • Loading branch information
Lars Gierth committed Sep 11, 2016
1 parent 0e2b4eb commit 5c38677
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
10 changes: 5 additions & 5 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
if err != nil {
return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccessKwd, err), nil
}
gatewayOpt := corehttp.GatewayOption(corehttp.WebUIPaths...)
gatewayOpt := corehttp.GatewayOption(false, corehttp.WebUIPaths...)
if unrestricted {
gatewayOpt = corehttp.GatewayOption("/ipfs", "/ipns")
gatewayOpt = corehttp.GatewayOption(true, "/ipfs", "/ipns")
}

var opts = []corehttp.ServeOption{
Expand Down Expand Up @@ -480,8 +480,8 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
if err != nil {
return fmt.Errorf("serveHTTPGateway: req.Option(%s) failed: %s", writableKwd, err), nil
}
if writableOptionFound {
cfg.Gateway.Writable = writable
if !writableOptionFound {
writable = cfg.Gateway.Writable
}

gwLis, err := manet.Listen(gatewayMaddr)
Expand All @@ -502,7 +502,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
corehttp.CommandsROOption(*req.InvocContext()),
corehttp.VersionOption(),
corehttp.IPNSHostnameOption(),
corehttp.GatewayOption("/ipfs", "/ipns"),
corehttp.GatewayOption(writable, "/ipfs", "/ipns"),
}

if len(cfg.Gateway.RootRedirect) > 0 {
Expand Down
3 changes: 1 addition & 2 deletions cmd/ipfswatch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ func run(ipfsPath, watchPath string) error {
if err != nil {
return err
}
cfg.Gateway.Writable = true

if *http {
addr := "/ip4/127.0.0.1/tcp/5001"
var opts = []corehttp.ServeOption{
corehttp.GatewayOption("/ipfs", "/ipns"),
corehttp.GatewayOption(true, "/ipfs", "/ipns"),
corehttp.WebUIOption,
corehttp.CommandsOption(cmdCtx(node, ipfsPath)),
}
Expand Down
4 changes: 2 additions & 2 deletions core/corehttp/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type GatewayConfig struct {
PathPrefixes []string
}

func GatewayOption(paths ...string) ServeOption {
func GatewayOption(writable bool, paths ...string) ServeOption {
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
cfg, err := n.Repo.Config()
if err != nil {
Expand All @@ -25,7 +25,7 @@ func GatewayOption(paths ...string) ServeOption {

gateway := newGatewayHandler(n, GatewayConfig{
Headers: cfg.Gateway.HTTPHeaders,
Writable: cfg.Gateway.Writable,
Writable: writable,
PathPrefixes: cfg.Gateway.PathPrefixes,
})

Expand Down
10 changes: 10 additions & 0 deletions test/sharness/t0111-gateway-writeable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ test_description="Test HTTP Gateway (Writable)"
. lib/test-lib.sh

test_init_ipfs

test_launch_ipfs_daemon --writable

test_expect_success "ipfs daemon --writable overrides config" '
curl -v -X POST http://$GWAY_ADDR/ipfs/ 2> outfile &&
grep "HTTP/1.1 201 Created" outfile &&
grep "Location: /ipfs/QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH" outfile
'

test_kill_ipfs_daemon
test_config_ipfs_gateway_writable
test_launch_ipfs_daemon

Expand Down

0 comments on commit 5c38677

Please sign in to comment.