Skip to content

Commit 426fb55

Browse files
author
Hideki Itakura
authored
Merge pull request #1378 from thaddeusalbers/gzipped_attachment_content_not_gzipped
Fixed gzipped attachment not returning gzipped content.
2 parents 90337e9 + 2717980 commit 426fb55

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/main/java/com/couchbase/lite/internal/AttachmentInternal.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ public InputStream getContentInputStream() {
211211
return new ByteArrayInputStream(getContent());
212212
}
213213

214+
public InputStream getEncodedContentInputStream() { return new ByteArrayInputStream(getEncodedContent()); }
215+
214216
public URL getContentURL() throws MalformedURLException {
215217
String path = database.getAttachmentStore().getBlobPathForKey(blobKey);
216218
return path != null ? new File(path).toURI().toURL() : null;

src/main/java/com/couchbase/lite/router/Router.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,10 +2054,12 @@ public Status do_GET_Attachment(Database _db, String docID, String _attachmentNa
20542054
if (acceptEncoding != null && acceptEncoding.contains("gzip") &&
20552055
attachment.getEncoding() == AttachmentInternal.AttachmentEncoding.AttachmentEncodingGZIP) {
20562056
connection.getResHeader().add("Content-Encoding", "gzip");
2057+
connection.setResponseInputStream(attachment.getEncodedContentInputStream());
2058+
}
2059+
else {
2060+
connection.setResponseInputStream(attachment.getContentInputStream());
20572061
}
2058-
20592062
dontOverwriteBody = true;
2060-
connection.setResponseInputStream(attachment.getContentInputStream());
20612063
return new Status(Status.OK);
20622064

20632065
} catch (CouchbaseLiteException e) {

0 commit comments

Comments
 (0)