I am trying to reduce network traffic with Gzipping all responses from the backend, but I ran into a problem when the cookie is not set in the browser, if the I / O call is executed the same way, and I donβt know why.
This is the internal code in Java.
Cookie cookie = new Cookie("cookie_name", cookieToken); cookie.setPath("/"); cookie.setMaxAge(Integer.MAX_VALUE); response.addCookie(cookie); response.setContentType("application/json; charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Content-Encoding", "gzip"); String json=serviceOutput.toString(); byte[] gzip = Utils.gzip(json.getBytes("UTF-8")); response.setContentLength(gzip.length); response.getOutputStream().write(gzip);
Any pointer to why this is not working? I am sure that I did the same thing earlier without any problems.
-
Gzip method added just in case it matches
public static byte[] gzip(byte[] content) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream g = new GZIPOutputStream(baos); if (content != null && content.length > 0) { g.write(content, 0, content.length); g.close(); } return baos.toByteArray(); }
java browser cookies gzip
juminoz
source share