code refactoring, added file download (#118)

This commit is contained in:
Marco
2023-12-27 15:08:51 +01:00
committed by GitHub
parent c5535fad71
commit 3859c80214
5 changed files with 82 additions and 39 deletions

View File

@@ -42,19 +42,9 @@ func validateToken(tokenValue string) error {
func Authenticated(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("X-Authentication")
if err := validateToken(token); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
next.ServeHTTP(w, r)
})
}
func WebSocketAuthentication(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token := r.URL.Query().Get("token")
if token == "" {
token = r.URL.Query().Get("token")
}
if err := validateToken(token); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)