getsentry / sentry-go

The official Go SDK for Sentry (sentry.io)

Home Page:https://docs.sentry.io/platforms/go/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request body consumed and not available to later middleware handlers

clinejj opened this issue · comments

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

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?