Skip to content

Instantly share code, notes, and snippets.

@pstadler
Created January 5, 2014 14:58
Show Gist options
  • Save pstadler/8269171 to your computer and use it in GitHub Desktop.
Save pstadler/8269171 to your computer and use it in GitHub Desktop.
Simple BOSH proxy written in Go
// 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