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

Request body consumed and not available to later middleware handlers #810

Open
clinejj opened this issue Apr 5, 2024 · 1 comment
Open
Assignees

Comments

@clinejj
Copy link

clinejj commented Apr 5, 2024

Summary

We're using Gorillamux and net/http and ran into an issue where the Sentry handler consumes the request body, which makes int unavailable for later handlers/middleware to use.

Steps To Reproduce

I don't have a fully reproducible code path, but rough outline:

router.HandleFunc("/some/path", PathHandler())

var sentryHandler = sentryhttp.New(sentryhttp.Options{
	Repanic:         true,
	WaitForDelivery: false,
})

func AuthUser() func(http.ResponseWriter, *http.Request) {
  return sentryHandler.handleFunc(func(rw http.ResponseWriter, r *http.Request) {
    r.ParseForm()
    someForm := r.FormValue("formKey")
    // someForm is blank and the parseForm will be empty because the body has been consumed
  })
}

When removing the sentry handler, the request form can be read as normal.

Expected Behavior

Later handler functions are able to use the body on the original request without having to pre-cache or otherwise get the body before the Sentry handler is used.

Screenshots

Sentry.io Event

n/a

Environment

SDK

  • sentry-go version: 0.27
  • Go version: 1.22.1
  • Using Go Modules? yes

Sentry

  • Using hosted Sentry in sentry.io? yes
  • Using your own Sentry installation? Version: n/a
  • Anything particular to your environment that could be related to this issue?

Additional context

@ribice
Copy link
Collaborator

ribice commented Apr 6, 2024

I tested this in multiple ways (just a route, wrapped, middleware) and every time it worked fine with and without the sentry handler.

Could you please provide a way to reproduce this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants