http client: Don't append '?' to the url if there are no query string options defined.
Closes elastic/elasticsearch#271 Original commit: elastic/x-pack-elasticsearch@63487fad87
This commit is contained in:
parent
5bc491d359
commit
f4d0dc4955
|
@ -61,7 +61,7 @@ public class HttpClient extends AbstractComponent {
|
|||
|
||||
public HttpResponse execute(HttpRequest request) throws IOException {
|
||||
String queryString = null;
|
||||
if (request.params() != null) {
|
||||
if (request.params() != null && !request.params().isEmpty()) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : request.params().entrySet()) {
|
||||
if (builder.length() != 0) {
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -98,6 +99,22 @@ public class HttpClientTest extends ElasticsearchTestCase {
|
|||
assertThat(recordedRequest.getHeader(headerKey), equalTo(headerValue));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoQueryString() throws Exception {
|
||||
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
|
||||
HttpRequest.Builder requestBuilder = HttpRequest.builder("localhost", webPort)
|
||||
.method(HttpMethod.GET)
|
||||
.path("/test");
|
||||
|
||||
HttpResponse response = httpClient.execute(requestBuilder.build());
|
||||
assertThat(response.status(), equalTo(200));
|
||||
assertThat(response.body().toUtf8(), equalTo("body"));
|
||||
|
||||
RecordedRequest recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getPath(), equalTo("/test"));
|
||||
assertThat(recordedRequest.getBody().readUtf8Line(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicAuth() throws Exception {
|
||||
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
|
||||
|
@ -110,6 +127,7 @@ public class HttpClientTest extends ElasticsearchTestCase {
|
|||
assertThat(response.status(), equalTo(200));
|
||||
assertThat(response.body().toUtf8(), equalTo("body"));
|
||||
RecordedRequest recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getPath(), equalTo("/test"));
|
||||
assertThat(recordedRequest.getHeader("Authorization"), equalTo("Basic dXNlcjpwYXNz"));
|
||||
}
|
||||
|
||||
|
@ -132,6 +150,7 @@ public class HttpClientTest extends ElasticsearchTestCase {
|
|||
assertThat(response.status(), equalTo(200));
|
||||
assertThat(response.body().toUtf8(), equalTo("body"));
|
||||
RecordedRequest recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getPath(), equalTo("/test"));
|
||||
assertThat(recordedRequest.getBody().readUtf8Line(), equalTo("body"));
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest
|
|||
|
||||
assertWatchWithMinimumPerformedActionsCount("_id", 1, false);
|
||||
RecordedRequest recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getPath(), equalTo("/test/_id?"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/test/_id"));
|
||||
assertThat(recordedRequest.getBody().readUtf8Line(), equalTo("{key=value}"));
|
||||
|
||||
SearchResponse response = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*")
|
||||
|
@ -146,7 +146,7 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest
|
|||
|
||||
assertWatchWithMinimumPerformedActionsCount("_id", 1, false);
|
||||
RecordedRequest recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getPath(), equalTo("/test/_id?"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/test/_id"));
|
||||
assertThat(recordedRequest.getBody().readUtf8Line(), equalTo("{key=value}"));
|
||||
assertThat(recordedRequest.getHeader("Authorization"), equalTo("Basic X3VzZXJuYW1lOl9wYXNzd29yZA=="));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue