MCPcopy Create free account
hub / github.com/koding/kite / backend

Method backend

reverseproxy/reverseproxy.go:145–179  ·  view source on GitHub ↗
(req *http.Request)

Source from the content-addressed store, hash-verified

143}
144
145func (p *Proxy) backend(req *http.Request) *url.URL {
146 withoutProxy := strings.TrimPrefix(req.URL.Path, "/proxy")
147 paths := strings.Split(withoutProxy, "/")
148
149 if len(paths) == 0 {
150 p.Kite.Log.Error("Invalid path '%s'", req.URL.String())
151 return nil
152 }
153
154 // remove the first empty path
155 paths = paths[1:]
156
157 // get our kiteId and individuals paths
158 kiteId, rest := paths[0], path.Join(paths[1:]...)
159
160 p.Kite.Log.Info("[%s] Incoming proxy request for scheme: '%s', endpoint '/%s'",
161 kiteId, req.URL.Scheme, rest)
162
163 p.kitesMu.Lock()
164 defer p.kitesMu.Unlock()
165
166 backendURL, ok := p.kites[kiteId]
167 if !ok {
168 p.Kite.Log.Error("kite for id '%s' is not found: %s", kiteId, req.URL.String())
169 return nil
170 }
171
172 // backendURL.Path contains the baseURL, like "/kite" and rest contains
173 // SockJS related endpoints, like /info or /123/kjasd213/websocket
174 backendURL.Scheme = req.URL.Scheme
175 backendURL.Path += "/" + rest
176
177 p.Kite.Log.Info("[%s] Proxying to backend url: '%s'.", kiteId, backendURL.String())
178 return &backendURL
179}
180
181func (p *Proxy) director(req *http.Request) {
182 u := p.backend(req)

Callers 1

directorMethod · 0.95

Calls 3

InfoMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected