Is there an way to reject/block an request in go net/http "listenandserver"?
In my case I want that only requests with useragent "test 1.0" are allowed. Everything else will be blocked.
"I also want to make an rate limit. ex: (If requests per second from same IP gets over 50 R/S over second block for 1h...)" I can do this but as I said I dont know how to block the request.
package main
import (
"net/http"
)
func handle(w http.ResponseWriter, r *http.Request) {
if r.UserAgent() == "test/1.0" {
//Allow
} else {
//Block request
}
}
func main() {
http.HandleFunc("/", handle)
http.ListenAndServe(":8080", nil)
}