Typo fix in post encoder and replaced static hashmap with array.

This commit is contained in:
Dmitriy Dumanskiy 2017-01-19 00:37:05 +02:00 committed by Scott Mitchell
parent 2fd42cfc6b
commit 2d11331591

View File

@ -43,13 +43,13 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.regex.Pattern;
import static io.netty.buffer.Unpooled.wrappedBuffer;
import static java.util.AbstractMap.SimpleImmutableEntry;
/**
* This encoder will help to encode Request for a FORM as POST.
@ -92,12 +92,14 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
HTML5
}
private static final Map<Pattern, String> percentEncodings = new HashMap<Pattern, String>();
private static final Map.Entry[] percentEncodings;
static {
percentEncodings.put(Pattern.compile("\\*"), "%2A");
percentEncodings.put(Pattern.compile("\\+"), "%20");
percentEncodings.put(Pattern.compile("%7E"), "~");
percentEncodings = new Map.Entry[] {
new SimpleImmutableEntry<Pattern, String>(Pattern.compile("\\*"), "%2A"),
new SimpleImmutableEntry<Pattern, String>(Pattern.compile("\\+"), "%20"),
new SimpleImmutableEntry<Pattern, String>(Pattern.compile("~"), "%7E")
};
}
/**
@ -371,7 +373,7 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
*/
public void addBodyFileUpload(String name, File file, String contentType, boolean isText)
throws ErrorDataEncoderException {
addBodyFileUpload(name, file.getName(), file, contentType, isText);
addBodyFileUpload(name, file.getName(), file, contentType, isText);
}
/**
@ -853,6 +855,7 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
* @throws ErrorDataEncoderException
* if the encoding is in error
*/
@SuppressWarnings("unchecked")
private String encodeAttribute(String s, Charset charset) throws ErrorDataEncoderException {
if (s == null) {
return "";
@ -860,7 +863,7 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
try {
String encoded = URLEncoder.encode(s, charset.name());
if (encoderMode == EncoderMode.RFC3986) {
for (Map.Entry<Pattern, String> entry : percentEncodings.entrySet()) {
for (Map.Entry<Pattern, String> entry : percentEncodings) {
String replacement = entry.getValue();
encoded = entry.getKey().matcher(encoded).replaceAll(replacement);
}