Created
April 24, 2015 11:38
-
-
Save jordanorelli/068da9553abe10d4308e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
"fmt" | |
"io" | |
"net/http" | |
"net/http/httputil" | |
"os" | |
"strings" | |
"unicode" | |
) | |
var client = new(http.Client) | |
func httpHandler(w http.ResponseWriter, r *http.Request) { | |
b, err := httputil.DumpRequest(r, true) | |
if err != nil { | |
fmt.Printf("error dumping request: %s\n", err) | |
return | |
} | |
os.Stdout.Write(b) | |
r.RequestURI = "" | |
r.URL.Scheme = strings.Map(unicode.ToLower, r.URL.Scheme) | |
res, err := client.Do(r) | |
if err != nil { | |
fmt.Printf("error forwarding request: %s\n", err) | |
return | |
} | |
defer res.Body.Close() | |
for k, v := range res.Header { | |
w.Header()[k] = v | |
} | |
if _, ok := w.Header()["Proxy-Connection"]; ok { | |
delete(w.Header(), "Proxy-Connection") | |
} | |
w.WriteHeader(res.StatusCode) | |
if _, err := io.Copy(w, res.Body); err != nil { | |
fmt.Printf("error copying body: %s\n", err) | |
} | |
} | |
func main() { | |
http.HandleFunc("/", httpHandler) | |
http.ListenAndServe(":8080", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment