Skip to content

Commit

Permalink
Add missing URL params in HTTP client (#1754)
Browse files Browse the repository at this point in the history
add missing URL params
  • Loading branch information
tylerwowen authored Nov 19, 2024
1 parent 09298a8 commit 20e9732
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,25 @@ private static OkHttpObservationInterceptor.Builder observationInterceptorBuilde

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));
}

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

0 comments on commit 20e9732

Please sign in to comment.