I am experimenting with the Go's httpuitls.ReverseProxy and http.HandleFunc. I am trying to create a way to Black Hole certain routes in my simple proxy as shown below. How do I get the http library to completely throw out my request without responding or sending a disconnect?
This example hopefully clarifies what I mean. See the /toss route below.
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
origin, _ := url.Parse("https://www.example.com:443/")
director := func(req *http.Request) {
req.URL.Scheme = "https"
req.URL.Host = origin.Host
req.Host = origin.Host
}
proxy := &httputil.ReverseProxy{Director: director}
http.HandleFunc("/toss", func(w http.ResponseWriter, r *http.Request) {
// What goes here to Black Hole this request??
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
proxy.ServeHTTP(w, r)
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
Adding a little context to the question, the ultimate goal here is to use this proxy with a destructive testing tool. The idea being that the clients are never given a response to certain routes and it allows the user of the tool to see how their applications will handle this.