0

I'm using Jetty 9.4.9.v20180320. I have implemented Reverse Proxy by extending Transparent servlet. I have overridden rewriteTarget and filterServerResponseHeader methods

  public class ServicesProxyServlet extends Transparent {
private static final long   serialVersionUID    = 1L;

@Override
protected String rewriteTarget(HttpServletRequest request) {
        ...
    return rewrittenURI;
}

@Override
protected String filterServerResponseHeader(HttpServletRequest clientRequest, Response serverResponse, String headerName, String headerValue) {
        ...
    return super.filterServerResponseHeader(clientRequest, serverResponse, headerName, headerValue);
}
}

The destination server sends chunked response at given interval of time.

Now, it seems the Transparent proxy receives the whole response before sending it to client which causes the client timeout with 504 Gateway Timeout. If I removed filterServerResponseHeader the error still occurs.

I expect to send the chunked response to client without buffering it in Transparent proxy. This would avoid client timeout. How to flush the received data immediately in Transparent proxy? How to handle this?

Malini Kennady
  • 371
  • 1
  • 7
  • 19
  • You should be using `AsyncProxyServlet.Transparent` (not `ProxyServlet.Transparent`), and an up to date version of Jetty (9.4.9 is old). – Joakim Erdfelt Aug 14 '19 at 10:25
  • @JoakimErdfelt I changed to `AsyncProxyServlet.Transparent`. I've overridden `onResponseContent` and used `HttpServletResponse.response.flushBuffer()`. This flushes header immediately. I have tried `response.getOutputStream().flush();` This does not flush chunked response. How to flush chunked data upon receiving from server? – Malini Kennady Aug 19 '19 at 10:39
  • @JoakimErdfelt I followed [link](https://jar-download.com/artifacts/org.eclipse.jetty/jetty-proxy/9.4.12.RC0/source-code/org/eclipse/jetty/proxy/ProxyServlet.java) and overrided `onResponseContent` and added `response.getOutputStream().flush();` to this method. It is flushing content immediately. Is this method fine? – Malini Kennady Aug 19 '19 at 14:01
  • Your link points to 9.4.12.RC0 (which is a unstable Release Candidate), don't use that in production. use an official stable release. – Joakim Erdfelt Aug 19 '19 at 14:04
  • I have not updated the jar. I have just override the method in the code given in question. So looking as a whole, to achieve reverse proxy I have created class by extending `AsyncProxyServlet.Transparent` and override 3 methods, `rewriteTarget`, `filterServerResponseHeader` and `onResponseContent`. – Malini Kennady Aug 19 '19 at 14:12

0 Answers0