@@ -116,6 +116,32 @@ public void testParseRequestTarget()
116
116
assertThat (uri .getPath (), is ("/bar" ));
117
117
}
118
118
119
+ @ Test
120
+ public void testCONNECT ()
121
+ {
122
+ HttpURI uri = new HttpURI ();
123
+
124
+ uri .parseRequestTarget ("CONNECT" , "host:80" );
125
+ assertThat (uri .getHost (), is ("host" ));
126
+ assertThat (uri .getPort (), is (80 ));
127
+ assertThat (uri .getPath (), nullValue ());
128
+
129
+ uri .parseRequestTarget ("CONNECT" , "host" );
130
+ assertThat (uri .getHost (), is ("host" ));
131
+ assertThat (uri .getPort (), is (-1 ));
132
+ assertThat (uri .getPath (), nullValue ());
133
+
134
+ uri .parseRequestTarget ("CONNECT" , "192.168.0.1:8080" );
135
+ assertThat (uri .getHost (), is ("192.168.0.1" ));
136
+ assertThat (uri .getPort (), is (8080 ));
137
+ assertThat (uri .getPath (), nullValue ());
138
+
139
+ uri .parseRequestTarget ("CONNECT" , "[::1]:8080" );
140
+ assertThat (uri .getHost (), is ("[::1]" ));
141
+ assertThat (uri .getPort (), is (8080 ));
142
+ assertThat (uri .getPath (), nullValue ());
143
+ }
144
+
119
145
@ Test
120
146
public void testExtB () throws Exception
121
147
{
@@ -789,4 +815,64 @@ public void testEncodedQuery(String input, String expectedQuery)
789
815
HttpURI httpURI = new HttpURI (input );
790
816
assertThat ("[" + input + "] .query" , httpURI .getQuery (), is (expectedQuery ));
791
817
}
818
+
819
+ @ Test
820
+ public void testRelativePathWithAuthority ()
821
+ {
822
+ assertThrows (IllegalArgumentException .class , () ->
823
+ {
824
+ HttpURI httpURI = new HttpURI ();
825
+ httpURI .setAuthority ("host" , 0 );
826
+ httpURI .setPath ("path" );
827
+ });
828
+ assertThrows (IllegalArgumentException .class , () ->
829
+ {
830
+ HttpURI httpURI = new HttpURI ();
831
+ httpURI .setAuthority ("host" , 8080 );
832
+ httpURI .setPath (";p=v/url" );
833
+ });
834
+ assertThrows (IllegalArgumentException .class , () ->
835
+ {
836
+ HttpURI httpURI = new HttpURI ();
837
+ httpURI .setAuthority ("host" , 0 );
838
+ httpURI .setPath (";" );
839
+ });
840
+
841
+ assertThrows (IllegalArgumentException .class , () ->
842
+ {
843
+ HttpURI httpURI = new HttpURI ();
844
+ httpURI .setPath ("path" );
845
+ httpURI .setAuthority ("host" , 0 );
846
+ });
847
+ assertThrows (IllegalArgumentException .class , () ->
848
+ {
849
+ HttpURI httpURI = new HttpURI ();
850
+ httpURI .setPath (";p=v/url" );
851
+ httpURI .setAuthority ("host" , 8080 );
852
+ });
853
+ assertThrows (IllegalArgumentException .class , () ->
854
+ {
855
+ HttpURI httpURI = new HttpURI ();
856
+ httpURI .setPath (";" );
857
+ httpURI .setAuthority ("host" , 0 );
858
+ });
859
+
860
+ HttpURI uri = new HttpURI ();
861
+ uri .setPath ("*" );
862
+ uri .setAuthority ("host" , 0 );
863
+ assertEquals ("//host*" , uri .toString ());
864
+ uri = new HttpURI ();
865
+ uri .setAuthority ("host" , 0 );
866
+ uri .setPath ("*" );
867
+ assertEquals ("//host*" , uri .toString ());
868
+
869
+ uri = new HttpURI ();
870
+ uri .setPath ("" );
871
+ uri .setAuthority ("host" , 0 );
872
+ assertEquals ("//host" , uri .toString ());
873
+ uri = new HttpURI ();
874
+ uri .setAuthority ("host" , 0 );
875
+ uri .setPath ("" );
876
+ assertEquals ("//host" , uri .toString ());
877
+ }
792
878
}
0 commit comments