From 34f44cb5d5d6316009f242d27d2f3d69f4d5b90e Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 2 Sep 2021 17:02:20 -0600 Subject: implementation of basic chat page which can show history and not much else --- srv/api/middleware.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'srv/api/middleware.go') diff --git a/srv/api/middleware.go b/srv/api/middleware.go index 2605d93..6ea0d13 100644 --- a/srv/api/middleware.go +++ b/srv/api/middleware.go @@ -40,12 +40,15 @@ func annotateMiddleware(h http.Handler) http.Handler { type logResponseWriter struct { http.ResponseWriter + http.Hijacker statusCode int } func newLogResponseWriter(rw http.ResponseWriter) *logResponseWriter { + h, _ := rw.(http.Hijacker) return &logResponseWriter{ ResponseWriter: rw, + Hijacker: h, statusCode: 200, } } @@ -78,9 +81,11 @@ func logMiddleware(logger *mlog.Logger, h http.Handler) http.Handler { }) } -func allowedMethod(method string, h http.Handler) http.Handler { +func postOnlyMiddleware(h http.Handler) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - if r.Method == method { + + // we allow websockets to not be POSTs because, well, they can't be + if r.Method == "POST" || r.Header.Get("Upgrade") == "websocket" { h.ServeHTTP(rw, r) return } -- cgit v1.2.3