MCPcopy Index your code
hub / github.com/koding/kite / New

Function New

reverseproxy/reverseproxy.go:49–93  ·  view source on GitHub ↗
(conf *config.Config)

Source from the content-addressed store, hash-verified

47}
48
49func New(conf *config.Config) *Proxy {
50 k := kite.New(Name, Version)
51 k.Config = conf
52
53 p := &Proxy{
54 Kite: k,
55 kites: make(map[string]url.URL),
56 readyC: make(chan bool),
57 closeC: make(chan bool),
58 mux: http.NewServeMux(),
59 }
60
61 // third part kites are going to use this to register themself to
62 // proxy-kite and get a proxy url, which they use for register to kontrol.
63 p.Kite.HandleFunc("register", p.handleRegister)
64
65 // create our websocketproxy http.handler
66
67 p.websocketProxy = &websocketproxy.WebsocketProxy{
68 Backend: p.backend,
69 Upgrader: &websocket.Upgrader{
70 ReadBufferSize: 4096,
71 WriteBufferSize: 4096,
72 CheckOrigin: func(r *http.Request) bool {
73 // TODO: change this to publicdomain and also kites should add them to
74 return true
75 },
76 },
77 }
78
79 p.httpProxy = &httputil.ReverseProxy{
80 Director: p.director,
81 }
82
83 p.mux.Handle("/", k)
84 p.mux.Handle("/proxy/", p)
85
86 // OnDisconnect is called whenever a kite is disconnected from us.
87 k.OnDisconnect(func(r *kite.Client) {
88 k.Log.Info("Removing kite Id '%s' from proxy. It's disconnected", r.Kite.ID)
89 delete(p.kites, r.Kite.ID)
90 })
91
92 return p
93}
94
95// ServeHTTP implements the http.Handler interface.
96func (p *Proxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

Callers 1

TestWebSocketProxyFunction · 0.70

Calls 4

HandleFuncMethod · 0.80
InfoMethod · 0.80
HandleMethod · 0.45
OnDisconnectMethod · 0.45

Tested by 1

TestWebSocketProxyFunction · 0.56