Chenjp commented on PR #801: URL: https://github.com/apache/tomcat/pull/801#issuecomment-2536373887
@rmaucher isPreconditionsAwareMethod, a new api proposal, as below: ```java /** * Determines whether a request method is preconditions aware, that is, returns <code>true</code> if the request * method involves the selection or modification of a selected representation. Otherwise, returns <code>false</code> * if a request method that does not involve, such as CONNECT, OPTIONS, or TRACE. * <p> * This method should be overridden when a web application uses a custom HTTP method to serve, meanwhile that method * involves selection or modification of a selected representation. <blockquote> * * <pre> * @override * protected boolean isPreconditionsAwareMethod(String method) { * if (super.isPreconditionsAwareMethod(method)) { * return true; * } else if ("ABC".equals(method) || "XYZ".equals(method)) { * return true; * } else { * return false; * } * } * </pre> * * </blockquote> * <p> * Additionally, for those "PreconditionsAware" HTTP method, a server need call * {@link #checkIfHeaders(HttpServletRequest, HttpServletResponse, WebResource)} after 3xx and 4xx detection and * prior to performing the method. <blockquote> * * <pre> * protected void doXyz(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { * * String path = getRelativePath(req); * * WebResource resource = resources.getResource(path); * * performNormalRequestChecks ... //normal request checks * * if (resource != null && !checkIfHeaders(req, resp, resource)) { * return; * } * * ... // process the request content (if any) * ... // perform the action associated with the request method * } * </pre> * * </blockquote> * <p> * <strong>Important:</strong> A subclass is recommended to override this method if customize a new HTTP method. * * @param method The request method. * * @return <code>true</code> if the request method involves the selection or modification of a selected * representation. * * @see #checkIfHeaders(HttpServletRequest, HttpServletResponse, WebResource) */ protected boolean isPreconditionsAwareMethod(String method) { if ("DELETE".equals(method) || "HEAD".equals(method) || "GET".equals(method) || "PATCH".equals(method) || "POST".equals(method) || "PUT".equals(method)) { return true; } else { return false; } } /** * Check if the conditions specified in the optional If headers are satisfied. * @@ -726,6 +799,9 @@ public class DefaultServlet extends HttpServlet { */ protected boolean checkIfHeaders(HttpServletRequest request, HttpServletResponse response, WebResource resource) throws IOException { if (!isPreconditionsAwareMethod(request.getMethod())) { return true; } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org