Skip to content

Instantly share code, notes, and snippets.

@gabrielbauman
Created May 16, 2014 13:58
Show Gist options
  • Save gabrielbauman/5e1c4d017e3ced09d4d3 to your computer and use it in GitHub Desktop.
Save gabrielbauman/5e1c4d017e3ced09d4d3 to your computer and use it in GitHub Desktop.
Openshift's haproxy hits '/' every 2 seconds with a null user agent to see if your scalable app is up. If "/" does not respond with a 200 OK, haproxy marks the server as down even if it's actually up. This filter generates an empty 200 OK when it detects a haproxy ping..
package com.gabrielbauman.gists;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebFilter(urlPatterns = "/")
public class OpenshiftHaproxyFilter implements Filter {
public void init(FilterConfig config) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
if (null == ((HttpServletRequest) request).getHeader("user-agent")) {
((HttpServletResponse) response).setStatus(HttpServletResponse.SC_OK);
} else {
chain.doFilter(request, response);
}
}
public void destroy() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment