@@ -77,6 +77,14 @@ public MockResponse dispatch(RecordedRequest request)
7777 .setBody ("{\" starting\" : false}" );
7878 }
7979
80+ if (request .getPath ().equals (healthCheckEndpoint + "?test-compression" )) {
81+ // Return the Accept-Encoding header value for compression testing
82+ String acceptEncoding = request .getHeader ("Accept-Encoding" );
83+ return new MockResponse ().setResponseCode (200 )
84+ .setHeader (CONTENT_TYPE , JSON_UTF_8 )
85+ .setBody (acceptEncoding != null ? acceptEncoding : "null" );
86+ }
87+
8088 if (request .getMethod ().equals ("PUT" ) && request .getPath ().equals (customPutEndpoint )) {
8189 return new MockResponse ().setResponseCode (200 )
8290 .setHeader (CONTENT_TYPE , JSON_UTF_8 )
@@ -156,4 +164,53 @@ void testGetQueryDetailsFromRequest()
156164 assertThat (queryDetail .getSource ()).isEqualTo ("trino-cli" );
157165 assertThat (queryDetail .getBackendUrl ()).isEqualTo ("http://localhost:" + routerPort );
158166 }
167+
168+ @ Test
169+ void testAcceptEncodingHeaderForwarding ()
170+ throws Exception
171+ {
172+ // Test that Accept-Encoding header is properly forwarded to backends
173+ String url = "http://localhost:" + routerPort + healthCheckEndpoint + "?test-compression" ;
174+ String expectedAcceptEncoding = "gzip, deflate, br" ;
175+
176+ Request request = new Request .Builder ()
177+ .url (url )
178+ .get ()
179+ .addHeader ("Accept-Encoding" , expectedAcceptEncoding )
180+ .build ();
181+
182+ try (Response response = httpClient .newCall (request ).execute ()) {
183+ assertThat (response .code ()).isEqualTo (200 );
184+ assertThat (response .body ()).isNotNull ();
185+
186+ // The mock backend returns the Accept-Encoding header value in the response
187+ // body
188+ String receivedAcceptEncoding = response .body ().string ();
189+ assertThat (receivedAcceptEncoding ).isEqualTo (expectedAcceptEncoding );
190+ }
191+ }
192+
193+ @ Test
194+ void testDefaultAcceptEncodingHeaderForwarding ()
195+ throws Exception
196+ {
197+ // Test that requests without explicit Accept-Encoding header work correctly
198+ // Note: OkHttp automatically adds "Accept-Encoding: gzip" when none is
199+ // specified
200+ String url = "http://localhost:" + routerPort + healthCheckEndpoint + "?test-compression" ;
201+
202+ Request request = new Request .Builder ()
203+ .url (url )
204+ .get ()
205+ .build (); // No explicit Accept-Encoding header
206+
207+ try (Response response = httpClient .newCall (request ).execute ()) {
208+ assertThat (response .code ()).isEqualTo (200 );
209+ assertThat (response .body ()).isNotNull ();
210+
211+ // OkHttp automatically adds "Accept-Encoding: gzip" when none is specified
212+ String receivedAcceptEncoding = response .body ().string ();
213+ assertThat (receivedAcceptEncoding ).isEqualTo ("gzip" );
214+ }
215+ }
159216}
0 commit comments