Skip to content

Commit e72e2a1

Browse files
author
manute
committed
chore: add more logs and address fedback
1 parent 43638d5 commit e72e2a1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

core/corehttp/gateway_handler.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
213213
break
214214
}
215215
}
216+
logger.Debugw("sub-path", "prefix", prefix)
216217
}
217218

218219
// HostnameOption might have constructed an IPNS/IPFS path using the Host header.
@@ -247,8 +248,8 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
247248
}
248249

249250
redirectURL := gopath.Join("/", prefix, u.Scheme, u.Host, path)
250-
http.Redirect(w, r, redirectURL, http.StatusMovedPermanently)
251251
logger.Debugw("received an uri param, redirect", "to", redirectURL, "status", http.StatusMovedPermanently)
252+
http.Redirect(w, r, redirectURL, http.StatusMovedPermanently)
252253
return
253254
}
254255

@@ -269,7 +270,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
269270
if prefix == "" && fixupSuperfluousNamespace(w, urlPath, r.URL.RawQuery) {
270271
// the error was due to redundant namespace, which we were able to fix
271272
// by returning error/redirect page, nothing left to do here
272-
logger.Debugw("redundant namespace, fixed by returning error/redirect page")
273+
logger.Debugw("redundant namespace, returning error/redirect page")
273274
return
274275
}
275276
// unable to fix path, returning error
@@ -286,6 +287,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
286287
return
287288
default:
288289
if i.servePretty404IfPresent(w, r, parsedPath) {
290+
logger.Debugw("serve pretty 404 if present")
289291
return
290292
}
291293

@@ -352,6 +354,8 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
352354
} else {
353355
name = getFilename(urlPath)
354356
}
357+
358+
logger.Debugw("serve file", "name", name)
355359
i.serveFile(w, r, name, modtime, f)
356360
return
357361
}
@@ -376,8 +380,8 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
376380
}
377381

378382
redirectURL := originalUrlPath + suffix
383+
logger.Debugw("serving index.html file", "to", redirectURL, "status", http.StatusFound, "path", idxPath)
379384
http.Redirect(w, r, redirectURL, http.StatusFound)
380-
logger.Debugw("error (type nil) getting file tree for index.html and dir w/o slash, redirect", "to", redirectURL, "status", http.StatusFound, "path", idxPath)
381385
return
382386
}
383387

@@ -387,12 +391,12 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
387391
return
388392
}
389393

390-
logger.Debugw("error (type nil) getting file tree for index.html, serve the file", "path", idxPath)
394+
logger.Debugw("serving index.html file", "path", idxPath)
391395
// write to request
392396
i.serveFile(w, r, "index.html", modtime, f)
393397
return
394398
case resolver.ErrNoLink:
395-
logger.Debugw("error getting file tree, no index.html; noop", "path", idxPath)
399+
logger.Debugw("no index.html; noop", "path", idxPath)
396400
default:
397401
internalWebError(w, err)
398402
return
@@ -403,8 +407,8 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
403407
// Note: this needs to occur before listingTemplate.Execute otherwise we get
404408
// superfluous response.WriteHeader call from prometheus/client_golang
405409
if w.Header().Get("Location") != "" {
406-
w.WriteHeader(http.StatusMovedPermanently)
407410
logger.Debugw("location moved permanently", "status", http.StatusMovedPermanently)
411+
w.WriteHeader(http.StatusMovedPermanently)
408412
return
409413
}
410414

@@ -600,8 +604,8 @@ func (i *gatewayHandler) postHandler(w http.ResponseWriter, r *http.Request) {
600604

601605
i.addUserHeaders(w) // ok, _now_ write user's headers.
602606
w.Header().Set("IPFS-Hash", p.Cid().String())
603-
http.Redirect(w, r, p.String(), http.StatusCreated)
604607
log.Debugw("CID created, http redirect", "from", r.URL, "to", p, "status", http.StatusCreated)
608+
http.Redirect(w, r, p.String(), http.StatusCreated)
605609
}
606610

607611
func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
@@ -695,8 +699,8 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
695699
w.Header().Set("IPFS-Hash", newcid.String())
696700

697701
redirectURL := gopath.Join(ipfsPathPrefix, newcid.String(), newPath)
698-
http.Redirect(w, r, redirectURL, http.StatusCreated)
699702
log.Debugw("CID replaced, http redirect", "from", r.URL, "to", redirectURL, "status", http.StatusCreated)
703+
http.Redirect(w, r, redirectURL, http.StatusCreated)
700704
}
701705

702706
func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
@@ -770,8 +774,8 @@ func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
770774

771775
redirectURL := gopath.Join(ipfsPathPrefix+ncid.String(), directory)
772776
// note: StatusCreated is technically correct here as we created a new resource.
773-
http.Redirect(w, r, redirectURL, http.StatusCreated)
774777
log.Debugw("CID deleted, http redirect", "from", r.URL, "to", redirectURL, "status", http.StatusCreated)
778+
http.Redirect(w, r, redirectURL, http.StatusCreated)
775779
}
776780

777781
func (i *gatewayHandler) addUserHeaders(w http.ResponseWriter) {

0 commit comments

Comments
 (0)