Code server: fix proxying gzipped resources

This commit is contained in:
Alexey Andreev 2020-02-26 14:27:49 +03:00
parent eeca1a502c
commit 6790ad0818

View File

@ -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));
}
}
}