Get query string through ServerHttpRequest.getQueryParams()

This commit is contained in:
hongqiaowei
2021-10-18 17:05:17 +08:00
parent eb793b3092
commit 62841a179e
9 changed files with 121 additions and 25 deletions

View File

@@ -125,26 +125,31 @@ public class FizzServerWebExchangeDecorator extends ServerWebExchangeDecorator {
for (Map.Entry<String, List<String>> fieldValuesEntry : fieldValuesEntries) {
String field = fieldValuesEntry.getKey();
List<String> values = fieldValuesEntry.getValue();
if (CollectionUtils.isEmpty(values)) {
if (values.isEmpty()) {
b.append(URLEncoder.encode(field, Consts.C.UTF8));
} else {
int vs = values.size();
for (int i = 0; i < vs; ) {
b.append(URLEncoder.encode(field, Consts.C.UTF8))
.append('=')
.append(URLEncoder.encode(values.get(i), Consts.C.UTF8));
if ((++i) != vs) {
b.append('&');
String v = values.get(i);
b.append(URLEncoder.encode(field, Consts.C.UTF8));
if (v != null) {
b.append(Consts.S.EQUAL);
if (!Consts.S.EMPTY.equals(v)) {
b.append(URLEncoder.encode(v, Consts.C.UTF8));
}
}
if ((++i) != vs) {
b.append(Consts.S.AND);
}
}
}
if ((++cnt) != fs) {
b.append('&');
b.append(Consts.S.AND);
}
}
} catch (UnsupportedEncodingException ex) {
throw new IllegalStateException(ex);
req.setBody(b.toString());
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
req.setBody(b.toString());
}
}

View File

@@ -53,6 +53,8 @@ public final class Consts {
public static final char RIGHT_BRACE = '}';
public static final char SQUARE = '^';
public static final char HASH = '#';
public static final char AND = '&';
public static final char OR = '|';
public static final char LF = '\n';
public static final char TAB = '\t';