提交 0aa136a9 作者: Jeromy Johnson 提交者: GitHub

Merge pull request #3206 from ipfs/feat/writable-flag

gateway: fix --writable flag :|
...@@ -409,9 +409,9 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) { ...@@ -409,9 +409,9 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
if err != nil { if err != nil {
return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccessKwd, 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 { if unrestricted {
gatewayOpt = corehttp.GatewayOption("/ipfs", "/ipns") gatewayOpt = corehttp.GatewayOption(true, "/ipfs", "/ipns")
} }
var opts = []corehttp.ServeOption{ var opts = []corehttp.ServeOption{
...@@ -480,8 +480,8 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) { ...@@ -480,8 +480,8 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
if err != nil { if err != nil {
return fmt.Errorf("serveHTTPGateway: req.Option(%s) failed: %s", writableKwd, err), nil return fmt.Errorf("serveHTTPGateway: req.Option(%s) failed: %s", writableKwd, err), nil
} }
if writableOptionFound { if !writableOptionFound {
cfg.Gateway.Writable = writable writable = cfg.Gateway.Writable
} }
gwLis, err := manet.Listen(gatewayMaddr) gwLis, err := manet.Listen(gatewayMaddr)
...@@ -502,7 +502,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) { ...@@ -502,7 +502,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
corehttp.CommandsROOption(*req.InvocContext()), corehttp.CommandsROOption(*req.InvocContext()),
corehttp.VersionOption(), corehttp.VersionOption(),
corehttp.IPNSHostnameOption(), corehttp.IPNSHostnameOption(),
corehttp.GatewayOption("/ipfs", "/ipns"), corehttp.GatewayOption(writable, "/ipfs", "/ipns"),
} }
if len(cfg.Gateway.RootRedirect) > 0 { if len(cfg.Gateway.RootRedirect) > 0 {
......
...@@ -81,16 +81,10 @@ func run(ipfsPath, watchPath string) error { ...@@ -81,16 +81,10 @@ func run(ipfsPath, watchPath string) error {
} }
defer node.Close() defer node.Close()
cfg, err := node.Repo.Config()
if err != nil {
return err
}
cfg.Gateway.Writable = true
if *http { if *http {
addr := "/ip4/127.0.0.1/tcp/5001" addr := "/ip4/127.0.0.1/tcp/5001"
var opts = []corehttp.ServeOption{ var opts = []corehttp.ServeOption{
corehttp.GatewayOption("/ipfs", "/ipns"), corehttp.GatewayOption(true, "/ipfs", "/ipns"),
corehttp.WebUIOption, corehttp.WebUIOption,
corehttp.CommandsOption(cmdCtx(node, ipfsPath)), corehttp.CommandsOption(cmdCtx(node, ipfsPath)),
} }
......
...@@ -16,7 +16,7 @@ type GatewayConfig struct { ...@@ -16,7 +16,7 @@ type GatewayConfig struct {
PathPrefixes []string 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) { return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
cfg, err := n.Repo.Config() cfg, err := n.Repo.Config()
if err != nil { if err != nil {
...@@ -25,7 +25,7 @@ func GatewayOption(paths ...string) ServeOption { ...@@ -25,7 +25,7 @@ func GatewayOption(paths ...string) ServeOption {
gateway := newGatewayHandler(n, GatewayConfig{ gateway := newGatewayHandler(n, GatewayConfig{
Headers: cfg.Gateway.HTTPHeaders, Headers: cfg.Gateway.HTTPHeaders,
Writable: cfg.Gateway.Writable, Writable: writable,
PathPrefixes: cfg.Gateway.PathPrefixes, PathPrefixes: cfg.Gateway.PathPrefixes,
}) })
......
...@@ -104,7 +104,7 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core ...@@ -104,7 +104,7 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core
ts.Listener, ts.Listener,
VersionOption(), VersionOption(),
IPNSHostnameOption(), IPNSHostnameOption(),
GatewayOption("/ipfs", "/ipns"), GatewayOption(false, "/ipfs", "/ipns"),
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
......
...@@ -9,7 +9,22 @@ test_description="Test HTTP Gateway (Writable)" ...@@ -9,7 +9,22 @@ test_description="Test HTTP Gateway (Writable)"
. lib/test-lib.sh . lib/test-lib.sh
test_init_ipfs 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_config_ipfs_gateway_writable
test_launch_ipfs_daemon --writable=false
test_expect_success "ipfs daemon --writable=false overrides Writable=true config" '
curl -v -X POST http://$GWAY_ADDR/ipfs/ 2> outfile &&
grep "HTTP/1.1 405 Method Not Allowed" outfile
'
test_kill_ipfs_daemon
test_launch_ipfs_daemon test_launch_ipfs_daemon
port=$GWAY_PORT port=$GWAY_PORT
......
...@@ -109,7 +109,7 @@ func run() error { ...@@ -109,7 +109,7 @@ func run() error {
opts := []corehttp.ServeOption{ opts := []corehttp.ServeOption{
corehttp.CommandsOption(cmdCtx(node, repoPath)), corehttp.CommandsOption(cmdCtx(node, repoPath)),
corehttp.GatewayOption(), corehttp.GatewayOption(false),
} }
if *cat { if *cat {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论