hooker/auth.go

26 lines
496 B
Go
Raw Normal View History

2023-09-19 22:47:19 +02:00
package main
import (
"log"
"net/http"
)
type AuthHandler struct {
Handler http.Handler
}
func (l *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
AuthHeader := r.Header.Get("Authorization")
2023-09-19 23:31:13 +02:00
RealIP := r.Header.Get("X-Real-IP")
2023-09-19 22:47:19 +02:00
if AuthHeader != task.Auth {
2023-09-19 23:31:13 +02:00
log.Printf("Dropping request from %s.", RealIP)
2023-09-19 22:47:19 +02:00
return // drop
}
l.Handler.ServeHTTP(w, r)
}
func NewAuth(handler http.Handler) AuthHandler {
return AuthHandler{handler}
}