-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(http): optimize parameter parsing #5483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
48585eb
be8f186
e6a5c68
5292497
a241aa3
54884dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| import org.apache.commons.lang3.StringUtils; | ||
| import org.bouncycastle.util.encoders.Hex; | ||
| import org.eclipse.jetty.http.HttpMethod; | ||
| import org.eclipse.jetty.http.MimeTypes; | ||
| import org.eclipse.jetty.util.MultiMap; | ||
| import org.eclipse.jetty.util.StringUtil; | ||
| import org.eclipse.jetty.util.UrlEncoded; | ||
|
|
@@ -78,8 +79,6 @@ public class Util { | |
| public static final String FUNCTION_SELECTOR = "function_selector"; | ||
| public static final String FUNCTION_PARAMETER = "parameter"; | ||
| public static final String CALL_DATA = "data"; | ||
| public static final String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded"; | ||
| public static final String APPLICATION_JSON = "application/json"; | ||
|
|
||
| public static String printTransactionFee(String transactionFee) { | ||
| JSONObject jsonObject = new JSONObject(); | ||
|
|
@@ -525,7 +524,6 @@ public static byte[] getAddress(HttpServletRequest request) throws Exception { | |
|
|
||
| private static String checkGetParam(HttpServletRequest request, String key) throws Exception { | ||
| String method = request.getMethod(); | ||
| String value = null; | ||
|
|
||
| if (HttpMethod.GET.toString().toUpperCase().equalsIgnoreCase(method)) { | ||
| return request.getParameter(key); | ||
|
|
@@ -535,8 +533,10 @@ private static String checkGetParam(HttpServletRequest request, String key) thro | |
| if (StringUtils.isBlank(contentType)) { | ||
| return null; | ||
| } | ||
| if (APPLICATION_JSON.toLowerCase().contains(contentType)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the contentType to lower case too ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defaults to lowercase. |
||
| value = getRequestValue(request); | ||
| if (contentType.contains(MimeTypes.Type.FORM_ENCODED.asString())) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we add some explanation about this change? |
||
| return request.getParameter(key); | ||
| } else { | ||
| String value = getRequestValue(request); | ||
| if (StringUtils.isBlank(value)) { | ||
| return null; | ||
| } | ||
|
|
@@ -545,13 +545,10 @@ private static String checkGetParam(HttpServletRequest request, String key) thro | |
| if (jsonObject != null) { | ||
| return jsonObject.getString(key); | ||
| } | ||
| } else if (APPLICATION_FORM_URLENCODED.toLowerCase().contains(contentType)) { | ||
| return request.getParameter(key); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
| return value; | ||
| return null; | ||
| } | ||
|
|
||
| public static String getRequestValue(HttpServletRequest request) throws IOException { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better add unit test