반응형

Request method 'HEAD' not supported 오류에 대한 대처 방법.

프로젝트 막바지에 위와 같은 오류에 직면 했다..ㅜ 첨 보는 오류..

그동안 너무 쉬엄쉬엄 했나..기본이 부족..

HTTP method GET, POST 이외에...PUT, DELETE...등 그 중 HEAD....

원리는 간단하다. web.xml 전 단계에서 doFilter 를 이용해 우회 처리를..

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        logger.debug("========== isHttpHead(httpServletRequest) : {}", isHttpHead(httpServletRequest));
        if (isHttpHead(httpServletRequest)) {
            chain.doFilter(new ForceGetRequestWrapper(httpServletRequest), response);
        } else {
            chain.doFilter(new FilteredRequest(request), response);
        }
    }

    private boolean isHttpHead(HttpServletRequest request) {
        return "HEAD".equals(request.getMethod());
    }

    private class ForceGetRequestWrapper extends HttpServletRequestWrapper {
        public ForceGetRequestWrapper(HttpServletRequest request) {
            super(request);
        }

        public String getMethod() {
            return "GET";
        }
    }

    public void destroy() {
    }
}

doFilter에 분기문을 추가하여 HEAD 요청시 GET으로 Method 를 변경한다.

http://axelfontaine.com/blog/http-head.html http://forum.spring.io/forum/spring-projects/web/89981-request-method-head-not-supported

 

Legacy forums will be shutdown February 28

In 2014, we announced the retirement of our legacy forum, forum.spring.io, in favor of providing an improved community experience on stackoverflow.com. As part of that announcement, we put our forum into read-only mode, preserving forum posts that were ref

spring.io

 

반응형

+ Recent posts