Commit 532a539
Eric Bower
·
2026-04-20 20:20:50 -0400 EDT
parent 1c474b9
feat(pgs): record metrics for compressed file types
3 files changed,
+19,
-2
+14,
-2
| ... | ... | @@ -13,6 +13,7 @@ import ( | |
| 13 | 13 | "log/slog" | |
| 14 | 14 | "net/http" | |
| 15 | 15 | "net/url" | |
| 16 | + | "slices" | |
| 16 | 17 | "strings" | |
| 17 | 18 | "time" | |
| 18 | 19 |
| ... | ... | @@ -749,6 +750,18 @@ func accessLogToVisit(dbpool db.DB, line string) (*db.AnalyticsVisits, error) { | |
| 749 | 750 | return deserializeCaddyAccessLog(dbpool, &accessLog) | |
| 750 | 751 | } | |
| 751 | 752 | ||
| 753 | + | var allowedMime = []string{ | |
| 754 | + | "application/gzip", | |
| 755 | + | "application/vnd.rar", | |
| 756 | + | "application/x-7z-compressed", | |
| 757 | + | "application/x-bzip", | |
| 758 | + | "application/x-bzip2", | |
| 759 | + | "application/x-freearc", | |
| 760 | + | "application/x-tar", | |
| 761 | + | "application/zip", | |
| 762 | + | "text/html", | |
| 763 | + | } | |
| 764 | + | ||
| 752 | 765 | func metricDrainSub(ctx context.Context, dbpool db.DB, logger *slog.Logger, secret string) { | |
| 753 | 766 | drain := metrics.ReconnectReadMetrics( | |
| 754 | 767 | ctx, |
| ... | ... | @@ -778,8 +791,7 @@ func metricDrainSub(ctx context.Context, dbpool db.DB, logger *slog.Logger, secr | |
| 778 | 791 | continue | |
| 779 | 792 | } | |
| 780 | 793 | ||
| 781 | - | if !strings.HasPrefix(visit.ContentType, "text/html") { | |
| 782 | - | logger.Info("invalid content type", "contentType", visit.ContentType) | |
| 794 | + | if !slices.Contains(allowedMime, visit.ContentType) { | |
| 783 | 795 | continue | |
| 784 | 796 | } | |
| 785 | 797 |
| ... | ... | @@ -84,6 +84,8 @@ func GetMimeType(fpath string) string { | |
| 84 | 84 | return "application/vnd.rar" | |
| 85 | 85 | case ".gz": | |
| 86 | 86 | return "application/gzip" | |
| 87 | + | case ".bz": | |
| 88 | + | return "application/x-bzip" | |
| 87 | 89 | case ".bz2": | |
| 88 | 90 | return "application/x-bzip2" | |
| 89 | 91 | case ".xz": |