diff options
author | 2025-02-24 11:17:18 +0100 | |
---|---|---|
committer | 2025-02-24 11:17:18 +0100 | |
commit | fd670c6a279e2aa54822546536dbf88b45a93051 (patch) | |
tree | 108c9b8ff3f01bc845a33f628ff302accde00211 /internal/api/robots/robots.go | |
parent | [docs] Update `interactionPolicy` (#3703) (diff) | |
download | gotosocial-fd670c6a279e2aa54822546536dbf88b45a93051.tar.xz |
[feature] Use ETag for robots.txt to prevent mishaps (#3829)v0.18.1
* [feature] Use ETag for robots.txt to prevent mishaps
* check incoming if-none-match header
Diffstat (limited to 'internal/api/robots/robots.go')
-rw-r--r-- | internal/api/robots/robots.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/api/robots/robots.go b/internal/api/robots/robots.go index 98db4682d..b72a01ed6 100644 --- a/internal/api/robots/robots.go +++ b/internal/api/robots/robots.go @@ -49,9 +49,29 @@ 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) } |