mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-11 10:04:08 +00:00
Merge pull request #80 from overleaf/sk-health-check-trailing-slash
Handle HEAD method, and trailing slash on status and health-check calls
This commit is contained in:
commit
395c558d77
3 changed files with 62 additions and 4 deletions
|
@ -28,8 +28,13 @@ public class HealthCheckHandler extends AbstractHandler {
|
|||
HttpServletRequest request,
|
||||
HttpServletResponse response
|
||||
) throws IOException {
|
||||
if ("GET".equals(baseRequest.getMethod()) && "/health_check".equals(target)) {
|
||||
Log.info("GET <- /health_check");
|
||||
String method = baseRequest.getMethod();
|
||||
if (
|
||||
("GET".equals(method) || "HEAD".equals(method))
|
||||
&& target != null
|
||||
&& target.matches("^/health_check/?$")
|
||||
) {
|
||||
Log.info(method + " <- /health_check");
|
||||
baseRequest.setHandled(true);
|
||||
response.setContentType("text/plain");
|
||||
if (bridge.healthCheck()) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class StatusHandler extends AbstractHandler {
|
||||
|
||||
|
@ -28,8 +29,13 @@ public class StatusHandler extends AbstractHandler {
|
|||
HttpServletRequest request,
|
||||
HttpServletResponse response
|
||||
) throws IOException {
|
||||
if ("GET".equals(baseRequest.getMethod()) && "/status".equals(target)) {
|
||||
Log.info("GET <- /status");
|
||||
String method = baseRequest.getMethod();
|
||||
if (
|
||||
("GET".equals(method) || "HEAD".equals(method))
|
||||
&& target != null
|
||||
&& target.matches("^/status/?$")
|
||||
) {
|
||||
Log.info(method + " <- /status");
|
||||
baseRequest.setHandled(true);
|
||||
response.setContentType("text/plain");
|
||||
response.setStatus(200);
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.apache.http.client.ClientProtocolException;
|
|||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.asynchttpclient.*;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
|
@ -921,6 +922,52 @@ public class WLGitBridgeIntegrationTest {
|
|||
assertEquals(200, healthCheckResponse.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatusAndHealthCheckEndpointsWithTrailingSlash() throws ClientProtocolException, IOException {
|
||||
int gitBridgePort = 33888;
|
||||
int mockServerPort = 3888;
|
||||
server = new MockSnapshotServer(mockServerPort, getResource("/canCloneARepository").toFile());
|
||||
server.start();
|
||||
server.setState(states.get("canCloneARepository").get("state"));
|
||||
wlgb = new GitBridgeApp(new String[] {
|
||||
makeConfigFile(gitBridgePort, mockServerPort)
|
||||
});
|
||||
wlgb.run();
|
||||
HttpClient client = HttpClients.createDefault();
|
||||
String urlBase = "http://127.0.0.1:" + gitBridgePort;
|
||||
// Status
|
||||
HttpGet statusRequest = new HttpGet(urlBase+"/status/");
|
||||
HttpResponse statusResponse = client.execute(statusRequest);
|
||||
assertEquals(200, statusResponse.getStatusLine().getStatusCode());
|
||||
// Health Check
|
||||
HttpGet healthCheckRequest = new HttpGet(urlBase+"/health_check/");
|
||||
HttpResponse healthCheckResponse = client.execute(healthCheckRequest);
|
||||
assertEquals(200, healthCheckResponse.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatusAndHealthCheckEndpointsWithHead() throws ClientProtocolException, IOException {
|
||||
int gitBridgePort = 33889;
|
||||
int mockServerPort = 3889;
|
||||
server = new MockSnapshotServer(mockServerPort, getResource("/canCloneARepository").toFile());
|
||||
server.start();
|
||||
server.setState(states.get("canCloneARepository").get("state"));
|
||||
wlgb = new GitBridgeApp(new String[] {
|
||||
makeConfigFile(gitBridgePort, mockServerPort)
|
||||
});
|
||||
wlgb.run();
|
||||
HttpClient client = HttpClients.createDefault();
|
||||
String urlBase = "http://127.0.0.1:" + gitBridgePort;
|
||||
// Status
|
||||
HttpHead statusRequest = new HttpHead(urlBase+"/status");
|
||||
HttpResponse statusResponse = client.execute(statusRequest);
|
||||
assertEquals(200, statusResponse.getStatusLine().getStatusCode());
|
||||
// Health Check
|
||||
HttpHead healthCheckRequest = new HttpHead(urlBase+"/health_check");
|
||||
HttpResponse healthCheckResponse = client.execute(healthCheckRequest);
|
||||
assertEquals(200, healthCheckResponse.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
private String makeConfigFile(
|
||||
int port,
|
||||
int apiPort
|
||||
|
|
Loading…
Add table
Reference in a new issue