blob: 52f5af6ca437ef6e7b42dfefa7d32d57d92af4b1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http;
import com.yahoo.container.jdisc.HttpResponse;
import org.apache.http.Header;
import org.apache.http.client.methods.CloseableHttpResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Optional;
/**
* Proxies response back to client, keeps Content-Type header if it is present
*
* @author olaa
* @author freva
*/
class ProxyResponse extends HttpResponse {
private final CloseableHttpResponse clientResponse;
ProxyResponse(CloseableHttpResponse clientResponse) {
super(clientResponse.getStatusLine().getStatusCode());
this.clientResponse = clientResponse;
}
@Override
public String getContentType() {
return Optional.ofNullable(clientResponse.getFirstHeader("Content-Type"))
.map(Header::getValue)
.orElseGet(super::getContentType);
}
@Override
public void render(OutputStream outputStream) throws IOException {
try (clientResponse) {
clientResponse.getEntity().writeTo(outputStream);
}
}
}
|