Do not use Servlet 3.0 API in doOptions()
Refactor FrameworkServlet.doOptions() to capture the "Allow" header by using a HttpServletResponseWrapper. Prior to this commit the HttpServletResponse.getHeader() method was used which is only available in Servlet 3.0 environments. Issue: SPR-10341
This commit is contained in:
@@ -26,6 +26,7 @@ import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpServletResponseWrapper;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -866,10 +867,18 @@ public abstract class FrameworkServlet extends HttpServletBean {
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.doOptions(request, response);
|
||||
String allowedMethods = response.getHeader("Allow");
|
||||
allowedMethods += ", " + RequestMethod.PATCH.name();
|
||||
response.setHeader("Allow", allowedMethods);
|
||||
|
||||
// Use response wrapper for Servlet 2.5 compatibility where
|
||||
// the getHeader() method does not exist
|
||||
super.doOptions(request, new HttpServletResponseWrapper(response) {
|
||||
@Override
|
||||
public void setHeader(String name, String value) {
|
||||
if("Allow".equals(name)) {
|
||||
value = (StringUtils.hasLength(value) ? value + ", " : "") + RequestMethod.PATCH.name();
|
||||
}
|
||||
super.setHeader(name, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user