I have a simple HTTP server standing in the Golang:
h := http.NewServeMux()
h.Handle("/somepath", MyHandler)
s := &http.Server{
Addr: "1234",
Handler: h,
}
s.ListenAndServe();
What is the best way to drop connections when the caller is not localhost? I am currently considering checking for basic connection information and ensuring that the IP address is there 127.0.0.1, but it takes a lot of resources (and goes through a whole chain of Go code) before eventually disconnecting the connection. Ideally, I can get the Golang server to remove the original TCP SYN packet based on the IP address, and not create a TCP connection at all (or show that this port is listening).
What is the cleanest way here?