@@ -241,6 +241,35 @@ def test_query_params_with_encoding
241241 end
242242 end
243243
244+ def test_host
245+ with_server ( -> ( request ) { handler_return_host ( request ) } ) do |client |
246+ response = client . get ( "/" )
247+ assert_equal 200 , response . status
248+ # The Host header should contain the server address
249+ host_header = JSON . parse ( response . body ) [ "message" ]
250+ assert_match ( /127\. 0\. 0\. 1/ , host_header )
251+ end
252+ end
253+
254+ def test_http2_host
255+ with_server ( -> ( request ) { handler_return_host ( request ) } ) do |client |
256+ # Configure client for HTTP/2
257+ client = client . with (
258+ debug : STDERR ,
259+ debug_level : 3 ,
260+ fallback_protocol : "h2"
261+ )
262+
263+ response = client . get ( "/" )
264+ assert_equal 200 , response . status
265+ assert_equal "2.0" , response . version
266+
267+ # The Host header should contain the server address
268+ host_header = JSON . parse ( response . body ) [ "message" ]
269+ assert_match ( /127\. 0\. 0\. 1/ , host_header )
270+ end
271+ end
272+
244273 private
245274
246275 def handler_simple ( request )
@@ -256,6 +285,10 @@ def handler_return_header(request, header_key)
256285 HyperRuby ::Response . new ( 200 , { 'Content-Type' => 'application/json' } , { message : request . header ( header_key ) } . to_json )
257286 end
258287
288+ def handler_return_host ( request )
289+ HyperRuby ::Response . new ( 200 , { 'Content-Type' => 'application/json' } , { message : request . host ( ) } . to_json )
290+ end
291+
259292 def handler_return_all_headers ( request )
260293 HyperRuby ::Response . new ( 200 , { 'Content-Type' => 'application/json' } , { headers : request . headers } . to_json )
261294 end
0 commit comments