Fix panic. Don't handle errors with fallthrough.
License: MIT Signed-off-by: Brendan McMillion <brendan@cloudflare.com>
Brendan McMillion committed
Jun 3, 2018 at 13:55 UTC
8387c394e9cec5e7a6b18d8f23486da3ae555aca
5 files changed
+11
-19
cmd/ipfs/daemon.go
+1
-1
@@ -151,7 +151,7 @@ Headers.
151
Options: []cmdkit.Option{
152
cmdkit.BoolOption(initOptionKwd, "Initialize ipfs with default settings if not already initialized"),
153
cmdkit.StringOption(initProfileOptionKwd, "Configuration profiles to apply for --init. See ipfs init --help for more"),
154
- cmdkit.StringOption(routingOptionKwd, "Overrides the routing option").WithDefault("default"),
154
+ cmdkit.StringOption(routingOptionKwd, "Overrides the routing option").WithDefault(routingOptionDefaultKwd),
155
cmdkit.BoolOption(mountKwd, "Mounts IPFS to the filesystem"),
156
cmdkit.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"),
157
cmdkit.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount). Defaults to config setting."),
core/core.go
-1
@@ -158,7 +158,6 @@ type Mounts struct {
158
}
159
160
func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption RoutingOption, hostOption HostOption, do DiscoveryOption, pubsub, ipnsps, mplex bool) error {
161
-
161
if n.PeerHost != nil { // already online.
162
return errors.New("node already online")
163
}
core/corehttp/commands.go
+2
-2
@@ -162,10 +162,10 @@ func CheckVersionOption() ServeOption {
162
pth := path.SplitList(cmdqry)
163
164
// backwards compatibility to previous version check
165
- if pth[1] != "version" {
165
+ if len(pth) >= 2 && pth[1] != "version" {
166
clientVersion := r.UserAgent()
167
// skips check if client is not go-ipfs
168
- if clientVersion != "" && strings.Contains(clientVersion, "/go-ipfs/") && daemonVersion != clientVersion {
168
+ if strings.Contains(clientVersion, "/go-ipfs/") && daemonVersion != clientVersion {
169
http.Error(w, fmt.Sprintf("%s (%s != %s)", errAPIVersionMismatch, daemonVersion, clientVersion), http.StatusBadRequest)
170
return
171
}
core/corehttp/gateway_handler.go
+7
-14
@@ -132,7 +132,6 @@ func (i *gatewayHandler) optionsHandler(w http.ResponseWriter, r *http.Request)
132
}
133
134
func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
135
-
135
urlPath := r.URL.Path
136
escapedURLPath := r.URL.EscapedPath()
137
@@ -140,8 +139,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
139
// the prefix header can be set to signal this sub-path.
140
// It will be prepended to links in directory listings and the index.html redirect.
141
prefix := ""
143
- if prefixHdr := r.Header["X-Ipfs-Gateway-Prefix"]; len(prefixHdr) > 0 {
144
- prfx := prefixHdr[0]
142
+ if prfx := r.Header.Get("X-Ipfs-Gateway-Prefix"); len(prfx) > 0 {
143
for _, p := range i.config.PathPrefixes {
144
if prfx == p || strings.HasPrefix(prfx, p+"/") {
145
prefix = prfx
@@ -157,8 +155,8 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
155
// the redirects and links would end up as http://example.net/ipns/example.net
156
originalUrlPath := prefix + urlPath
157
ipnsHostname := false
160
- if hdr := r.Header["X-Ipns-Original-Path"]; len(hdr) > 0 {
161
- originalUrlPath = prefix + hdr[0]
158
+ if hdr := r.Header.Get("X-Ipns-Original-Path"); len(hdr) > 0 {
159
+ originalUrlPath = prefix + hdr
160
ipnsHostname = true
161
}
162
@@ -170,15 +168,10 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
168
169
// Resolve path to the final DAG node for the ETag
170
resolvedPath, err := i.api.ResolvePath(ctx, parsedPath)
173
- switch err {
174
- case nil:
175
- case coreiface.ErrOffline:
176
- if !i.node.OnlineMode() {
177
- webError(w, "ipfs resolve -r "+escapedURLPath, err, http.StatusServiceUnavailable)
178
- return
179
- }
180
- fallthrough
181
- default:
171
+ if err == coreiface.ErrOffline && !i.node.OnlineMode() {
172
+ webError(w, "ipfs resolve -r "+escapedURLPath, err, http.StatusServiceUnavailable)
173
+ return
174
+ } else if err != nil {
175
webError(w, "ipfs resolve -r "+escapedURLPath, err, http.StatusNotFound)
176
return
177
}
core/corehttp/ipns_hostname.go
+1
-1
@@ -26,7 +26,7 @@ func IPNSHostnameOption() ServeOption {
26
if len(host) > 0 && isd.IsDomain(host) {
27
name := "/ipns/" + host
28
if _, err := n.Namesys.Resolve(ctx, name, nsopts.Depth(1)); err == nil {
29
- r.Header["X-Ipns-Original-Path"] = []string{r.URL.Path}
29
+ r.Header.Set("X-Ipns-Original-Path", r.URL.Path)
30
r.URL.Path = name + r.URL.Path
31
}
32
}