JSR-356 making HTTP Header map use TreeMap(String.CASE_INSENSITIVE_ORDER)

This commit is contained in:
Joakim Erdfelt 2013-08-01 10:50:01 -07:00
parent cbaf68be20
commit 07041f6439
6 changed files with 21 additions and 26 deletions

View File

@ -25,8 +25,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
@ -37,7 +37,7 @@ public class UpgradeRequest
private List<String> subProtocols = new ArrayList<>();
private List<ExtensionConfig> extensions = new ArrayList<>();
private List<HttpCookie> cookies = new ArrayList<>();
private Map<String, List<String>> headers = new HashMap<>();
private Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private Map<String, List<String>> parameters = new HashMap<>();
private Object session;
private String httpVersion;
@ -94,7 +94,7 @@ public class UpgradeRequest
public String getHeader(String name)
{
List<String> values = headers.get(name.toLowerCase(Locale.ENGLISH));
List<String> values = headers.get(name);
// no value list
if (values == null)
{
@ -128,7 +128,7 @@ public class UpgradeRequest
public int getHeaderInt(String name)
{
List<String> values = headers.get(name.toLowerCase(Locale.ENGLISH));
List<String> values = headers.get(name);
// no value list
if (values == null)
{
@ -267,14 +267,14 @@ public class UpgradeRequest
public void setHeader(String name, List<String> values)
{
headers.put(name.toLowerCase(Locale.ENGLISH),values);
headers.put(name,values);
}
public void setHeader(String name, String value)
{
List<String> values = new ArrayList<>();
values.add(value);
setHeader(name.toLowerCase(Locale.ENGLISH),values);
setHeader(name,values);
}
public void setHeaders(Map<String, List<String>> headers)

View File

@ -20,10 +20,10 @@ package org.eclipse.jetty.websocket.api;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
@ -33,13 +33,13 @@ public class UpgradeResponse
public static final String SEC_WEBSOCKET_PROTOCOL = "Sec-WebSocket-Protocol";
private int statusCode;
private String statusReason;
private Map<String, List<String>> headers = new HashMap<>();
private Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private List<ExtensionConfig> extensions = new ArrayList<>();
private boolean success = false;
public void addHeader(String name, String value)
{
String key = name.toLowerCase();
String key = name;
List<String> values = headers.get(key);
if (values == null)
{
@ -115,7 +115,7 @@ public class UpgradeResponse
public List<String> getHeaders(String name)
{
return headers.get(name.toLowerCase());
return headers.get(name);
}
public int getStatusCode()
@ -188,7 +188,7 @@ public class UpgradeResponse
{
List<String> values = new ArrayList<>();
values.add(value);
headers.put(name.toLowerCase(),values);
headers.put(name,values);
}
public void setStatusCode(int statusCode)

View File

@ -173,7 +173,7 @@ public class ClientUpgradeRequest extends UpgradeRequest
// Other headers
for (String key : getHeaders().keySet())
{
if (FORBIDDEN_HEADERS.contains(key.toLowerCase()))
if (FORBIDDEN_HEADERS.contains(key))
{
LOG.warn("Skipping forbidden header - {}",key);
continue; // skip

View File

@ -19,26 +19,25 @@
package org.eclipse.jetty.websocket.common.io.http;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
public class HttpResponseParseCapture implements HttpResponseHeaderParseListener
{
private int statusCode;
private String statusReason;
private Map<String, String> headers = new HashMap<>();
private Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private ByteBuffer remainingBuffer;
@Override
public void addHeader(String name, String value)
{
headers.put(name.toLowerCase(Locale.ENGLISH),value);
headers.put(name,value);
}
public String getHeader(String name)
{
return headers.get(name.toLowerCase(Locale.ENGLISH));
return headers.get(name);
}
public ByteBuffer getRemainingBuffer()

View File

@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.jetty.websocket.common.io.http.HttpResponseHeaderParseListener;
@ -29,13 +30,13 @@ public class HttpResponse implements HttpResponseHeaderParseListener
{
private int statusCode;
private String statusReason;
private Map<String, String> headers = new HashMap<>();
private Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private ByteBuffer remainingBuffer;
@Override
public void addHeader(String name, String value)
{
headers.put(name.toLowerCase(Locale.ENGLISH),value);
headers.put(name,value);
}
public String getExtensionsHeader()
@ -45,7 +46,7 @@ public class HttpResponse implements HttpResponseHeaderParseListener
public String getHeader(String name)
{
return headers.get(name.toLowerCase(Locale.ENGLISH));
return headers.get(name);
}
public ByteBuffer getRemainingBuffer()

View File

@ -86,12 +86,7 @@ public class ServletUpgradeRequest extends UpgradeRequest
while (headerNames.hasMoreElements())
{
String name = headerNames.nextElement();
Enumeration<String> valuesEnum = request.getHeaders(name);
List<String> values = new ArrayList<>();
while (valuesEnum.hasMoreElements())
{
values.add(valuesEnum.nextElement());
}
List<String> values = Collections.list(request.getHeaders(name));
setHeader(name,values);
}