mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Use ETag for robots.txt to prevent mishaps (#3829)
* [feature] Use ETag for robots.txt to prevent mishaps * check incoming if-none-match header
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user