Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 726418a

Browse files
author
emiguez
committed
feat: allow HEAD http method for healthcheck
refactor: improve readibility of healthcheck function code test: add test for HEAD healthcheck on disabled whitelist closes #39
1 parent c49d555 commit 726418a

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ file. This file is structured according to http://keepachangelog.com/
55
Use `date "+%Y-%m-%d"` to get the correct date formatting
66

77
- - -
8+
## [Unreleased][unreleased]
9+
### - Added
10+
- allow HEAD root url authentication #39
11+
812
## [1.5.0][2015年07月04日]
913

1014
### - Added

‎src/main/java/com/asquera/elasticsearch/plugins/http/HttpBasicServer.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.io.IOException;
2323
import java.net.InetAddress;
24+
import java.util.Arrays;
2425
import java.net.InetSocketAddress;
2526

2627
import static org.elasticsearch.rest.RestStatus.OK;
@@ -91,9 +92,17 @@ public void internalDispatchRequest(final HttpRequest request, final HttpChannel
9192
}
9293
}
9394

95+
// @param an http method
96+
// @returns True iff the method is one of the methods used for health check
97+
private boolean isHealthCheckMethod(final RestRequest.Method method){
98+
final RestRequest.Method[] healthCheckMethods = { RestRequest.Method.GET, RestRequest.Method.HEAD };
99+
return Arrays.asList(healthCheckMethods).contains(method);
100+
}
101+
102+
// @param an http Request
103+
// @returns True iff we check the root path and is a method allowed for healthCheck
94104
private boolean healthCheck(final HttpRequest request) {
95-
String path = request.path();
96-
return (request.method() == RestRequest.Method.GET) && path.equals("/");
105+
return request.path().equals("/") && isHealthCheckMethod(request.method());
97106
}
98107

99108
/**

‎src/test/java/com/asquera/elasticsearch/plugins/http/auth/integration/DisabledWhitelistIntegrationTest.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
2525
import org.elasticsearch.test.rest.client.http.HttpRequestBuilder;
2626
import org.elasticsearch.test.rest.client.http.HttpResponse;
27+
import org.apache.http.client.methods.HttpHead;
2728
import org.junit.Test;
2829

2930
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
@@ -49,6 +50,19 @@ public void clientIpAuthenticationFails() throws Exception {
4950
assertThat(response.getStatusCode(), equalTo(RestStatus.UNAUTHORIZED.getStatus()));
5051
}
5152

53+
@Test
54+
// GET by default
55+
public void testHealthCheck() throws Exception {
56+
HttpResponse response = httpClient().path("/").execute();
57+
assertThat(response.getStatusCode(), equalTo(RestStatus.OK.getStatus()));
58+
}
59+
60+
@Test
61+
public void testHealthCheckHeadMethod() throws Exception {
62+
HttpResponse response = httpClient().method(HttpHead.METHOD_NAME).path("/").execute();
63+
assertThat(response.getStatusCode(), equalTo(RestStatus.OK.getStatus()));
64+
}
65+
5266
@Test
5367
public void clientGoodCredentialsBasicAuthenticationSuceeds() throws Exception {
5468
HttpResponse response = requestWithCredentials("admin:admin_pw")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /