Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing URL params in HTTP client #1754

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,25 @@

public String get(String url, Map<String, String> params, Map<String, String> headers)
throws IOException {
return makeCall(createRequestBuilder(url, headers).build());
return makeCall(createRequestBuilder(url, params, headers).build());
}

public String post(String url, String body, Map<String, String> headers) throws IOException {
return makeCall(createRequestBuilder(url, headers).post(buildJsonBody(body)).build());
return makeCall(createRequestBuilder(url, null, headers).post(buildJsonBody(body)).build());
}

public String put(String url, String body, Map<String, String> headers) throws IOException {
return makeCall(createRequestBuilder(url, headers).put(buildJsonBody(body)).build());
return makeCall(createRequestBuilder(url, null, headers).put(buildJsonBody(body)).build());
}

public String delete(String url, String body, Map<String, String> headers) throws IOException {
return makeCall(createRequestBuilder(url, headers).delete(buildJsonBody(body)).build());
return makeCall(
createRequestBuilder(url, null, headers).delete(buildJsonBody(body)).build());
}

private Request.Builder createRequestBuilder(String url, Map<String, String> headers) {
return new Request.Builder().url(buildUrl(url, null)).headers(buildHeaders(headers));
private Request.Builder createRequestBuilder(
String url, Map<String, String> params, Map<String, String> headers) {
return new Request.Builder().url(buildUrl(url, params)).headers(buildHeaders(headers));
Dismissed Show dismissed Hide dismissed
}

public Headers buildHeaders(Map<String, String> rawHeaders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,16 @@ void testBuildJsonBodyNull() throws IOException {
void testGetSuccess() throws IOException, InterruptedException {
mockWebServer.enqueue(new MockResponse().setBody(TEST_BODY));

String result = sut.get(mockWebServer.url(TEST_PATH).toString(), null, TEST_HEADERS);
String result = sut.get(mockWebServer.url(TEST_PATH).toString(), TEST_PARAMS, TEST_HEADERS);
assertEquals(TEST_BODY, result);

RecordedRequest request = mockWebServer.takeRequest();
assertEquals(TEST_PATH, request.getPath());
assertEquals(TEST_PATH + "?p1=v1&p2=v2", request.getPath());
assertEquals("GET", request.getMethod());
assertEquals(TEST_HEADERS.get("h1"), request.getHeader("h1"));
assertEquals(TEST_HEADERS.get("h2"), request.getHeader("h2"));
assertEquals(TEST_PARAMS.get("p1"), request.getRequestUrl().queryParameter("p1"));
assertEquals(TEST_PARAMS.get("p2"), request.getRequestUrl().queryParameter("p2"));
}

@Test
Expand Down
Loading