Skip to content

Commit 27e618c

Browse files
authored
Merge pull request #205 from avaje/feature/client-url
[http client] Expose UrlBuilder url() method on client
2 parents 4928979 + c04103f commit 27e618c

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

http-client/src/main/java/io/avaje/http/client/HttpClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ static Builder builder() {
6565
*/
6666
HttpClientRequest request();
6767

68+
/**
69+
* Return a UrlBuilder to use to build an URL taking into account the base URL.
70+
*/
71+
UrlBuilder url();
72+
6873
/**
6974
* Deprecated - migrate to {@link #bodyAdapter()}.
7075
* <p>

http-client/src/main/java/io/avaje/http/client/SpiHttpClient.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
*/
99
interface SpiHttpClient {
1010

11-
/**
12-
* Return a UrlBuilder to use to build an URL taking into
13-
* account the base URL.
14-
*/
15-
UrlBuilder url();
16-
1711
/**
1812
* Return the underlying http client.
1913
*/

http-client/src/test/java/io/avaje/http/client/DHttpClientContextTest.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.example.github.BasicClientInterface;
44
import org.junit.jupiter.api.Test;
55

6-
import java.net.http.HttpClient;
76
import java.nio.charset.StandardCharsets;
87

98
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,49 +39,49 @@ void gzip_contentDecode() {
4039
@Test
4140
void build_basic() {
4241

43-
final HttpClientContext context =
44-
HttpClientContext.builder()
42+
final HttpClient client =
43+
HttpClient.builder()
4544
.baseUrl("http://localhost")
4645
.build();
4746

48-
SpiHttpClient spi = (SpiHttpClient)context;
47+
SpiHttpClient spi = (SpiHttpClient)client;
4948
// has default client created
5049
assertThat(spi.httpClient()).isNotNull();
51-
assertThat(spi.httpClient().version()).isEqualTo(HttpClient.Version.HTTP_2);
50+
assertThat(spi.httpClient().version()).isEqualTo(java.net.http.HttpClient.Version.HTTP_2);
5251
assertThat(spi.httpClient().cookieHandler()).isPresent();
5352

5453
// has expected url building
55-
assertThat(spi.url().build()).isEqualTo("http://localhost");
56-
assertThat(spi.url().path("hello").build()).isEqualTo("http://localhost/hello");
57-
assertThat(spi.url().queryParam("hello","there").build()).isEqualTo("http://localhost?hello=there");
54+
assertThat(client.url().build()).isEqualTo("http://localhost");
55+
assertThat(client.url().path("hello").build()).isEqualTo("http://localhost/hello");
56+
assertThat(client.url().queryParam("hello","there").build()).isEqualTo("http://localhost?hello=there");
5857
}
5958

6059
@Test
6160
void build_noCookieHandler() {
6261

63-
final HttpClientContext context =
64-
HttpClientContext.builder()
62+
final HttpClient client =
63+
HttpClient.builder()
6564
.baseUrl("http://localhost")
6665
.cookieHandler(null)
67-
.redirect(HttpClient.Redirect.ALWAYS)
66+
.redirect(java.net.http.HttpClient.Redirect.ALWAYS)
6867
.build();
6968

70-
SpiHttpClient spi = (SpiHttpClient)context;
69+
SpiHttpClient spi = (SpiHttpClient)client;
7170
// has default client created
7271
assertThat(spi.httpClient()).isNotNull();
73-
assertThat(spi.httpClient().version()).isEqualTo(HttpClient.Version.HTTP_2);
72+
assertThat(spi.httpClient().version()).isEqualTo(java.net.http.HttpClient.Version.HTTP_2);
7473
assertThat(spi.httpClient().cookieHandler()).isEmpty();
7574

7675
// has expected url building
77-
assertThat(spi.url().build()).isEqualTo("http://localhost");
78-
assertThat(spi.url().path("hello").build()).isEqualTo("http://localhost/hello");
79-
assertThat(spi.url().queryParam("hello","there").build()).isEqualTo("http://localhost?hello=there");
76+
assertThat(client.url().build()).isEqualTo("http://localhost");
77+
assertThat(client.url().path("hello").build()).isEqualTo("http://localhost/hello");
78+
assertThat(client.url().queryParam("hello","there").build()).isEqualTo("http://localhost?hello=there");
8079
}
8180

8281
@Test
8382
void build_missingBaseUrl() {
8483
try {
85-
HttpClientContext.builder().build();
84+
HttpClient.builder().build();
8685
} catch (NullPointerException e) {
8786
assertThat(e.getMessage()).contains("baseUrl is not specified");
8887
}

0 commit comments

Comments
 (0)