diff options
author | Valerij Fredriksen <valerijf@yahooinc.com> | 2022-04-07 14:07:47 +0200 |
---|---|---|
committer | Valerij Fredriksen <valerijf@yahooinc.com> | 2022-04-07 14:20:08 +0200 |
commit | 9be53748e3acc410e58cc245c1965d7f20004150 (patch) | |
tree | d8b33754e406b8f2af2cfb2fcb685d66c5cddf7d /configserver/src | |
parent | 4c3de59b341522a53e3ebbf8ad40bd2b12aff86e (diff) |
Proxy without going via UTF-8
Diffstat (limited to 'configserver/src')
3 files changed, 8 insertions, 27 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/HttpProxy.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/HttpProxy.java index 14acd1b5630..37ee4f25f83 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/HttpProxy.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/HttpProxy.java @@ -6,11 +6,6 @@ import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.model.api.PortInfo; import com.yahoo.config.model.api.ServiceInfo; import com.yahoo.container.jdisc.HttpResponse; - -import java.util.HashSet; -import java.util.List; -import java.util.logging.Level; - import com.yahoo.net.DomainName; import com.yahoo.restapi.HttpURL; import com.yahoo.restapi.HttpURL.Path; @@ -22,10 +17,9 @@ import com.yahoo.vespa.config.server.http.NotFoundException; import com.yahoo.vespa.config.server.http.SimpleHttpFetcher; import java.net.MalformedURLException; -import java.net.URL; +import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; -import java.util.stream.Stream; public class HttpProxy { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/SimpleHttpFetcher.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/SimpleHttpFetcher.java index 4fb14dacd9a..6add1f7a9fc 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/SimpleHttpFetcher.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/SimpleHttpFetcher.java @@ -8,16 +8,13 @@ import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.HttpEntity; -import org.apache.hc.core5.http.ParseException; -import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.hc.core5.util.Timeout; -import java.util.logging.Level; - import java.io.IOException; import java.net.SocketTimeoutException; import java.net.URISyntaxException; import java.net.URL; +import java.util.logging.Level; import java.util.logging.Logger; public class SimpleHttpFetcher implements HttpFetcher { @@ -40,16 +37,12 @@ public class SimpleHttpFetcher implements HttpFetcher { return new StaticResponse( response.getCode(), entity.getContentType(), - EntityUtils.toString(entity)); + entity.getContent().readAllBytes()); } } catch (SocketTimeoutException e) { String message = "Timed out after " + params.readTimeoutMs + " ms reading response from " + url; logger.log(Level.WARNING, message, e); throw new RequestTimeoutException(message); - } catch (ParseException e) { - String message = "Parse error in response from " + url; - logger.log(Level.WARNING, message, e); - throw new InternalServerException(message); } catch (IOException e) { String message = "Failed to get response from " + url; logger.log(Level.WARNING, message, e); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/StaticResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/StaticResponse.java index 3b0f29be765..a64a5551095 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/StaticResponse.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/StaticResponse.java @@ -3,33 +3,27 @@ package com.yahoo.vespa.config.server.http; import com.yahoo.container.jdisc.HttpResponse; -import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; public class StaticResponse extends HttpResponse { private final String contentType; - private final InputStream body; + private final byte[] body; - /** - * @param body Ownership is passed to StaticResponse (is responsible for closing it) - */ - public StaticResponse(int status, String contentType, InputStream body) { + public StaticResponse(int status, String contentType, byte[] body) { super(status); this.contentType = contentType; this.body = body; } public StaticResponse(int status, String contentType, String body) { - this(status, contentType, new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); + this(status, contentType, body.getBytes(StandardCharsets.UTF_8)); } @Override public void render(OutputStream outputStream) throws IOException { - body.transferTo(outputStream); - body.close(); + outputStream.write(body); } @Override |