Created
May 16, 2014 13:58
-
-
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..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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