Skip to content

Commit 874d709

Browse files
committed
HttpURLConnectionDownloaderService: be tolerant with gzipped response that has unknown size.
Required for #660
1 parent 14a7f9e commit 874d709

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/java/ru/mystamps/web/service/HttpURLConnectionDownloaderService.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ private Code validateConnection(HttpURLConnection conn) throws IOException {
184184
return Code.INVALID_FILE_TYPE;
185185
}
186186

187-
// TODO: content length can be -1 for gzipped responses
188187
// TODO: add protection against huge files
188+
// When the content length is not known, methods returns -1. It also happens for gzipped
189+
// response. In this case, we allow to download a file and relies to a form validation
190+
// that will take place later.
189191
int contentLength = conn.getContentLength();
190-
if (contentLength < 0) {
192+
if (contentLength == 0) {
191193
// TODO(security): fix possible log injection
192194
LOG.debug("Couldn't download file: invalid Content-Length: {}", contentLength);
193195
return Code.INVALID_FILE_SIZE;

0 commit comments

Comments
 (0)