MCPcopy Create free account
hub / github.com/askfalse/roproxy-lite / requestHandler

Function requestHandler

main.go:31–56  ·  view source on GitHub ↗
(ctx *fasthttp.RequestCtx)

Source from the content-addressed store, hash-verified

29}
30
31func requestHandler(ctx *fasthttp.RequestCtx) {
32 val, ok := os.LookupEnv("KEY")
33
34 if ok && string(ctx.Request.Header.Peek("PROXYKEY")) != val {
35 ctx.SetStatusCode(407)
36 ctx.SetBody([]byte("Missing or invalid PROXYKEY header."))
37 return
38 }
39
40 if len(strings.SplitN(string(ctx.Request.Header.RequestURI())[1:], "/", 2)) < 2 {
41 ctx.SetStatusCode(400)
42 ctx.SetBody([]byte("URL format invalid."))
43 return
44 }
45
46 response := makeRequest(ctx, 1)
47
48 defer fasthttp.ReleaseResponse(response)
49
50 body := response.Body()
51 ctx.SetBody(body)
52 ctx.SetStatusCode(response.StatusCode())
53 response.Header.VisitAll(func (key, value []byte) {
54 ctx.Response.Header.Set(string(key), string(value))
55 })
56}
57
58func makeRequest(ctx *fasthttp.RequestCtx, attempt int) *fasthttp.Response {
59 if attempt > retries {

Callers

nothing calls this directly

Calls 1

makeRequestFunction · 0.85

Tested by

no test coverage detected