Skip to content

Commit b986771

Browse files
committed
actually test client changes
1 parent 86c6e44 commit b986771

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,24 @@ public HttpClientRequest header(String name, String value) {
124124
return this;
125125
}
126126

127+
@Override
128+
public HttpClientRequest header(String name, Collection<String> value) {
129+
if (headers == null) {
130+
headers = new LinkedHashMap<>();
131+
}
132+
headers.computeIfAbsent(name, s -> new ArrayList<>()).addAll(value);
133+
return this;
134+
}
135+
127136
@Override
128137
@SuppressWarnings("unchecked")
129138
public HttpClientRequest header(String name, Object value) {
130139

131140
if (value instanceof Collection) {
132-
value = ((Collection) value).stream().map(Object::toString).collect(Collectors.joining(","));
141+
final var headerList =
142+
((Collection<Object>) value).stream().map(Object::toString).collect(Collectors.toList());
143+
144+
return header(name, headerList);
133145
}
134146

135147
return value != null ? header(name, value.toString()) : this;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.net.http.HttpResponse;
66
import java.nio.file.Path;
77
import java.time.Duration;
8+
import java.util.Collection;
89
import java.util.List;
910
import java.util.Map;
1011
import java.util.function.Supplier;
@@ -126,6 +127,15 @@ public interface HttpClientRequest {
126127
*/
127128
HttpClientRequest header(Map<String, ?> headers);
128129

130+
/**
131+
* Add the headers to the request via Collection.
132+
*
133+
* @param name The header name
134+
* @param value The header values
135+
* @return The request being built
136+
*/
137+
HttpClientRequest header(String name, Collection<String> value);
138+
129139
/**
130140
* Return the header values that have been set for the given header name.
131141
*

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package io.avaje.http.client;
22

3-
import org.junit.jupiter.api.Test;
3+
import static org.assertj.core.api.Assertions.assertThat;
44

55
import java.time.Duration;
6+
import java.util.List;
67

7-
import static org.assertj.core.api.Assertions.assertThat;
8+
import org.junit.jupiter.api.Test;
89

910
class DHttpClientRequestTest {
1011

@@ -21,6 +22,35 @@ void suppressLogging_listenerEvent_expect_suppressedPayloadContent() {
2122
assertThat(event.responseBody()).isEqualTo("<suppressed response body>");
2223
}
2324

25+
@Test
26+
void assertHeader() {
27+
final var request = new DHttpClientRequest(context, Duration.ZERO);
28+
29+
final var headers =
30+
request
31+
.header("Accept", (Object) List.of("application/json", "application/json2"))
32+
.header("Accept");
33+
34+
assertThat(headers).asList().contains("application/json", "application/json2");
35+
}
36+
37+
@Test
38+
void assertQuery() {
39+
final var client = HttpClient.builder().baseUrl("https://ap7i.github.com").build();
40+
41+
final var uri =
42+
client
43+
.request()
44+
.queryParam("param", List.of("param1", "param2"))
45+
.HEAD()
46+
.asDiscarding()
47+
.request()
48+
.uri()
49+
.toString();
50+
51+
assertThat(uri).isEqualTo("https://ap7i.github.com?param=param1&param=param2");
52+
}
53+
2454
@Test
2555
void skipAuthToken_listenerEvent_expect_suppressedPayloadContent() {
2656
final DHttpClientRequest request = new DHttpClientRequest(context, Duration.ZERO);

0 commit comments

Comments
 (0)