perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.65k stars 1.56k forks source link

When using two before filters, request.body() is reseted to empty string #969

Open Frietziek opened 6 years ago

Frietziek commented 6 years ago

Hello, i am experiencing the same problem (i think) that this issue opened in 2014: #201

Basically, i have two before filters, that do some processing over request.body(), in the first filter the request come filled with body perfectly, but when the second before filter is executed, the request body comes empty...Also, it comes empty to the controller itself.

if i remove the second filter, it works ok, and come filled to the controller.

radolang commented 6 years ago

I thought I was having the same problem but I was hitting this: #666 #900

In one of my filters I was accessing request.queryParams("locale") Accessing request.queryParams somehow clears request.body

jasantoro commented 6 years ago

I've the same issue, taking a look at the code in the BeforeFilters.execute, the request delegate is set every time, in Routes and AfterFilters only if it is null.

ghost commented 6 years ago

Exact same issue as @radolang. I have a filter that call request.queryParams("locale") and the request.body() returns "" after. This is a critical bug in my opinion. A blocker in my case. I'm using Spark 2.7.2.

hunghoang commented 6 years ago

I had the same issue too My before() function access to request body(), then I cannot get the body of the request in the controller. I run sparkjava 2.7.2 in tomcat 9

markcline commented 4 years ago

@hunghoang (or for others since this ticket is super old), I had the same problem. After looking at it for a while, it looks like when using the built in Jetty server it uses a httprequestwrapper which allows you to read the body more than once. So I implemented my own filter so that tomcat would behave the same (I'm unclear why this isn't just part of Spark itself).

Here's the gist of it: https://gist.github.com/markcline/bcf6fd4304449f072991c5a36c70ff08