@@ -548,7 +548,7 @@ defmodule Mint.HTTP1Test do
548
548
request_string ( """
549
549
GET / HTTP/1.1
550
550
host: localhost:#{ port }
551
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
551
+ user-agent: #{ mint_user_agent ( ) }
552
552
553
553
\
554
554
""" )
@@ -570,7 +570,7 @@ defmodule Mint.HTTP1Test do
570
570
request_string ( """
571
571
GET / HTTP/1.1
572
572
host: localhost
573
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
573
+ user-agent: #{ mint_user_agent ( ) }
574
574
575
575
\
576
576
""" )
@@ -591,7 +591,7 @@ defmodule Mint.HTTP1Test do
591
591
GET / HTTP/1.1
592
592
content-length: 4
593
593
host: localhost:#{ port }
594
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
594
+ user-agent: #{ mint_user_agent ( ) }
595
595
596
596
body\
597
597
""" )
@@ -607,7 +607,7 @@ defmodule Mint.HTTP1Test do
607
607
request_string ( """
608
608
GET / HTTP/1.1
609
609
host: localhost:#{ port }
610
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
610
+ user-agent: #{ mint_user_agent ( ) }
611
611
612
612
\
613
613
""" )
@@ -626,7 +626,7 @@ defmodule Mint.HTTP1Test do
626
626
request_string ( """
627
627
GET / HTTP/1.1
628
628
host: localhost:#{ port }
629
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
629
+ user-agent: #{ mint_user_agent ( ) }
630
630
content-length: 10
631
631
632
632
body\
@@ -760,6 +760,42 @@ defmodule Mint.HTTP1Test do
760
760
761
761
""" )
762
762
end
763
+
764
+ @ invalid_request_targets [ "/ /" , "/%foo" , "/foo%x" ]
765
+ test "targets are validated by default" , % { port: port , server_ref: server_ref } do
766
+ assert { :ok , conn } = HTTP1 . connect ( :http , "localhost" , port )
767
+
768
+ assert_receive { ^ server_ref , _server_socket }
769
+
770
+ for invalid_target <- @ invalid_request_targets do
771
+ assert { :error , % Mint.HTTP1 { } ,
772
+ % Mint.HTTPError { reason: { :invalid_request_target , ^ invalid_target } } } =
773
+ HTTP1 . request ( conn , "GET" , invalid_target , [ ] , "" )
774
+ end
775
+ end
776
+
777
+ test "target validation may be skipped based on connection options" , % {
778
+ port: port ,
779
+ server_ref: server_ref
780
+ } do
781
+ assert { :ok , conn } = HTTP1 . connect ( :http , "localhost" , port , skip_target_validation: true )
782
+
783
+ assert_receive { ^ server_ref , server_socket }
784
+
785
+ for invalid_target <- @ invalid_request_targets do
786
+ assert { :ok , _conn , _ref } = HTTP1 . request ( conn , "GET" , invalid_target , [ ] , "body" )
787
+
788
+ assert receive_request_string ( server_socket ) ==
789
+ request_string ( """
790
+ GET #{ invalid_target } HTTP/1.1
791
+ content-length: 4
792
+ host: localhost:#{ port }
793
+ user-agent: #{ mint_user_agent ( ) }
794
+
795
+ body\
796
+ """ )
797
+ end
798
+ end
763
799
end
764
800
765
801
describe "streaming requests" do
@@ -772,7 +808,7 @@ defmodule Mint.HTTP1Test do
772
808
GET / HTTP/1.1
773
809
transfer-encoding: chunked
774
810
host: localhost:#{ port }
775
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
811
+ user-agent: #{ mint_user_agent ( ) }
776
812
777
813
\
778
814
""" )
@@ -795,7 +831,7 @@ defmodule Mint.HTTP1Test do
795
831
request_string ( """
796
832
GET / HTTP/1.1
797
833
host: localhost:#{ port }
798
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
834
+ user-agent: #{ mint_user_agent ( ) }
799
835
transfer-encoding: chunked
800
836
801
837
\
@@ -815,7 +851,7 @@ defmodule Mint.HTTP1Test do
815
851
request_string ( """
816
852
GET / HTTP/1.1
817
853
host: localhost:#{ port }
818
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
854
+ user-agent: #{ mint_user_agent ( ) }
819
855
transfer-encoding: gzip,chunked
820
856
821
857
\
@@ -839,7 +875,7 @@ defmodule Mint.HTTP1Test do
839
875
request_string ( """
840
876
GET / HTTP/1.1
841
877
host: localhost:#{ port }
842
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
878
+ user-agent: #{ mint_user_agent ( ) }
843
879
transfer-encoding: identity
844
880
845
881
\
@@ -859,7 +895,7 @@ defmodule Mint.HTTP1Test do
859
895
request_string ( """
860
896
GET / HTTP/1.1
861
897
host: localhost:#{ port }
862
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
898
+ user-agent: #{ mint_user_agent ( ) }
863
899
content-length: 5
864
900
865
901
\
@@ -877,7 +913,7 @@ defmodule Mint.HTTP1Test do
877
913
GET / HTTP/1.1
878
914
transfer-encoding: chunked
879
915
host: localhost:#{ port }
880
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
916
+ user-agent: #{ mint_user_agent ( ) }
881
917
882
918
\
883
919
""" )
@@ -897,7 +933,7 @@ defmodule Mint.HTTP1Test do
897
933
POST / HTTP/1.1
898
934
transfer-encoding: chunked
899
935
host: localhost:#{ port }
900
- user-agent: mint/ #{ Mix.Project . config ( ) [ :version ] }
936
+ user-agent: #{ mint_user_agent ( ) }
901
937
902
938
\
903
939
""" )
@@ -997,4 +1033,7 @@ defmodule Mint.HTTP1Test do
997
1033
defp stream_message_bytewise ( << >> , conn , responses ) do
998
1034
{ :ok , conn , responses }
999
1035
end
1036
+
1037
+ @ mint_user_agent "mint/#{ Mix.Project . config ( ) [ :version ] } "
1038
+ defp mint_user_agent , do: @ mint_user_agent
1000
1039
end
0 commit comments