JSR-356 making HTTP Header map use TreeMap(String.CASE_INSENSITIVE_ORDER)
This commit is contained in:
parent
cbaf68be20
commit
07041f6439
|
@ -25,8 +25,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||||
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
|
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
|
||||||
|
@ -37,7 +37,7 @@ public class UpgradeRequest
|
||||||
private List<String> subProtocols = new ArrayList<>();
|
private List<String> subProtocols = new ArrayList<>();
|
||||||
private List<ExtensionConfig> extensions = new ArrayList<>();
|
private List<ExtensionConfig> extensions = new ArrayList<>();
|
||||||
private List<HttpCookie> cookies = 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 Map<String, List<String>> parameters = new HashMap<>();
|
||||||
private Object session;
|
private Object session;
|
||||||
private String httpVersion;
|
private String httpVersion;
|
||||||
|
@ -94,7 +94,7 @@ public class UpgradeRequest
|
||||||
|
|
||||||
public String getHeader(String name)
|
public String getHeader(String name)
|
||||||
{
|
{
|
||||||
List<String> values = headers.get(name.toLowerCase(Locale.ENGLISH));
|
List<String> values = headers.get(name);
|
||||||
// no value list
|
// no value list
|
||||||
if (values == null)
|
if (values == null)
|
||||||
{
|
{
|
||||||
|
@ -128,7 +128,7 @@ public class UpgradeRequest
|
||||||
|
|
||||||
public int getHeaderInt(String name)
|
public int getHeaderInt(String name)
|
||||||
{
|
{
|
||||||
List<String> values = headers.get(name.toLowerCase(Locale.ENGLISH));
|
List<String> values = headers.get(name);
|
||||||
// no value list
|
// no value list
|
||||||
if (values == null)
|
if (values == null)
|
||||||
{
|
{
|
||||||
|
@ -267,14 +267,14 @@ public class UpgradeRequest
|
||||||
|
|
||||||
public void setHeader(String name, List<String> values)
|
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)
|
public void setHeader(String name, String value)
|
||||||
{
|
{
|
||||||
List<String> values = new ArrayList<>();
|
List<String> values = new ArrayList<>();
|
||||||
values.add(value);
|
values.add(value);
|
||||||
setHeader(name.toLowerCase(Locale.ENGLISH),values);
|
setHeader(name,values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeaders(Map<String, List<String>> headers)
|
public void setHeaders(Map<String, List<String>> headers)
|
||||||
|
|
|
@ -20,10 +20,10 @@ package org.eclipse.jetty.websocket.api;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||||
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
|
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";
|
public static final String SEC_WEBSOCKET_PROTOCOL = "Sec-WebSocket-Protocol";
|
||||||
private int statusCode;
|
private int statusCode;
|
||||||
private String statusReason;
|
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 List<ExtensionConfig> extensions = new ArrayList<>();
|
||||||
private boolean success = false;
|
private boolean success = false;
|
||||||
|
|
||||||
public void addHeader(String name, String value)
|
public void addHeader(String name, String value)
|
||||||
{
|
{
|
||||||
String key = name.toLowerCase();
|
String key = name;
|
||||||
List<String> values = headers.get(key);
|
List<String> values = headers.get(key);
|
||||||
if (values == null)
|
if (values == null)
|
||||||
{
|
{
|
||||||
|
@ -115,7 +115,7 @@ public class UpgradeResponse
|
||||||
|
|
||||||
public List<String> getHeaders(String name)
|
public List<String> getHeaders(String name)
|
||||||
{
|
{
|
||||||
return headers.get(name.toLowerCase());
|
return headers.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStatusCode()
|
public int getStatusCode()
|
||||||
|
@ -188,7 +188,7 @@ public class UpgradeResponse
|
||||||
{
|
{
|
||||||
List<String> values = new ArrayList<>();
|
List<String> values = new ArrayList<>();
|
||||||
values.add(value);
|
values.add(value);
|
||||||
headers.put(name.toLowerCase(),values);
|
headers.put(name,values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatusCode(int statusCode)
|
public void setStatusCode(int statusCode)
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class ClientUpgradeRequest extends UpgradeRequest
|
||||||
// Other headers
|
// Other headers
|
||||||
for (String key : getHeaders().keySet())
|
for (String key : getHeaders().keySet())
|
||||||
{
|
{
|
||||||
if (FORBIDDEN_HEADERS.contains(key.toLowerCase()))
|
if (FORBIDDEN_HEADERS.contains(key))
|
||||||
{
|
{
|
||||||
LOG.warn("Skipping forbidden header - {}",key);
|
LOG.warn("Skipping forbidden header - {}",key);
|
||||||
continue; // skip
|
continue; // skip
|
||||||
|
|
|
@ -19,26 +19,25 @@
|
||||||
package org.eclipse.jetty.websocket.common.io.http;
|
package org.eclipse.jetty.websocket.common.io.http;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class HttpResponseParseCapture implements HttpResponseHeaderParseListener
|
public class HttpResponseParseCapture implements HttpResponseHeaderParseListener
|
||||||
{
|
{
|
||||||
private int statusCode;
|
private int statusCode;
|
||||||
private String statusReason;
|
private String statusReason;
|
||||||
private Map<String, String> headers = new HashMap<>();
|
private Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
private ByteBuffer remainingBuffer;
|
private ByteBuffer remainingBuffer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addHeader(String name, String value)
|
public void addHeader(String name, String value)
|
||||||
{
|
{
|
||||||
headers.put(name.toLowerCase(Locale.ENGLISH),value);
|
headers.put(name,value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHeader(String name)
|
public String getHeader(String name)
|
||||||
{
|
{
|
||||||
return headers.get(name.toLowerCase(Locale.ENGLISH));
|
return headers.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer getRemainingBuffer()
|
public ByteBuffer getRemainingBuffer()
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.eclipse.jetty.websocket.common.io.http.HttpResponseHeaderParseListener;
|
import org.eclipse.jetty.websocket.common.io.http.HttpResponseHeaderParseListener;
|
||||||
|
|
||||||
|
@ -29,13 +30,13 @@ public class HttpResponse implements HttpResponseHeaderParseListener
|
||||||
{
|
{
|
||||||
private int statusCode;
|
private int statusCode;
|
||||||
private String statusReason;
|
private String statusReason;
|
||||||
private Map<String, String> headers = new HashMap<>();
|
private Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
private ByteBuffer remainingBuffer;
|
private ByteBuffer remainingBuffer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addHeader(String name, String value)
|
public void addHeader(String name, String value)
|
||||||
{
|
{
|
||||||
headers.put(name.toLowerCase(Locale.ENGLISH),value);
|
headers.put(name,value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExtensionsHeader()
|
public String getExtensionsHeader()
|
||||||
|
@ -45,7 +46,7 @@ public class HttpResponse implements HttpResponseHeaderParseListener
|
||||||
|
|
||||||
public String getHeader(String name)
|
public String getHeader(String name)
|
||||||
{
|
{
|
||||||
return headers.get(name.toLowerCase(Locale.ENGLISH));
|
return headers.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer getRemainingBuffer()
|
public ByteBuffer getRemainingBuffer()
|
||||||
|
|
|
@ -86,12 +86,7 @@ public class ServletUpgradeRequest extends UpgradeRequest
|
||||||
while (headerNames.hasMoreElements())
|
while (headerNames.hasMoreElements())
|
||||||
{
|
{
|
||||||
String name = headerNames.nextElement();
|
String name = headerNames.nextElement();
|
||||||
Enumeration<String> valuesEnum = request.getHeaders(name);
|
List<String> values = Collections.list(request.getHeaders(name));
|
||||||
List<String> values = new ArrayList<>();
|
|
||||||
while (valuesEnum.hasMoreElements())
|
|
||||||
{
|
|
||||||
values.add(valuesEnum.nextElement());
|
|
||||||
}
|
|
||||||
setHeader(name,values);
|
setHeader(name,values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue