(ctx *fasthttp.RequestCtx)
| 29 | } |
| 30 | |
| 31 | func 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 | |
| 58 | func makeRequest(ctx *fasthttp.RequestCtx, attempt int) *fasthttp.Response { |
| 59 | if attempt > retries { |
nothing calls this directly
no test coverage detected