26 lines
496 B
Go
26 lines
496 B
Go
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")
|
|
RealIP := r.Header.Get("X-Real-IP")
|
|
if AuthHeader != task.Auth {
|
|
log.Printf("Dropping request from %s.", RealIP)
|
|
return // drop
|
|
}
|
|
l.Handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
func NewAuth(handler http.Handler) AuthHandler {
|
|
return AuthHandler{handler}
|
|
}
|