Created
January 5, 2014 14:58
-
-
Save pstadler/8269171 to your computer and use it in GitHub Desktop.
Simple BOSH proxy written in Go
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
// Simple BOSH proxy written in Go | |
// | |
// See: https://github.com/pstadler/candy-go | |
package main | |
import ( | |
"fmt" | |
"io" | |
"net/http" | |
"net/url" | |
) | |
const target_url = "http://localhost:5280/http-bind/" | |
func main() { | |
url, _ := url.Parse(target_url) | |
http.HandleFunc("/http-bind/", func(w http.ResponseWriter, r *http.Request) { | |
r.RequestURI = "" | |
r.URL = url | |
r.Host = url.Host | |
client := &http.Client{} | |
response, err := client.Do(r) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
w.Header().Set("Content-Type", response.Header.Get("Content-Type")) | |
w.Header().Set("Content-Encoding", response.Header.Get("Content-Encoding")) | |
io.Copy(w, response.Body) | |
}) | |
http.ListenAndServe(":1080", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment