Fixes #4808 - Review HttpClient Request header APIs.

Fixed test failures.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2020-05-05 14:48:36 +02:00
parent cf9df70935
commit a93b2c6084
2 changed files with 7 additions and 3 deletions

View File

@ -118,7 +118,7 @@ public class HttpResponse implements Response
public HttpFields getTrailers() public HttpFields getTrailers()
{ {
return trailers.asImmutable(); return trailers == null ? null : trailers.asImmutable();
} }
public HttpResponse trailer(HttpField trailer) public HttpResponse trailer(HttpField trailer)

View File

@ -538,8 +538,12 @@ public abstract class AbstractProxyServlet extends HttpServlet
{ {
proxyRequest.headers(headers -> headers.add(HttpHeader.X_FORWARDED_FOR, clientRequest.getRemoteAddr())); proxyRequest.headers(headers -> headers.add(HttpHeader.X_FORWARDED_FOR, clientRequest.getRemoteAddr()));
proxyRequest.headers(headers -> headers.add(HttpHeader.X_FORWARDED_PROTO, clientRequest.getScheme())); proxyRequest.headers(headers -> headers.add(HttpHeader.X_FORWARDED_PROTO, clientRequest.getScheme()));
proxyRequest.headers(headers -> headers.add(HttpHeader.X_FORWARDED_HOST, clientRequest.getHeader(HttpHeader.HOST.asString()))); String hostHeader = clientRequest.getHeader(HttpHeader.HOST.asString());
proxyRequest.headers(headers -> headers.add(HttpHeader.X_FORWARDED_SERVER, clientRequest.getLocalName())); if (hostHeader != null)
proxyRequest.headers(headers -> headers.add(HttpHeader.X_FORWARDED_HOST, hostHeader));
String localName = clientRequest.getLocalName();
if (localName != null)
proxyRequest.headers(headers -> headers.add(HttpHeader.X_FORWARDED_SERVER, localName));
} }
protected void sendProxyRequest(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Request proxyRequest) protected void sendProxyRequest(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Request proxyRequest)