Created
August 19, 2014 15:13
-
-
Save giter/4d517931fbc9d172fe03 to your computer and use it in GitHub Desktop.
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 ( | |
"bufio" | |
"net/http" | |
"log" | |
) | |
func handler(w http.ResponseWriter, r *http.Request) { | |
resp, err := http.DefaultTransport.RoundTrip(r) | |
if err != nil { | |
log.Print(err) | |
return | |
} | |
for k, vv := range resp.Header { | |
for _,v := range vv{ | |
w.Header().Add(k,v) | |
} | |
} | |
w.Header().Add("Proxy","HIT") | |
if resp.StatusCode >= 300 { | |
w.WriteHeader(resp.StatusCode); | |
return | |
} | |
defer resp.Body.Close() | |
bufio.NewReader(resp.Body).WriteTo(w) | |
} | |
func main() { | |
http.HandleFunc("/", handler) | |
log.Println("Start serving on port 8888") | |
http.ListenAndServe(":8888", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment