java - Serve an already-gzipped response from a Servlet -
i have gzipped json resource in application want serve via servlet. browsers disagree on why, none of them load content. wrong code?
public class myservlet extends httpservlet { @override protected void doget(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception { resp.setstatus(200); inputstream in = <get input stream gzipped data>; resp.setintheader("content-length", in.available()); outputstream out = resp.getoutputstream(); out.write(ioutils.tobytearray(in)); out.close(); resp.setheader("content-encoding", "gzip"); resp.setheader("content-type", "application/json"); } }
i think answer looking available in link in accepted answer in thread - serve gzipped content java servlets.
this includes working example o'reilly site.
however question need introducing cross curling concern , gzip contents manually. assuming using apache or fork thereof, suggest @ mod_deflate configurable , powerful , releases need write boilerplate code gzipping responses.