0

Why is it that the bodies a HttpServletRequest and HttpServletResponse are accessable only once? Due to this fact, you are obligated to create your own mutable/multi-readable request and response. One can always use Spring ContentCached-Wrappers, but in the case of the request it's necessary to call the getParameters method, and in the case of the response one needs to call the copyBodyToResponse method. Why did they implemented is like this?

Vince
  • 1
  • 1
  • This is defined, kind of, in the servlet specification. Section 3.1.1 to be precise, about accessing parameters. – M. Deinum Apr 25 '19 at 14:30
  • It's very important that you don't call getParameter(), getParameterMap(), getParameterValues(), getInputStream(), getReader(), etc on the same request beforehand. Otherwise the servlet container will read and parse the request body and thus you will get an empty request body. see also- https://stackoverflow.com/q/13881272/8098322 – Onkar Musale Apr 26 '19 at 05:01

1 Answers1

0

Got this from https://gist.github.com/calo81/2071634, bhonnegowda commented on Apr 15, 2015: "When you read the content of a request, you access its InputStream object and that InputStream cannot be reset to its initial position to re-read the content of the request. It's simply not possible, you can't read the content twice so apparently by making a request wrapper you essentially get a duplicate request which leaves the original request alone."

Vince
  • 1
  • 1