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

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

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

01public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throwsIOException, ServletException {
02         
03        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
04        logger.debug("========== isHttpHead(httpServletRequest) : {}", isHttpHead(httpServletRequest));
05        if (isHttpHead(httpServletRequest)) {
06            chain.doFilter(new ForceGetRequestWrapper(httpServletRequest), response);
07        else {
08            chain.doFilter(new FilteredRequest(request), response);
09        }
10    }
11     
12    private boolean isHttpHead(HttpServletRequest request) {
13        return "HEAD".equals(request.getMethod());
14    }
15 
16    private class ForceGetRequestWrapper extends HttpServletRequestWrapper {
17        public ForceGetRequestWrapper(HttpServletRequest request) {
18            super(request);
19        }
20 
21        public String getMethod() {
22            return "GET";
23        }
24    }
25     
26    public void destroy() {
27    }
28}

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

Posted by 양형

댓글을 달아 주세요