New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GzipHandler and GzipHttpOutputInterceptor do not flush response when body is empty #4835
Comments
9.4.15 is old. (and has a few CVEs filed against it - https://www.eclipse.org/jetty/security-reports.html) What are your |
Looking at the code, it seems that on initial flush the Which enters with the parameters ...
Which means that that Using Also, it seems our |
Small demo project that reproduces the report. Use $ curl -H "Accept-Encoding: gzip" -o /dev/null -vvvv http://localhost:8888/demo/ package jetty.gzip;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.IntStream;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
public class GzipFlushBufferDemo
{
public static void main(String[] args) throws Exception
{
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8888);
server.addConnector(connector);
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setContextPath("/");
contextHandler.addServlet(FlushBufferServlet.class, "/demo/");
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setHandler(contextHandler);
server.setHandler(gzipHandler);
server.start();
server.join();
}
public static class FlushBufferServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/plain");
ServletOutputStream out = response.getOutputStream();
response.flushBuffer();
try { Thread.sleep(5000); } catch (InterruptedException ignored) { }
byte[] buf = new byte[8000];
ThreadLocalRandom.current().nextBytes(buf);
out.write(buf);
}
}
} |
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Thanks for the quick response to this. May I know when (ETA) 9.4.29 will be released? |
Issue #4835 - Addressing flush/commit with GzipHttpOutputInterceptor
Merged into |
Jetty version
9.4.15.v20190215
Java version
Java 11
OS type/version
Most Os (Mac and Unix)
Description
Recently we switched to Jetty 9.4 from Jetty 9.0. Jetty 9.4 comes with GzipHandler so we used that. At the request processing time we flush out response to send back (link) headers to browser early by doing response.flushBuffer(), this is done on purpose. In jetty 9.0's GzipFilter response used to be flushed right away but in GzipHandler it isn't flushed (because we are flushing only headers and body is empty). This is causing an increase in wait time in the browser as headers are received a little late on the browser side. I was wondering how can we make this response flush immediately in GzipHanlder in Jetty9.4? apparently GZIP output interceptor doesn't flush response headers when the response.flushBuffer() is called and when the body is empty!
The text was updated successfully, but these errors were encountered: