Skip to content

Commit d21ec92

Browse files
author
manute
committed
chore(gateway): log subdomains and from=requestURI, refactor
1 parent e72e2a1 commit d21ec92

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

core/corehttp/gateway_handler.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (sw *statusResponseWriter) WriteHeader(code int) {
8383
if redirect != "" && code == http.StatusOK {
8484
code = http.StatusMovedPermanently
8585
}
86+
log.Debugw("subdomain redirect", "location", redirect, "status", code)
8687
sw.ResponseWriter.WriteHeader(code)
8788
}
8889

@@ -198,7 +199,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
198199
urlPath := r.URL.Path
199200
escapedURLPath := r.URL.EscapedPath()
200201

201-
logger := log.With("from", r.URL)
202+
logger := log.With("from", r.RequestURI)
202203
logger.Debug("http request received")
203204

204205
// If the gateway is behind a reverse proxy and mounted at a sub-path,
@@ -213,7 +214,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
213214
break
214215
}
215216
}
216-
logger.Debugw("sub-path", "prefix", prefix)
217+
logger.Debugw("sub-path (deprecrated)", "prefix", prefix)
217218
}
218219

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

250251
redirectURL := gopath.Join("/", prefix, u.Scheme, u.Host, path)
251-
logger.Debugw("received an uri param, redirect", "to", redirectURL, "status", http.StatusMovedPermanently)
252+
logger.Debugw("uri param, redirect", "to", redirectURL, "status", http.StatusMovedPermanently)
252253
http.Redirect(w, r, redirectURL, http.StatusMovedPermanently)
253254
return
254255
}
@@ -270,7 +271,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
270271
if prefix == "" && fixupSuperfluousNamespace(w, urlPath, r.URL.RawQuery) {
271272
// the error was due to redundant namespace, which we were able to fix
272273
// by returning error/redirect page, nothing left to do here
273-
logger.Debugw("redundant namespace, returning error/redirect page")
274+
logger.Debugw("redundant namespace; noop")
274275
return
275276
}
276277
// unable to fix path, returning error
@@ -355,7 +356,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
355356
name = getFilename(urlPath)
356357
}
357358

358-
logger.Debugw("serve file", "name", name)
359+
logger.Debugw("serving file", "name", name)
359360
i.serveFile(w, r, name, modtime, f)
360361
return
361362
}
@@ -508,7 +509,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
508509
Hash: hash,
509510
}
510511

511-
logger.Debugw("http request processed", "tplDataDNSLink", dnslink, "tplDataSize", size, "tplDataBackLink", backLink, "tplDataHash", hash, "duration", time.Since(begin))
512+
logger.Debugw("request processed", "tplDataDNSLink", dnslink, "tplDataSize", size, "tplDataBackLink", backLink, "tplDataHash", hash, "duration", time.Since(begin))
512513

513514
if err := listingTemplate.Execute(w, tplData); err != nil {
514515
internalWebError(w, err)
@@ -699,7 +700,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
699700
w.Header().Set("IPFS-Hash", newcid.String())
700701

701702
redirectURL := gopath.Join(ipfsPathPrefix, newcid.String(), newPath)
702-
log.Debugw("CID replaced, http redirect", "from", r.URL, "to", redirectURL, "status", http.StatusCreated)
703+
log.Debugw("CID replaced, redirect", "from", r.URL, "to", redirectURL, "status", http.StatusCreated)
703704
http.Redirect(w, r, redirectURL, http.StatusCreated)
704705
}
705706

@@ -774,7 +775,7 @@ func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
774775

775776
redirectURL := gopath.Join(ipfsPathPrefix+ncid.String(), directory)
776777
// note: StatusCreated is technically correct here as we created a new resource.
777-
log.Debugw("CID deleted, http redirect", "from", r.URL, "to", redirectURL, "status", http.StatusCreated)
778+
log.Debugw("CID deleted, redirect", "from", r.RequestURI, "to", redirectURL, "status", http.StatusCreated)
778779
http.Redirect(w, r, redirectURL, http.StatusCreated)
779780
}
780781

0 commit comments

Comments
 (0)