From 982c7eda4fc775b66cab403df7dab8bd3ff29575 Mon Sep 17 00:00:00 2001 From: tobi Date: Mon, 24 Feb 2025 10:37:45 +0100 Subject: [PATCH] check incoming if-none-match header --- internal/api/robots/robots.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/api/robots/robots.go b/internal/api/robots/robots.go index d7af8b22b..b72a01ed6 100644 --- a/internal/api/robots/robots.go +++ b/internal/api/robots/robots.go @@ -51,11 +51,27 @@ func (m *Module) Route(attachHandler func(method string, path string, f ...gin.H func (m *Module) robotsGETHandler(c *gin.Context) { const ETag = "\"" + apiutil.RobotsTxtETag + "\"" c.Header("ETag", ETag) + + if c.Request.Header.Get("If-None-Match") == ETag { + // Cached. + c.AbortWithStatus(http.StatusNotModified) + return + } + + // Not cached, serve. c.String(http.StatusOK, apiutil.RobotsTxt) } func (m *Module) robotsGETHandlerDisallowNodeInfo(c *gin.Context) { const ETag = "\"" + apiutil.RobotsTxtDisallowNodeInfoETag + "\"" c.Header("ETag", ETag) + + if c.Request.Header.Get("If-None-Match") == ETag { + // Cached. + c.AbortWithStatus(http.StatusNotModified) + return + } + + // Not cached, serve. c.String(http.StatusOK, apiutil.RobotsTxtDisallowNodeInfo) }