@@ -487,23 +487,36 @@ defmodule HTTP1ProtocolTest do
487487
488488 @ tag :capture_log
489489 test "returns 400 if a non-absolute path is send" , context do
490- client = SimpleHTTP1Client . tcp_client ( context )
491- SimpleHTTP1Client . send ( client , "GET" , "./../non_absolute_path" , [ "host: localhost" ] )
492- assert { :ok , "400 Bad Request" , _headers , << >> } = SimpleHTTP1Client . recv_reply ( client )
490+ assert { :ok , "400 Bad Request" , _headers , << >> } =
491+ recv_bad_request_with_single_retry ( context , "./../non_absolute_path" )
493492
494493 assert_receive { :log , % { level: :error , msg: { :string , msg } } } , 500
495494 assert msg == "** (Bandit.HTTPError) Unsupported request target (RFC9112§3.2)"
496495 end
497496
498497 @ tag :capture_log
499498 test "returns 400 if path has no leading slash" , context do
500- client = SimpleHTTP1Client . tcp_client ( context )
501- SimpleHTTP1Client . send ( client , "GET" , "path_without_leading_slash" , [ "host: localhost" ] )
502- assert { :ok , "400 Bad Request" , _headers , << >> } = SimpleHTTP1Client . recv_reply ( client )
499+ assert { :ok , "400 Bad Request" , _headers , << >> } =
500+ recv_bad_request_with_single_retry ( context , "path_without_leading_slash" )
503501
504502 assert_receive { :log , % { level: :error , msg: { :string , msg } } } , 500
505503 assert msg == "** (Bandit.HTTPError) Unsupported request target (RFC9112§3.2)"
506504 end
505+
506+ defp recv_bad_request_with_single_retry ( context , request_target ) do
507+ send_and_recv = fn ->
508+ client = SimpleHTTP1Client . tcp_client ( context )
509+ SimpleHTTP1Client . send ( client , "GET" , request_target , [ "host: localhost" ] )
510+ SimpleHTTP1Client . recv_reply ( client )
511+ end
512+
513+ try do
514+ send_and_recv . ( )
515+ rescue
516+ e in MatchError ->
517+ if e . term == { :error , :closed } , do: send_and_recv . ( ) , else: reraise ( e , __STACKTRACE__ )
518+ end
519+ end
507520 end
508521
509522 describe "absolute-form request target (RFC9112§3.2.2)" do
0 commit comments