MCPcopy Index your code
hub / github.com/SenseUnit/dumbproxy / ServeHTTP

Method ServeHTTP

handler/handler.go:228–276  ·  view source on GitHub ↗
(wr http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

226}
227
228func (s *ProxyHandler) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
229 if originator, isLoopback := s.isLoopback(req); isLoopback {
230 s.logger.Critical("Loopback tunnel detected: %s is an outbound "+
231 "address for another request from %s", req.RemoteAddr, originator)
232 http.Error(wr, auth.BAD_REQ_MSG, http.StatusBadRequest)
233 return
234 }
235
236 if s.directResponse != nil && isDirectRequest(req) {
237 s.reject(s.directResponse, wr, req)
238 return
239 }
240
241 ctx := req.Context()
242 username, ok := s.auth.Validate(ctx, wr, req)
243 localAddr := getLocalAddr(req.Context())
244 s.logger.Info("Request: %v => %v %q %v %v %v", req.RemoteAddr, localAddr, username, req.Proto, req.Method, req.URL)
245
246 if !ok {
247 return
248 }
249
250 if (req.URL.Host == "" || req.URL.Scheme == "" && req.Method != "CONNECT") && req.ProtoMajor < 2 ||
251 req.Host == "" && req.ProtoMajor == 2 {
252 http.Error(wr, auth.BAD_REQ_MSG, http.StatusBadRequest)
253 return
254 }
255
256 var ipHints *string
257 if s.userIPHints {
258 hintValues := req.Header.Values(HintsHeaderName)
259 if len(hintValues) > 0 {
260 req.Header.Del(HintsHeaderName)
261 ipHints = &hintValues[0]
262 }
263 }
264 ctx = ddto.BoundDialerParamsToContext(ctx, ipHints, trimAddrPort(localAddr))
265 ctx = ddto.FilterParamsToContext(ctx, req, username)
266 req = req.WithContext(ctx)
267 delHopHeaders(req.Header)
268 switch req.Method {
269 case "CONNECT":
270 s.HandleTunnel(wr, req, username)
271 case "GETRANDOM":
272 s.HandleGetRandom(wr, req, username)
273 default:
274 s.HandleRequest(wr, req, username)
275 }
276}
277
278func (s *ProxyHandler) rejectAccess(wr http.ResponseWriter, req *http.Request) {
279 if s.accessReject == nil {

Callers 3

TestDirectResponseFunction · 0.95
TestAccessRejectFunction · 0.95
ValidateMethod · 0.80

Calls 13

isLoopbackMethod · 0.95
rejectMethod · 0.95
HandleTunnelMethod · 0.95
HandleGetRandomMethod · 0.95
HandleRequestMethod · 0.95
isDirectRequestFunction · 0.85
getLocalAddrFunction · 0.85
trimAddrPortFunction · 0.85
delHopHeadersFunction · 0.85
CriticalMethod · 0.80
ValidateMethod · 0.65
ErrorMethod · 0.45

Tested by 2

TestDirectResponseFunction · 0.76
TestAccessRejectFunction · 0.76