-
-
Save dustin/c510c603dabfdc13ce53 to your computer and use it in GitHub Desktop.
Deauthing proxy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"log" | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
) | |
var target = flag.String("target", "http://www.google.com/", "Where to go.") | |
var addr = flag.String("listen", ":12345", "Address/port on which to listen.") | |
var auth = flag.String("auth", "", "Authorization header to add (optional).") | |
func main() { | |
flag.Parse() | |
targetUrl, uerr := url.Parse(*target) | |
if uerr != nil { | |
log.Fatalf("Error parsing target ``%v'': %v", target, uerr) | |
} | |
proxy := httputil.ReverseProxy{Director: func(req *http.Request) { | |
req.URL.Scheme = targetUrl.Scheme | |
req.URL.Host = targetUrl.Host | |
req.Host = targetUrl.Host | |
if *auth != "" { | |
req.Header.Set("Authorization", *auth) | |
} | |
}} | |
err := http.ListenAndServe(*addr, &proxy) | |
if err != nil { | |
log.Fatalf("ListenAndServe: %v", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment