hooker/auth.go

29 lines
540 B
Go
Raw Permalink Normal View History

2023-09-19 22:47:19 +02:00
package main
import (
"log"
"net/http"
)
2023-10-02 20:57:07 +02:00
// Java like
const TAG = "[ Auth ]"
2023-09-19 22:47:19 +02:00
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-10-02 20:57:07 +02:00
log.Printf("%s Dropping request from %s", TAG, 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}
}