File tree Expand file tree Collapse file tree 2 files changed +48
-5
lines changed
main/java/com/intuit/karate/http
test/java/com/intuit/karate/http Expand file tree Collapse file tree 2 files changed +48
-5
lines changed Original file line number Diff line number Diff line change @@ -259,23 +259,24 @@ public HttpRequestBuilder path(String path) {
259259 return this ;
260260 }
261261
262- private String getUri () {
262+ public String getUri () {
263263 try {
264264 URIBuilder builder ;
265265 if (url == null ) {
266266 builder = new URIBuilder ();
267267 } else {
268- if (url .endsWith ("/" )) {
269- url = url .substring (0 , url .length () - 1 );
270- }
271268 builder = new URIBuilder (url );
272269 }
273270 if (params != null ) {
274271 params .forEach ((key , values ) -> values .forEach (value -> builder .addParameter (key , value )));
275272 }
276273 if (paths != null ) {
277274 List <String > segments = new ArrayList ();
278- segments .addAll (builder .getPathSegments ());
275+ for (String item : builder .getPathSegments ()) {
276+ if (!item .isEmpty ()) {
277+ segments .add (item );
278+ }
279+ }
279280 for (String item : paths ) {
280281 for (String s : StringUtils .split (item , '/' , true )) {
281282 segments .add (s );
Original file line number Diff line number Diff line change 1+ package com .intuit .karate .http ;
2+
3+ import com .intuit .karate .core .ScenarioEngine ;
4+ import static org .junit .jupiter .api .Assertions .*;
5+ import org .junit .jupiter .api .BeforeEach ;
6+ import org .junit .jupiter .api .Test ;
7+ import org .slf4j .Logger ;
8+ import org .slf4j .LoggerFactory ;
9+
10+ /**
11+ *
12+ * @author pthomas3
13+ */
14+ class HttpRequestBuilderTest {
15+
16+ static final Logger logger = LoggerFactory .getLogger (HttpRequestBuilderTest .class );
17+
18+ HttpRequestBuilder http ;
19+
20+ @ BeforeEach
21+ void beforeEach () {
22+ ScenarioEngine se = ScenarioEngine .forTempUse ();
23+ http = new HttpRequestBuilder (HttpClientFactory .DEFAULT .create (se ));
24+ }
25+
26+ @ Test
27+ void testUrlAndPath () {
28+ http .url ("http://host/foo" );
29+ assertEquals ("http://host/foo" , http .getUri ());
30+ http .path ("/bar" );
31+ assertEquals ("http://host/foo/bar" , http .getUri ());
32+ }
33+
34+ @ Test
35+ void testUrlAndPathWithSlash () {
36+ http .url ("http://host/foo/" );
37+ assertEquals ("http://host/foo/" , http .getUri ());
38+ http .path ("/bar/" );
39+ assertEquals ("http://host/foo/bar" , http .getUri ());
40+ }
41+
42+ }
You can’t perform that action at this time.
0 commit comments