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 if mock is not nil before writing response #115

Merged
merged 1 commit into from
Apr 27, 2024

Conversation

martinsirbe
Copy link
Contributor

This pull request introduces a safeguard in the event that the mock object is nil. This will fix cases where the response is HTTP 204 with no response body.

http: panic serving [::1]:54949: http: request method or response status code does not allow body
goroutine 5165 [running]:
net/http.(*conn).serve.func1()
        /usr/local/go/src/net/http/server.go:1898 +0x118
panic({0x104071000?, 0x1400031fde0?})
        /usr/local/go/src/runtime/panic.go:770 +0xf0
github.com/pb33f/wiretap/daemon.(*WiretapService).handleMockRequest(0x140010aa820, 0x140015fc240, 0x140003a0908, 0x140014d4fc0)
        /Users/martinsirbe/dev/go/src/github.com/pb33f/wiretap/daemon/handle_mock.go:95 +0xf3c
github.com/pb33f/wiretap/daemon.(*WiretapService).handleHttpRequest(0x140010aa820, 0x140015fc240)
        /Users/martinsirbe/dev/go/src/github.com/pb33f/wiretap/daemon/handle_request.go:137 +0x718
github.com/pb33f/wiretap/daemon.(*WiretapService).HandleHttpRequest(0x140010aa820, 0x140015fc240)
        /Users/martinsirbe/dev/go/src/github.com/pb33f/wiretap/daemon/wiretap_service.go:98 +0x24
github.com/pb33f/wiretap/cmd.handleHttpTraffic.func1.1({0x10421d9d0, 0x140011c7450}, 0x140014d4ea0)
        /Users/martinsirbe/dev/go/src/github.com/pb33f/wiretap/cmd/handle_http_traffic.go:27 +0x198
net/http.HandlerFunc.ServeHTTP(0x14000982210, {0x10421d9d0, 0x140011c7450}, 0x140014d4ea0)
        /usr/local/go/src/net/http/server.go:2166 +0x40
net/http.(*ServeMux).ServeHTTP(0x1400128e9c0, {0x10421d9d0, 0x140011c7450}, 0x140014d4ea0)
        /usr/local/go/src/net/http/server.go:2683 +0x29c
github.com/gorilla/handlers.CompressHandlerLevel.func1({0x10421d9d0, 0x140011c7450}, 0x140014d4ea0)
        /Users/martinsirbe/dev/go/pkg/mod/github.com/gorilla/[email protected]/compress.go:148 +0xc4c
net/http.HandlerFunc.ServeHTTP(0x1400103e080, {0x10421db50, 0x14000216000}, 0x140014d4ea0)
        /usr/local/go/src/net/http/server.go:2166 +0x40
net/http.serverHandler.ServeHTTP({0x1400152a1e0}, {0x10421db50, 0x14000216000}, 0x140014d4ea0)
        /usr/local/go/src/net/http/server.go:3137 +0x2b0
net/http.(*conn).serve(0x14000e4ed80, {0x10421f678, 0x140011c7310})
        /usr/local/go/src/net/http/server.go:2039 +0x15f8
created by net/http.(*Server).Serve in goroutine 7620
        /usr/local/go/src/net/http/server.go:3285 +0x88c

Copy link
Member

@daveshanley daveshanley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank you!

@daveshanley daveshanley merged commit bd63eae into pb33f:main Apr 27, 2024
2 checks passed
@martinsirbe martinsirbe deleted the check-mock-not-nil-before-write branch April 27, 2024 18:35
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

Successfully merging this pull request may close these issues.

2 participants