Updated to latest Protocol Version
This commit is contained in:
@@ -33,20 +33,20 @@ public final class MergedRequestParams {
|
||||
public static MergedRequestParams from(String rawTarget, Map<String, String> headers, byte[] body) {
|
||||
Map<String, List<String>> merged = new LinkedHashMap<>();
|
||||
|
||||
// 1) Query string
|
||||
// Query string
|
||||
String query = extractQuery(rawTarget);
|
||||
if (query != null && !query.isBlank()) {
|
||||
mergeInto(merged, parseUrlEncoded(query, StandardCharsets.UTF_8), false);
|
||||
}
|
||||
|
||||
// 2) Body
|
||||
// Body
|
||||
if (body != null && body.length > 0) {
|
||||
String contentType = header(headers, "content-type");
|
||||
Map<String, List<String>> bodyParams = parseBody(contentType, body);
|
||||
mergeInto(merged, bodyParams, true);
|
||||
}
|
||||
|
||||
return new MergedRequestParams(merged);
|
||||
return new MergedRequestParams(Collections.unmodifiableMap(merged));
|
||||
}
|
||||
|
||||
private static String extractQuery(String rawTarget) {
|
||||
@@ -70,16 +70,20 @@ public final class MergedRequestParams {
|
||||
|
||||
private static void mergeInto(Map<String, List<String>> target, Map<String, List<String>> src, boolean override) {
|
||||
if (src == null || src.isEmpty()) return;
|
||||
|
||||
for (Map.Entry<String, List<String>> e : src.entrySet()) {
|
||||
if (e.getKey() == null) continue;
|
||||
|
||||
String k = e.getKey();
|
||||
List<String> vals = e.getValue() == null ? List.of() : e.getValue();
|
||||
List<String> vals = (e.getValue() == null) ? List.of() : e.getValue();
|
||||
|
||||
if (!override && target.containsKey(k)) {
|
||||
// append
|
||||
// Always keep ArrayList in target to allow appends safely.
|
||||
target.get(k).addAll(vals);
|
||||
continue;
|
||||
}
|
||||
// override or insert
|
||||
|
||||
// Insert/override with a mutable list to preserve later merge behavior.
|
||||
target.put(k, new ArrayList<>(vals));
|
||||
}
|
||||
}
|
||||
@@ -166,6 +170,7 @@ public final class MergedRequestParams {
|
||||
|
||||
/**
|
||||
* Minimal multipart parser for text fields only.
|
||||
*
|
||||
* <p>Ignores file uploads and binary content.</p>
|
||||
*/
|
||||
private static Map<String, List<String>> parseMultipartTextFields(byte[] body, String boundary, Charset charset) {
|
||||
@@ -293,13 +298,8 @@ public final class MergedRequestParams {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// ISO-8859-1 safe char -> byte
|
||||
if (c <= 0xFF) baos.write((byte) c);
|
||||
else {
|
||||
// for non-latin chars, fall back to UTF-8 bytes of that char
|
||||
byte[] b = String.valueOf(c).getBytes(charset);
|
||||
baos.writeBytes(b);
|
||||
}
|
||||
else baos.writeBytes(String.valueOf(c).getBytes(charset));
|
||||
}
|
||||
return baos.toString(charset);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user