Skip to content

Commit

Permalink
Improved: Change 'restMethod' by '_method' in request parameters
Browse files Browse the repository at this point in the history
(OFBIZ-11332)

When we analyse a request method, we currently check the parameter "restMethod".
Mathieu Lirzin propose [1] to use "_method" instead to use a parameter name more generic

I create a new function UtilHttp.getRequestMethod() to centralize the request method resolution.

[1] https://issues.apache.org/jira/browse/OFBIZ-11007?focusedCommentId=17012712&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17012712
  • Loading branch information
nmalin committed Jan 29, 2020
1 parent fac12a4 commit 11cf350
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,17 @@ public static String getFullRequestUrl(HttpServletRequest request) {
return requestUrl.toString();
}

/** Resolve the method send with the request.
* check first the parameter _method before return the request method
* @param request
* @return
*/
public static String getRequestMethod(HttpServletRequest request) {
return request.getParameter("_method") != null ?
request.getParameter("_method") :
request.getMethod();
}

public static Locale getLocale(HttpServletRequest request, HttpSession session, Object appDefaultLocale) {
// check session first, should override all if anything set there
Object localeObject = session != null ? session.getAttribute("locale") : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ public void doRequest(HttpServletRequest request, HttpServletResponse response,
// The "overriddenView" attribute is set by resolveURI when necessary.
String overrideViewUri = (String) request.getAttribute("overriddenView");

String restMethod = request.getParameter("restMethod");
String method = (restMethod != null) ? restMethod : request.getMethod();
String method = UtilHttp.getRequestMethod(request);
RequestMap requestMap = resolveMethod(method, rmaps).orElseThrow(() -> {
String msg = UtilProperties.getMessage("WebappUiLabels", "RequestMethodNotMatchConfig",
UtilMisc.toList(requestUri, method), UtilHttp.getLocale(request));
Expand Down

0 comments on commit 11cf350

Please sign in to comment.