/** @see Service#service(nextapp.echo.webcontainer.Connection) */ @Override public final void service(Connection conn) throws IOException { /* * Apply our specific cache seconds value if it has been specified * using the system property. */ if (StringVersionService.Manager.cacheSeconds != -1l) { conn.getResponse() .setHeader( "Cache-Control", "max-age=" + String.valueOf(StringVersionService.Manager.cacheSeconds) + ", public"); conn.getResponse() .setDateHeader( "Expires", System.currentTimeMillis() + (StringVersionService.Manager.cacheSeconds * 1000)); } String userAgent = conn.getRequest().getHeader("user-agent"); if (!StringVersionService.Manager.allowIEcompression && (userAgent == null || userAgent.indexOf("MSIE") != -1)) { // Due to behavior detailed Microsoft Knowledge Base Article Id 312496, // all HTTP compression support is disabled for this browser. // Due to the fact that ClientProperties information is not necessarily // available at this stage, browsers which provide deceitful user-agent // headers will also be affected. servicePlain(conn); } else { String acceptEncoding = conn.getRequest().getHeader("accept-encoding"); if (acceptEncoding != null && acceptEncoding.indexOf("gzip") != -1) { serviceGZipCompressed(conn); } else { servicePlain(conn); } } }
/** * Renders the resource WITHOUT using GZip encoding. * * @param conn the relevant <code>Connection</code> */ private void servicePlain(Connection conn) throws IOException { conn.getResponse().setContentType(getContnentType().getMimeType()); conn.getWriter().print(content); }
/** * Renders the resource using GZip encoding. * * @param conn the relevant <code>Connection</code> */ private void serviceGZipCompressed(Connection conn) throws IOException { conn.getResponse().setContentType(getContnentType().getMimeType()); conn.getResponse().setHeader("Content-Encoding", "gzip"); conn.getOutputStream().write(gzipContent); }