From 6790ad0818f1b0992c8406a9f51d62175761b9c3 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 26 Feb 2020 14:27:49 +0300 Subject: [PATCH] Code server: fix proxying gzipped resources --- .../java/org/teavm/devserver/CodeServlet.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/devserver/src/main/java/org/teavm/devserver/CodeServlet.java b/tools/devserver/src/main/java/org/teavm/devserver/CodeServlet.java index ca6b50324..f513199f2 100644 --- a/tools/devserver/src/main/java/org/teavm/devserver/CodeServlet.java +++ b/tools/devserver/src/main/java/org/teavm/devserver/CodeServlet.java @@ -445,8 +445,11 @@ public class CodeServlet extends HttpServlet { sent = true; resp.setStatus(response.getStatus()); + int length = -1; + boolean isGzip = false; for (HttpField field : response.getHeaders()) { - if (field.getName().toLowerCase().equals("location")) { + String name = field.getName().toLowerCase(); + if (name.equals("location")) { String value = field.getValue(); if (value.startsWith(proxyUrl)) { String relLocation = value.substring(proxyUrl.length()); @@ -454,8 +457,23 @@ public class CodeServlet extends HttpServlet { continue; } } + if (name.equals("content-encoding")) { + isGzip = true; + continue; + } else if (name.equals("content-length")) { + try { + length = Integer.parseInt(field.getValue()); + } catch (NumberFormatException e) { + // do nothing + } + continue; + } resp.addHeader(field.getName(), field.getValue()); } + + if (length > 0 && !isGzip) { + resp.addHeader("Content-Length", String.valueOf(length)); + } } }