coreapi unixfs: gw handler cleanup
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Oct 23, 2018 at 01:14 UTC
519c67a00cd0b5354f4489b736350bea35bcac80
2 files changed
+7
-9
core/coreapi/coreapi.go
+1
-1
@@ -91,4 +91,4 @@ func (api *CoreAPI) PubSub() coreiface.PubSubAPI {
91
func (api *CoreAPI) getSession(ctx context.Context) *CoreAPI {
92
ng := dag.NewReadOnlyDagService(dag.NewSession(ctx, api.dag))
93
return &CoreAPI{api.node, ng}
94
-}
\ No newline at end of file
94
+}
core/corehttp/gateway_handler.go
+6
-8
@@ -179,18 +179,16 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
179
}
180
181
dr, err := i.api.Unixfs().Get(ctx, resolvedPath)
182
- dir := false
183
- switch {
184
- case err == nil:
185
- dir = dr.IsDirectory()
186
- if !dir {
187
- defer dr.Close()
188
- }
189
- default:
182
+ if err != nil {
183
webError(w, "ipfs cat "+escapedURLPath, err, http.StatusNotFound)
184
return
185
}
186
187
+ dir := dr.IsDirectory()
188
+ if !dir {
189
+ defer dr.Close()
190
+ }
191
+
192
// Check etag send back to us
193
etag := "\"" + resolvedPath.Cid().String() + "\""
194
if r.Header.Get("If-None-Match") == etag || r.Header.Get("If-None-Match") == "W/"+etag {