mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-30 17:32:24 -05: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:
parent
c9de6c9a1e
commit
fd670c6a27
3 changed files with 26 additions and 1 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue