Skip to content
Snippets Groups Projects

feat: Add GZIP support to DefaultAPIMiddleware

3 files
+ 132
4
Compare changes
  • Side-by-side
  • Inline
Files
3
/* Copyright (c) 2019 Eclipse Foundation and others.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License 2.0
* which is available at http://www.eclipse.org/legal/epl-v20.html,
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipsefoundation.core.service.impl;
import java.io.InputStream;
@@ -7,6 +14,7 @@ import java.util.List;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
@@ -25,11 +33,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.arc.Unremovable;
/**
* Serves as a middleware for external calls. This generalizes retrieving multiple pages of data using the Link header
* rather than manually iterating over the data or using less robust checks (such as no data in response), or for
* Serves as a middleware for external calls. This generalizes retrieving
* multiple pages of data using the Link header
* rather than manually iterating over the data or using less robust checks
* (such as no data in response), or for
* passing that pagination data on to the current request.
*
* @author Martin Lowe
* @author Martin Lowe, Zachary Sabourin
*
*/
@ApplicationScoped
@@ -85,7 +95,9 @@ public class DefaultAPIMiddleware implements APIMiddleware {
private <T> List<T> readInValue(List<T> out, Response r, Class<T> type) {
Object o = r.getEntity();
try {
if (o instanceof InputStream) {
if (o instanceof InputStream && r.getHeaderString("Content-Encoding").equalsIgnoreCase("GZIP")) {
out.addAll(objectMapper.readerForListOf(type).readValue(new GZIPInputStream((InputStream) o)));
} else if (o instanceof InputStream) {
out.addAll(objectMapper.readerForListOf(type).readValue((InputStream) o));
} else if (type.isAssignableFrom(o.getClass())) {
out.add((T) o);
Loading