From a93b2c608470ecb2853fdc8417ae54b5424268f6 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 5 May 2020 14:48:36 +0200 Subject: [PATCH] Fixes #4808 - Review HttpClient Request header APIs. Fixed test failures. Signed-off-by: Simone Bordet --- .../main/java/org/eclipse/jetty/client/HttpResponse.java | 2 +- .../org/eclipse/jetty/proxy/AbstractProxyServlet.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpResponse.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpResponse.java index 28c0dcf0df6c..012cd425b5d0 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpResponse.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpResponse.java @@ -118,7 +118,7 @@ public List getListeners(Class type) public HttpFields getTrailers() { - return trailers.asImmutable(); + return trailers == null ? null : trailers.asImmutable(); } public HttpResponse trailer(HttpField trailer) diff --git a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java index 4f2c8a749601..8e5669e1a269 100644 --- a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java +++ b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java @@ -538,8 +538,12 @@ protected void addXForwardedHeaders(HttpServletRequest clientRequest, Request pr { 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_HOST, clientRequest.getHeader(HttpHeader.HOST.asString()))); - proxyRequest.headers(headers -> headers.add(HttpHeader.X_FORWARDED_SERVER, clientRequest.getLocalName())); + String hostHeader = clientRequest.getHeader(HttpHeader.HOST.asString()); + 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)