@@ -109,11 +109,6 @@ public ProxyRequestHandler(
109109 proxyResponseConfiguration = haGatewayConfiguration .getProxyResponseConfiguration ();
110110 }
111111
112- private static String getRemoteTarget (URI remoteUri )
113- {
114- return format ("%s://%s" , remoteUri .getScheme (), remoteUri .getAuthority ());
115- }
116-
117112 private static Response handleProxyException (Request request , ProxyException e )
118113 {
119114 log .warn (e , "Proxy request failed: %s %s" , request .getMethod (), request .getUri ());
@@ -129,8 +124,7 @@ private static WebApplicationException badRequest(String message)
129124 .build ());
130125 }
131126
132- public static QueryHistoryManager .QueryDetail getQueryDetailsFromRequest (Request request ,
133- Optional <String > username )
127+ public static QueryHistoryManager .QueryDetail getQueryDetailsFromRequest (Request request , Optional <String > username )
134128 {
135129 QueryHistoryManager .QueryDetail queryDetail = new QueryHistoryManager .QueryDetail ();
136130 queryDetail .setBackendUrl (getRemoteTarget (request .getUri ()));
@@ -143,6 +137,11 @@ public static QueryHistoryManager.QueryDetail getQueryDetailsFromRequest(Request
143137 return queryDetail ;
144138 }
145139
140+ private static String getRemoteTarget (URI remoteUri )
141+ {
142+ return format ("%s://%s" , remoteUri .getScheme (), remoteUri .getAuthority ());
143+ }
144+
146145 @ PreDestroy
147146 public void shutdown ()
148147 {
@@ -201,8 +200,7 @@ private void performRequest(
201200 for (String name : list (servletRequest .getHeaderNames ())) {
202201 for (String value : list (servletRequest .getHeaders (name ))) {
203202 // TODO: decide what should and shouldn't be forwarded
204- if (!name .equalsIgnoreCase ("Accept-Encoding" )
205- && !name .equalsIgnoreCase ("Host" )
203+ if (!name .equalsIgnoreCase ("Host" )
206204 && (addXForwardedHeaders || !name .startsWith ("X-Forwarded" ))) {
207205 requestBuilder .addHeader (name , value );
208206 }
@@ -262,7 +260,7 @@ else if (servletRequest.getCookies() != null) {
262260
263261 private Response buildResponse (ProxyResponse response , ImmutableList <NewCookie > cookie )
264262 {
265- Response .ResponseBuilder builder = Response .status (response .statusCode ()).entity (response .body ());
263+ Response .ResponseBuilder builder = Response .status (response .statusCode ()).entity (response .getRawBody ());
266264 response .headers ().forEach ((headerName , value ) -> builder .header (headerName .toString (), value ));
267265 cookie .forEach (builder ::cookie );
268266 return builder .build ();
@@ -287,26 +285,27 @@ private FluentFuture<ProxyResponse> executeHttp(Request request)
287285 private ProxyResponse recordBackendForQueryId (Request request , ProxyResponse response , Optional <String > username ,
288286 RoutingDestination routingDestination )
289287 {
290- log .debug ("For Request [%s] got Response [%s]" , request .getUri (), response .body ());
288+ String body = response .getDecompressedBody ();
289+ log .debug ("For Request [%s] got Response [%s]" , request .getUri (), body );
291290
292291 QueryHistoryManager .QueryDetail queryDetail = getQueryDetailsFromRequest (request , username );
293292
294293 log .debug ("Extracting proxy destination : [%s] for request : [%s]" , queryDetail .getBackendUrl (), request .getUri ());
295294
296295 if (response .statusCode () == OK .getStatusCode ()) {
297296 try {
298- HashMap <String , String > results = OBJECT_MAPPER .readValue (response . body () , HashMap .class );
297+ HashMap <String , String > results = OBJECT_MAPPER .readValue (body , HashMap .class );
299298 queryDetail .setQueryId (results .get ("id" ));
300299 routingManager .setBackendForQueryId (queryDetail .getQueryId (), queryDetail .getBackendUrl ());
301300 routingManager .setRoutingGroupForQueryId (queryDetail .getQueryId (), routingDestination .routingGroup ());
302301 log .debug ("QueryId [%s] mapped with proxy [%s]" , queryDetail .getQueryId (), queryDetail .getBackendUrl ());
303302 }
304303 catch (IOException e ) {
305- log .error ("Failed to get QueryId from response [%s] , Status code [%s]" , response . body () , response .statusCode ());
304+ log .error ("Failed to get QueryId from response [%s] , Status code [%s]" , body , response .statusCode ());
306305 }
307306 }
308307 else {
309- log .error ("Non OK HTTP Status code with response [%s] , Status code [%s], user: [%s]" , response . body () , response .statusCode (), username .orElse (null ));
308+ log .error ("Non OK HTTP Status code with response [%s] , Status code [%s], user: [%s]" , body , response .statusCode (), username .orElse (null ));
310309 }
311310 queryDetail .setRoutingGroup (routingDestination .routingGroup ());
312311 queryDetail .setExternalUrl (routingDestination .externalUrl ());
0 commit comments