- commit
- 68d2fb1
- parent
- 1b8771c
- author
- Eric Bower
- date
- 2024-03-02 20:00:13 +0000 UTC
chore(pgs): log requests
2 files changed,
+16,
-6
+14,
-4
1@@ -150,7 +150,7 @@ func createRssHandler(by string) http.HandlerFunc {
2 }
3 }
4
5-func (h *AssetHandler) handle(w http.ResponseWriter) {
6+func (h *AssetHandler) handle(w http.ResponseWriter, r *http.Request) {
7 var redirects []*RedirectRule
8 redirectFp, _, _, err := h.Storage.GetObject(h.Bucket, filepath.Join(h.ProjectDir, "_redirects"))
9 if err == nil {
10@@ -174,7 +174,7 @@ func (h *AssetHandler) handle(w http.ResponseWriter) {
11 var contents io.ReadCloser
12 contentType := ""
13 assetFilepath := ""
14- status := 200
15+ status := http.StatusOK
16 attempts := []string{}
17 for _, fp := range routes {
18 attempts = append(attempts, fp.Filepath)
19@@ -244,9 +244,19 @@ func (h *AssetHandler) handle(w http.ResponseWriter) {
20 w.Header().Add(hdr.Name, hdr.Value)
21 }
22 if w.Header().Get("content-type") == "" {
23- w.Header().Set("Content-Type", contentType)
24+ w.Header().Set("content-type", contentType)
25 }
26
27+ h.Logger.Info(
28+ "serving asset",
29+ "host", r.Host,
30+ "url", r.URL,
31+ "bucket", h.Bucket.Name,
32+ "asset", assetFilepath,
33+ "status", status,
34+ "contentType", w.Header().Get("content-type"),
35+ )
36+
37 w.WriteHeader(status)
38 _, err = io.Copy(w, contents)
39
40@@ -341,7 +351,7 @@ func ServeAsset(fname string, opts *storage.ImgProcessOpts, fromImgs bool, hasPe
41 ImgProcessOpts: opts,
42 }
43
44- asset.handle(w)
45+ asset.handle(w, r)
46 }
47
48 type HasPerm = func(proj *db.Project) bool
+2,
-2
1@@ -64,7 +64,7 @@ func expandRoute(projectName, fp string, status int) []*HttpReply {
2 func calcRoutes(projectName, fp string, userRedirects []*RedirectRule) []*HttpReply {
3 notFound := &HttpReply{
4 Filepath: filepath.Join(projectName, "404.html"),
5- Status: 404,
6+ Status: http.StatusNotFound,
7 }
8
9 rts := expandRoute(projectName, fp, http.StatusOK)
10@@ -78,7 +78,7 @@ func calcRoutes(projectName, fp string, userRedirects []*RedirectRule) []*HttpRe
11
12 rts = append(rts,
13 &HttpReply{
14- Filepath: defRoute, Status: 200,
15+ Filepath: defRoute, Status: http.StatusOK,
16 },
17 )
18 }