rename ElasticsearchResponse#getFirstHeader to getHeader

This commit is contained in:
javanna 2016-06-03 18:28:31 +02:00 committed by Luca Cavanna
parent 29eee328fe
commit f17f0f9247
7 changed files with 19 additions and 19 deletions

View File

@ -83,7 +83,7 @@ public class ElasticsearchResponse implements Closeable {
* If there is more than one matching header in the message the first element is returned.
* If there is no matching header in the message <code>null</code> is returned.
*/
public String getFirstHeader(String name) {
public String getHeader(String name) {
Header header = response.getFirstHeader(name);
if (header == null) {
return null;

View File

@ -53,7 +53,7 @@ public class DetailedErrorsDisabledIT extends ESIntegTestCase {
fail("request should have failed");
} catch(ElasticsearchResponseException e) {
ElasticsearchResponse response = e.getElasticsearchResponse();
assertThat(response.getFirstHeader("Content-Type"), is("application/json"));
assertThat(response.getHeader("Content-Type"), is("application/json"));
assertThat(e.getResponseBody(), is("{\"error\":\"error traces in responses are disabled.\"}"));
assertThat(response.getStatusLine().getStatusCode(), is(400));
}

View File

@ -51,7 +51,7 @@ public class DetailedErrorsEnabledIT extends ESIntegTestCase {
fail("request should have failed");
} catch(ElasticsearchResponseException e) {
ElasticsearchResponse response = e.getElasticsearchResponse();
assertThat(response.getFirstHeader("Content-Type"), containsString("application/json"));
assertThat(response.getHeader("Content-Type"), containsString("application/json"));
assertThat(e.getResponseBody(), containsString("\"stack_trace\":\"[Validation Failed: 1: index / indices is missing;]; " +
"nested: ActionRequestValidationException[Validation Failed: 1:"));
}
@ -61,7 +61,7 @@ public class DetailedErrorsEnabledIT extends ESIntegTestCase {
fail("request should have failed");
} catch(ElasticsearchResponseException e) {
ElasticsearchResponse response = e.getElasticsearchResponse();
assertThat(response.getFirstHeader("Content-Type"), containsString("application/json"));
assertThat(response.getHeader("Content-Type"), containsString("application/json"));
assertThat(e.getResponseBody(), not(containsString("\"stack_trace\":\"[Validation Failed: 1: index / indices is missing;]; "
+ "nested: ActionRequestValidationException[Validation Failed: 1:")));
}

View File

@ -61,13 +61,13 @@ public class ResponseHeaderPluginIT extends ESIntegTestCase {
} catch(ElasticsearchResponseException e) {
ElasticsearchResponse response = e.getElasticsearchResponse();
assertThat(response, hasStatus(UNAUTHORIZED));
assertThat(response.getFirstHeader("Secret"), equalTo("required"));
assertThat(response.getHeader("Secret"), equalTo("required"));
}
try (ElasticsearchResponse authResponse = getRestClient().performRequest("GET", "/_protected", Collections.emptyMap(), null,
new BasicHeader("Secret", "password"))) {
assertThat(authResponse, hasStatus(OK));
assertThat(authResponse.getFirstHeader("Secret"), equalTo("granted"));
assertThat(authResponse.getHeader("Secret"), equalTo("granted"));
}
}
}

View File

@ -49,16 +49,16 @@ public class CorsNotSetIT extends ESIntegTestCase {
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue))) {
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getFirstHeader("Access-Control-Allow-Credentials"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Credentials"), nullValue());
}
}
public void testThatOmittingCorsHeaderDoesNotReturnAnything() throws Exception {
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getFirstHeader("Access-Control-Allow-Credentials"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Credentials"), nullValue());
}
}
}

View File

@ -69,7 +69,7 @@ public class CorsRegexIT extends ESIntegTestCase {
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue));) {
assertResponseWithOriginheader(response, corsValue);
assertThat(response.getFirstHeader("Access-Control-Allow-Credentials"), is("true"));
assertThat(response.getHeader("Access-Control-Allow-Credentials"), is("true"));
}
}
@ -82,7 +82,7 @@ public class CorsRegexIT extends ESIntegTestCase {
ElasticsearchResponse response = e.getElasticsearchResponse();
// a rejected origin gets a FORBIDDEN - 403
assertThat(response.getStatusLine().getStatusCode(), is(403));
assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
}
}
@ -90,14 +90,14 @@ public class CorsRegexIT extends ESIntegTestCase {
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
new BasicHeader("User-Agent", "Mozilla Bar"))) {
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
}
}
public void testThatRegularExpressionIsNotAppliedWithoutCorrectBrowserOnMatch() throws Exception {
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
}
}
@ -107,7 +107,7 @@ public class CorsRegexIT extends ESIntegTestCase {
new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue),
new BasicHeader(HttpHeaders.Names.ACCESS_CONTROL_REQUEST_METHOD, "GET"));) {
assertResponseWithOriginheader(response, corsValue);
assertNotNull(response.getFirstHeader("Access-Control-Allow-Methods"));
assertNotNull(response.getHeader("Access-Control-Allow-Methods"));
}
}
@ -121,13 +121,13 @@ public class CorsRegexIT extends ESIntegTestCase {
ElasticsearchResponse response = e.getElasticsearchResponse();
// a rejected origin gets a FORBIDDEN - 403
assertThat(response.getStatusLine().getStatusCode(), is(403));
assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getFirstHeader("Access-Control-Allow-Methods"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Methods"), nullValue());
}
}
protected static void assertResponseWithOriginheader(ElasticsearchResponse response, String expectedCorsHeader) {
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), is(expectedCorsHeader));
assertThat(response.getHeader("Access-Control-Allow-Origin"), is(expectedCorsHeader));
}
}

View File

@ -125,7 +125,7 @@ public class RestTestResponse {
}
private boolean isJson() {
String contentType = response.getFirstHeader("Content-Type");
String contentType = response.getHeader("Content-Type");
return contentType != null && contentType.contains("application/json");
}