[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jetty-users] Possible bug in 9.4 HttpServletResponse redirect?
|
Hi,
On Thu, Jan 5, 2017 at 4:14 PM, Silvio Bierman
<sbierman@xxxxxxxxxxxxxxxxxx> wrote:
> Hello all,
>
> With Jetty 9.4 I experience failure of some code that used to work with
> previous Jetty versions. But since I am unsure if my code is valid I want to
> check here first.
>
> My code is supposed to proxy an incoming request by forwarding it to another
> server (using HttpURLConnection) and then pass back the result to the
> response. In pseudo-code and somewhat simplified it does something like:
>
> - forward all headers from HttpServletRequest#getHeaderNames +
> HttpServletRequest#getHeaders via HttpURLConnection#addRequestProperty
> - forward request body from HttpServletRequest#getInputStream to
> HttpURLConnection#getOutputStream
> - pass back all headers from HttpURLConnection#getHeaderFields to
> HttpServletResponse#addHeader
> - pass back response body from HttpURLConnection#getInputStream to
> HttpServletResponse#getOutputStream
> - HttpServletResponse#sendError(HttpURLConnection#getResponseCode)
Oh wow !
You cannot do that, and I'm surprised it even worked in Jetty 9.3 - it
probably only does because the content is small.
You want to set the response code *before* writing any content via
HttpServletResponse#setStatus().
The reason it does not work in 9.4.x is that we have cleaned up the
way we handle errors, that was pretty broken in 9.3.x (so I guess your
code was working because of a Jetty 9.3.x bug).
Have you considered using one of the many Jetty ProxyServlets, or at
least HttpClient instead of HttpURLConnection ?
--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.