http input: The http input should only url encode once

Java's URI class already does url encoding, so we don't need to do this on out side.

Closes elastic/elasticsearch#699

Original commit: elastic/x-pack-elasticsearch@612dc99945
This commit is contained in:
Martijn van Groningen 2015-09-23 14:20:04 +02:00
parent 0d1602255b
commit 1ce6f9ddba
4 changed files with 21 additions and 5 deletions

View File

@ -128,7 +128,7 @@ holds an object where the keys serve as the header names and the values serve as
| `request.scheme` | no | http | The connection scheme. Valid values are: `http` or `https`.
| `request.host` | yes | - | The host to connect to.
| `request.port` | yes | - | The port the HTTP service is listening on.
| `request.path` | no | - | The URL path. The path can be static text or include Mustache <<templates, templates>>.
| `request.path` | no | - | The URL path. The path can be static text or include Mustache <<templates, templates>>. URL query string parameters must be specified via the `request.params` attribute.
| `request.method` | no | get | The HTTP method. Valid values are: `head`, `get`, `post`, `put` and `delete`.
| `request.headers` | no | - | The HTTP request headers. The header values can be static text or include Mustache <<templates, templates>>.
| `request.params` | no | - | The URL query string parameters. The parameter values can be static text or include Mustache <<templates, templates>>.

View File

@ -30,7 +30,7 @@ NOTE: If the body of the response from the HTTP endpoint is in the JSON or YAM
| `request.scheme` | no | http | Url scheme. Valid values are: `http` or `https`.
| `request.host` | yes | - | The host to connect to.
| `request.port` | yes | - | The port the http service is listening on.
| `request.path` | no | - | The URL path. The path can be static text or contain `mustache` <<templates, templates>>.
| `request.path` | no | - | The URL path. The path can be static text or contain `mustache` <<templates, templates>>. URL query string parameters must be specified via the `request.params` attribute.
| `request.method` | no | get | The HTTP method. Supported values are: `head`, `get`, `post`, `put` and `delete`.
| `request.headers` | no | - | The HTTP request headers. The header values can be static text or include `mustache` <<templates, templates>>.
| `request.params` | no | - | The URL query string parameters. The parameter values can be static text or contain `mustache` <<templates, templates>>.

View File

@ -107,9 +107,9 @@ public class HttpClient extends AbstractLifecycleComponent<HttpClient> {
if (builder.length() != 0) {
builder.append('&');
}
builder.append(URLEncoder.encode(entry.getKey(), "utf-8"))
builder.append(entry.getKey())
.append('=')
.append(URLEncoder.encode(entry.getValue(), "utf-8"));
.append(entry.getValue());
}
queryString = builder.toString();
}

View File

@ -74,7 +74,6 @@ public class HttpClientTests extends ESTestCase {
}
@Test
public void testBasics() throws Exception {
int responseCode = randomIntBetween(200, 203);
String body = randomAsciiOfLengthBetween(2, 8096);
@ -127,6 +126,23 @@ public class HttpClientTests extends ESTestCase {
assertThat(recordedRequest.getBody().readUtf8Line(), nullValue());
}
@Test
public void testUrlEncoding() throws Exception{
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
HttpRequest.Builder requestBuilder = HttpRequest.builder("localhost", webPort)
.method(HttpMethod.GET)
.path("/test")
.setParam("key", "value 123:123");
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?key=value%20123:123"));
assertThat(recordedRequest.getBody().readUtf8Line(), nullValue());
}
@Test
public void testBasicAuth() throws Exception {
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));