Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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;
@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