summaryrefslogtreecommitdiff
path: root/internal/middleware/useragent.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-12-18 14:18:25 +0000
committerLibravatar GitHub <noreply@github.com>2023-12-18 14:18:25 +0000
commit8ebb7775a35b632d49a8f294d83ac786666631f3 (patch)
tree02ac5475274125170132b0a4d9f69bd67491a32c /internal/middleware/useragent.go
parentfix poll total vote double count (#2464) (diff)
downloadgotosocial-8ebb7775a35b632d49a8f294d83ac786666631f3.tar.xz
[feature] request blocking by http headers (#2409)
Diffstat (limited to 'internal/middleware/useragent.go')
-rw-r--r--internal/middleware/useragent.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/internal/middleware/useragent.go b/internal/middleware/useragent.go
index 6dc3e401f..38d28f4e5 100644
--- a/internal/middleware/useragent.go
+++ b/internal/middleware/useragent.go
@@ -18,21 +18,22 @@
package middleware
import (
- "errors"
"net/http"
"github.com/gin-gonic/gin"
+ apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
)
// UserAgent returns a gin middleware which aborts requests with
// empty user agent strings, returning code 418 - I'm a teapot.
func UserAgent() gin.HandlerFunc {
// todo: make this configurable
+ var rsp = []byte(`{"error": "I'm a teapot: no user-agent sent with request"}`)
return func(c *gin.Context) {
if ua := c.Request.UserAgent(); ua == "" {
- code := http.StatusTeapot
- err := errors.New(http.StatusText(code) + ": no user-agent sent with request")
- c.AbortWithStatusJSON(code, gin.H{"error": err.Error()})
+ apiutil.Data(c,
+ http.StatusTeapot, apiutil.AppJSON, rsp)
+ c.Abort()
}
}
}