Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for x-response-json header before attempting to use it #14

Closed
notnmeyer opened this issue Oct 23, 2023 · 1 comment
Closed

check for x-response-json header before attempting to use it #14

notnmeyer opened this issue Oct 23, 2023 · 1 comment

Comments

@notnmeyer
Copy link
Owner

notnmeyer commented Oct 23, 2023

here we read the header directly without verifying if it exists yet first. this causes the request to blow up and 502 if its behind an LB,

➜ curl -i https://mockpi.fly.dev
HTTP/2 502
server: Fly/55f8eaa0 (2023-10-09)
via: 2 fly.io
fly-request-id: 01HDF07QYT6S44KJKSAJ6DPEE2-sea
date: Mon, 23 Oct 2023 19:29:53 GMT

and the error itself,

➜ go run main.go
Listening on :8080...
2023/10/23 13:57:27 http: panic serving 127.0.0.1:56990: runtime error: index out of range [0] with length 0
goroutine 4 [running]:
net/http.(*conn).serve.func1()
        /nix/store/s1xk6hrfn0kw8ycvqbx4vv4gr00k6qpl-go-1.21.1/share/go/src/net/http/server.go:1868 +0xb0
panic({0x1025eb040?, 0x1400001a300?})
        /nix/store/s1xk6hrfn0kw8ycvqbx4vv4gr00k6qpl-go-1.21.1/share/go/src/runtime/panic.go:920 +0x26c
main.handler({0x102607bc0, 0x14000152000}, 0x14000130100)
        /Users/nate/code/mockpi/main.go:37 +0x240
net/http.HandlerFunc.ServeHTTP(0x14000149b08?, {0x102607bc0?, 0x14000152000?}, 0x1024fdb48?)
        /nix/store/s1xk6hrfn0kw8ycvqbx4vv4gr00k6qpl-go-1.21.1/share/go/src/net/http/server.go:2136 +0x38
net/http.(*ServeMux).ServeHTTP(0x1027c63a0?, {0x102607bc0, 0x14000152000}, 0x14000130100)
        /nix/store/s1xk6hrfn0kw8ycvqbx4vv4gr00k6qpl-go-1.21.1/share/go/src/net/http/server.go:2514 +0x144
net/http.serverHandler.ServeHTTP({0x1400007ec30?}, {0x102607bc0?, 0x14000152000?}, 0x6?)
        /nix/store/s1xk6hrfn0kw8ycvqbx4vv4gr00k6qpl-go-1.21.1/share/go/src/net/http/server.go:2938 +0xbc
net/http.(*conn).serve(0x14000140000, {0x1026083f8, 0x1400007eb40})
        /nix/store/s1xk6hrfn0kw8ycvqbx4vv4gr00k6qpl-go-1.21.1/share/go/src/net/http/server.go:2009 +0x518
created by net/http.(*Server).Serve in goroutine 1
        /nix/store/s1xk6hrfn0kw8ycvqbx4vv4gr00k6qpl-go-1.21.1/share/go/src/net/http/server.go:3086 +0x4cc

we should check for the presence of the header first and return a 400 Bad Request when it's missing instead

@notnmeyer
Copy link
Owner Author

fixed in #15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant