Search in sources :

Example 1 with FailReason

use of org.apache.tomcat.util.http.Parameters.FailReason in project tomcat by apache.

the class FailedRequestFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (!isGoodRequest(request)) {
        FailReason reason = (FailReason) request.getAttribute(Globals.PARAMETER_PARSE_FAILED_REASON_ATTR);
        int status;
        switch(reason) {
            case IO_ERROR:
                // Not the client's fault
                status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                break;
            case POST_TOO_LARGE:
                status = HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE;
                break;
            case TOO_MANY_PARAMETERS:
            // Assume the client is at fault
            case UNKNOWN:
            // a specific status code so use the default.
            case INVALID_CONTENT_TYPE:
            case MULTIPART_CONFIG_INVALID:
            case NO_NAME:
            case REQUEST_BODY_INCOMPLETE:
            case URL_DECODING:
            case CLIENT_DISCONNECT:
            // for the access logs. The default is fine.
            default:
                // 400
                status = HttpServletResponse.SC_BAD_REQUEST;
                break;
        }
        ((HttpServletResponse) response).sendError(status);
        return;
    }
    chain.doFilter(request, response);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) FailReason(org.apache.tomcat.util.http.Parameters.FailReason)

Aggregations

HttpServletResponse (javax.servlet.http.HttpServletResponse)1 FailReason (org.apache.tomcat.util.http.Parameters.FailReason)1