check incoming if-none-match header

This commit is contained in:
tobi 2025-02-24 10:37:45 +01:00
commit 982c7eda4f

View file

@ -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)
}