jetty-9 - Moved SPDY's Headers class to jetty-util module as Fields.

This commit is contained in:
Simone Bordet 2012-09-06 13:22:04 +02:00
parent 236df8e94b
commit d8ed9116f1
42 changed files with 374 additions and 452 deletions

View File

@ -46,7 +46,8 @@ import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
/* ------------------------------------------------------------ */ // TODO: Make this class inherit from oej.util.Fields
/** /**
* HTTP Fields. A collection of HTTP header and or Trailer fields. * HTTP Fields. A collection of HTTP header and or Trailer fields.
* *
@ -57,30 +58,24 @@ import org.eclipse.jetty.util.log.Logger;
public class HttpFields implements Iterable<HttpFields.Field> public class HttpFields implements Iterable<HttpFields.Field>
{ {
private static final Logger LOG = Log.getLogger(HttpFields.class); private static final Logger LOG = Log.getLogger(HttpFields.class);
/* ------------------------------------------------------------ */
public static final String __COOKIE_DELIM="\"\\\n\r\t\f\b%+ ;="; public static final String __COOKIE_DELIM="\"\\\n\r\t\f\b%+ ;=";
public static final TimeZone __GMT = TimeZone.getTimeZone("GMT"); public static final TimeZone __GMT = TimeZone.getTimeZone("GMT");
public static final DateCache __dateCache = new DateCache("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US); public static final DateCache __dateCache = new DateCache("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
/* -------------------------------------------------------------- */
static static
{ {
__GMT.setID("GMT"); __GMT.setID("GMT");
__dateCache.setTimeZone(__GMT); __dateCache.setTimeZone(__GMT);
} }
/* ------------------------------------------------------------ */
public final static String __separators = ", \t"; public final static String __separators = ", \t";
/* ------------------------------------------------------------ */
private static final String[] DAYS = private static final String[] DAYS =
{ "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; { "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
private static final String[] MONTHS = private static final String[] MONTHS =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan"}; { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan"};
/* ------------------------------------------------------------ */
private static class DateGenerator private static class DateGenerator
{ {
private final StringBuilder buf = new StringBuilder(32); private final StringBuilder buf = new StringBuilder(32);
@ -126,7 +121,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return buf.toString(); return buf.toString();
} }
/* ------------------------------------------------------------ */
/** /**
* Format "EEE, dd-MMM-yy HH:mm:ss 'GMT'" for cookies * Format "EEE, dd-MMM-yy HH:mm:ss 'GMT'" for cookies
*/ */
@ -167,7 +161,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
} }
/* ------------------------------------------------------------ */
private static final ThreadLocal<DateGenerator> __dateGenerator =new ThreadLocal<DateGenerator>() private static final ThreadLocal<DateGenerator> __dateGenerator =new ThreadLocal<DateGenerator>()
{ {
@Override @Override
@ -177,7 +170,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
}; };
/* ------------------------------------------------------------ */
/** /**
* Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" * Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
*/ */
@ -186,7 +178,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return __dateGenerator.get().formatDate(date); return __dateGenerator.get().formatDate(date);
} }
/* ------------------------------------------------------------ */
/** /**
* Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies * Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies
*/ */
@ -195,7 +186,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
__dateGenerator.get().formatCookieDate(buf,date); __dateGenerator.get().formatCookieDate(buf,date);
} }
/* ------------------------------------------------------------ */
/** /**
* Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies * Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies
*/ */
@ -206,7 +196,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return buf.toString(); return buf.toString();
} }
/* ------------------------------------------------------------ */
private final static String __dateReceiveFmt[] = private final static String __dateReceiveFmt[] =
{ {
"EEE, dd MMM yyyy HH:mm:ss zzz", "EEE, dd MMM yyyy HH:mm:ss zzz",
@ -222,7 +211,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
"EEE dd-MMM-yy HH:mm:ss zzz", "EEE dd-MMM-yy HH:mm:ss", "EEE dd-MMM-yy HH:mm:ss zzz", "EEE dd-MMM-yy HH:mm:ss",
}; };
/* ------------------------------------------------------------ */
private static class DateParser private static class DateParser
{ {
final SimpleDateFormat _dateReceive[]= new SimpleDateFormat[__dateReceiveFmt.length]; final SimpleDateFormat _dateReceive[]= new SimpleDateFormat[__dateReceiveFmt.length];
@ -269,13 +257,11 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
} }
/* ------------------------------------------------------------ */
public static long parseDate(String date) public static long parseDate(String date)
{ {
return __dateParser.get().parse(date); return __dateParser.get().parse(date);
} }
/* ------------------------------------------------------------ */
private static final ThreadLocal<DateParser> __dateParser =new ThreadLocal<DateParser>() private static final ThreadLocal<DateParser> __dateParser =new ThreadLocal<DateParser>()
{ {
@Override @Override
@ -285,16 +271,13 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
}; };
/* -------------------------------------------------------------- */
public final static String __01Jan1970=formatDate(0); public final static String __01Jan1970=formatDate(0);
public final static ByteBuffer __01Jan1970_BUFFER=BufferUtil.toBuffer(__01Jan1970); public final static ByteBuffer __01Jan1970_BUFFER=BufferUtil.toBuffer(__01Jan1970);
public final static String __01Jan1970_COOKIE = formatCookieDate(0).trim(); public final static String __01Jan1970_COOKIE = formatCookieDate(0).trim();
private final static byte[] __colon_space = new byte[] {':',' '}; private final static byte[] __colon_space = new byte[] {':',' '};
/* -------------------------------------------------------------- */ private final ArrayList<Field> _fields = new ArrayList<>(20);
private final ArrayList<Field> _fields = new ArrayList<Field>(20); private final StringMap<Field> _names = new StringMap<>(true);
private final StringMap<Field> _names = new StringMap<Field>(true);
/* ------------------------------------------------------------ */
/** /**
* Constructor. * Constructor.
*/ */
@ -303,13 +286,12 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
/* -------------------------------------------------------------- */
/** /**
* Get Collection of header names. * Get Collection of header names.
*/ */
public Collection<String> getFieldNamesCollection() public Collection<String> getFieldNamesCollection()
{ {
final List<String> list = new ArrayList<String>(_fields.size()); final List<String> list = new ArrayList<>(_fields.size());
for (Field f : _fields) for (Field f : _fields)
{ {
if (f!=null) if (f!=null)
@ -318,7 +300,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return list; return list;
} }
/* -------------------------------------------------------------- */
/** /**
* Get enumeration of header _names. Returns an enumeration of strings representing the header * Get enumeration of header _names. Returns an enumeration of strings representing the header
* _names for this request. * _names for this request.
@ -342,13 +323,11 @@ public class HttpFields implements Iterable<HttpFields.Field>
}; };
} }
/* ------------------------------------------------------------ */
public int size() public int size()
{ {
return _fields.size(); return _fields.size();
} }
/* ------------------------------------------------------------ */
/** /**
* Get a Field by index. * Get a Field by index.
* @return A Field value or null if the Field value has not been set * @return A Field value or null if the Field value has not been set
@ -359,50 +338,42 @@ public class HttpFields implements Iterable<HttpFields.Field>
return _fields.get(i); return _fields.get(i);
} }
/* ------------------------------------------------------------ */
@Override @Override
public Iterator<Field> iterator() public Iterator<Field> iterator()
{ {
return _fields.iterator(); return _fields.iterator();
} }
/* ------------------------------------------------------------ */
public Field getField(HttpHeader header) public Field getField(HttpHeader header)
{ {
return _names.get(header.toString()); return _names.get(header.toString());
} }
/* ------------------------------------------------------------ */
public Field getField(String name) public Field getField(String name)
{ {
return _names.get(name); return _names.get(name);
} }
/* ------------------------------------------------------------ */
public boolean containsKey(String name) public boolean containsKey(String name)
{ {
return _names.containsKey(name); return _names.containsKey(name);
} }
/* -------------------------------------------------------------- */
public String getStringField(HttpHeader header) public String getStringField(HttpHeader header)
{ {
return getStringField(header.asString()); return getStringField(header.asString());
} }
/* -------------------------------------------------------------- */
public String get(HttpHeader header) public String get(HttpHeader header)
{ {
return getStringField(header.asString()); return getStringField(header.asString());
} }
/* -------------------------------------------------------------- */
public String get(String header) public String get(String header)
{ {
return getStringField(header); return getStringField(header);
} }
/* -------------------------------------------------------------- */
/** /**
* @return the value of a field, or null if not found. For multiple fields of the same name, * @return the value of a field, or null if not found. For multiple fields of the same name,
* only the first is returned. * only the first is returned.
@ -415,7 +386,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
/* -------------------------------------------------------------- */
/** /**
* Get multi headers * Get multi headers
* *
@ -428,7 +398,7 @@ public class HttpFields implements Iterable<HttpFields.Field>
if (field==null) if (field==null)
return null; return null;
final List<String> list = new ArrayList<String>(); final List<String> list = new ArrayList<>();
while(field!=null) while(field!=null)
{ {
@ -438,7 +408,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return list; return list;
} }
/* -------------------------------------------------------------- */
/** /**
* Get multi headers * Get multi headers
* *
@ -475,7 +444,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
}; };
} }
/* -------------------------------------------------------------- */
/** /**
* Get multi field values with separator. The multiple values can be represented as separate * Get multi field values with separator. The multiple values can be represented as separate
* headers of the same name, or by a single header using the separator(s), or a combination of * headers of the same name, or by a single header using the separator(s), or a combination of
@ -520,7 +488,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
/* -------------------------------------------------------------- */
/** /**
* Set a field. * Set a field.
* *
@ -539,13 +506,11 @@ public class HttpFields implements Iterable<HttpFields.Field>
_names.put(name, field); _names.put(name, field);
} }
/* -------------------------------------------------------------- */
public void put(HttpHeader header, HttpHeaderValue value) public void put(HttpHeader header, HttpHeaderValue value)
{ {
put(header,value.toString()); put(header,value.toString());
} }
/* -------------------------------------------------------------- */
/** /**
* Set a field. * Set a field.
* *
@ -564,7 +529,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
_names.put(header.toString(), field); _names.put(header.toString(), field);
} }
/* -------------------------------------------------------------- */
/** /**
* Set a field. * Set a field.
* *
@ -579,7 +543,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
add(name,v); add(name,v);
} }
/* -------------------------------------------------------------- */
/** /**
* Add to or set a field. If the field is allowed to have multiple values, add will add multiple * Add to or set a field. If the field is allowed to have multiple values, add will add multiple
* headers of the same name. * headers of the same name.
@ -613,18 +576,16 @@ public class HttpFields implements Iterable<HttpFields.Field>
_names.put(name, field); _names.put(name, field);
} }
/* -------------------------------------------------------------- */
public void add(HttpHeader header, HttpHeaderValue value) throws IllegalArgumentException public void add(HttpHeader header, HttpHeaderValue value) throws IllegalArgumentException
{ {
add(header,value.toString()); add(header,value.toString());
} }
/* -------------------------------------------------------------- */
/** /**
* Add to or set a field. If the field is allowed to have multiple values, add will add multiple * Add to or set a field. If the field is allowed to have multiple values, add will add multiple
* headers of the same name. * headers of the same name.
* *
* @param name the name of the field * @param header the header
* @param value the value of the field. * @param value the value of the field.
* @exception IllegalArgumentException If the name is a single valued field and already has a * @exception IllegalArgumentException If the name is a single valued field and already has a
* value. * value.
@ -652,22 +613,20 @@ public class HttpFields implements Iterable<HttpFields.Field>
_names.put(header.toString(), field); _names.put(header.toString(), field);
} }
/* ------------------------------------------------------------ */
/** /**
* Remove a field. * Remove a field.
* *
* @param name * @param name the field to remove
*/ */
public void remove(HttpHeader name) public void remove(HttpHeader name)
{ {
remove(name.toString()); remove(name.toString());
} }
/* ------------------------------------------------------------ */
/** /**
* Remove a field. * Remove a field.
* *
* @param name * @param name the field to remove
*/ */
public void remove(String name) public void remove(String name)
{ {
@ -679,7 +638,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
} }
/* -------------------------------------------------------------- */
/** /**
* Get a header as an long value. Returns the value of an integer field or -1 if not found. The * Get a header as an long value. Returns the value of an integer field or -1 if not found. The
* case of the field name is ignored. * case of the field name is ignored.
@ -693,7 +651,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return field==null?-1L:field.getLongValue(); return field==null?-1L:field.getLongValue();
} }
/* -------------------------------------------------------------- */
/** /**
* Get a header as a date value. Returns the value of a date field, or -1 if not found. The case * Get a header as a date value. Returns the value of a date field, or -1 if not found. The case
* of the field name is ignored. * of the field name is ignored.
@ -717,7 +674,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
/* -------------------------------------------------------------- */
/** /**
* Sets the value of an long field. * Sets the value of an long field.
* *
@ -730,7 +686,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
put(name, v); put(name, v);
} }
/* -------------------------------------------------------------- */
/** /**
* Sets the value of an long field. * Sets the value of an long field.
* *
@ -744,7 +699,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
/* -------------------------------------------------------------- */
/** /**
* Sets the value of a date field. * Sets the value of a date field.
* *
@ -757,7 +711,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
put(name, d); put(name, d);
} }
/* -------------------------------------------------------------- */
/** /**
* Sets the value of a date field. * Sets the value of a date field.
* *
@ -770,7 +723,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
put(name, d); put(name, d);
} }
/* -------------------------------------------------------------- */
/** /**
* Sets the value of a date field. * Sets the value of a date field.
* *
@ -783,7 +735,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
add(name,d); add(name,d);
} }
/* ------------------------------------------------------------ */
/** /**
* Format a set cookie value * Format a set cookie value
* *
@ -907,29 +858,25 @@ public class HttpFields implements Iterable<HttpFields.Field>
put(HttpHeader.EXPIRES.toString(), __01Jan1970); put(HttpHeader.EXPIRES.toString(), __01Jan1970);
} }
/* -------------------------------------------------------------- */
public void putTo(ByteBuffer bufferInFillMode) throws IOException public void putTo(ByteBuffer bufferInFillMode) throws IOException
{ {
for (int i = 0; i < _fields.size(); i++) for (Field field : _fields)
{ {
Field field = _fields.get(i);
if (field != null) if (field != null)
field.putTo(bufferInFillMode); field.putTo(bufferInFillMode);
} }
BufferUtil.putCRLF(bufferInFillMode); BufferUtil.putCRLF(bufferInFillMode);
} }
/* -------------------------------------------------------------- */
@Override @Override
public String public String
toString() toString()
{ {
try try
{ {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
for (int i = 0; i < _fields.size(); i++) for (Field field : _fields)
{ {
Field field = _fields.get(i);
if (field != null) if (field != null)
{ {
String tmp = field.getName(); String tmp = field.getName();
@ -950,7 +897,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
} }
/* ------------------------------------------------------------ */
/** /**
* Clear the header. * Clear the header.
*/ */
@ -960,12 +906,11 @@ public class HttpFields implements Iterable<HttpFields.Field>
_names.clear(); _names.clear();
} }
/* ------------------------------------------------------------ */
/** /**
* Add fields from another HttpFields instance. Single valued fields are replaced, while all * Add fields from another HttpFields instance. Single valued fields are replaced, while all
* others are added. * others are added.
* *
* @param fields * @param fields the fields to add
*/ */
public void add(HttpFields fields) public void add(HttpFields fields)
{ {
@ -981,7 +926,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
} }
/* ------------------------------------------------------------ */
/** /**
* Get field value parameters. Some field values can have parameters. This method separates the * Get field value parameters. Some field values can have parameters. This method separates the
* value from the parameters and optionally populates a map with the parameters. For example: * value from the parameters and optionally populates a map with the parameters. For example:
@ -1021,7 +965,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return value.substring(0, i).trim(); return value.substring(0, i).trim();
} }
/* ------------------------------------------------------------ */
private static final Float __one = new Float("1.0"); private static final Float __one = new Float("1.0");
private static final Float __zero = new Float("0.0"); private static final Float __zero = new Float("0.0");
private static final StringMap<Float> __qualities = new StringMap<>(); private static final StringMap<Float> __qualities = new StringMap<>();
@ -1045,7 +988,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
__qualities.put("0.0", __zero); __qualities.put("0.0", __zero);
} }
/* ------------------------------------------------------------ */
public static Float getQuality(String value) public static Float getQuality(String value)
{ {
if (value == null) return __zero; if (value == null) return __zero;
@ -1061,7 +1003,7 @@ public class HttpFields implements Iterable<HttpFields.Field>
return q; return q;
} }
Map<String,String> params = new HashMap<String,String>(4); Map<String,String> params = new HashMap<>(4);
valueParameters(value, params); valueParameters(value, params);
String qs = params.get("q"); String qs = params.get("q");
if (qs==null) if (qs==null)
@ -1081,7 +1023,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return q; return q;
} }
/* ------------------------------------------------------------ */
/** /**
* List values in quality order. * List values in quality order.
* *
@ -1099,10 +1040,10 @@ public class HttpFields implements Iterable<HttpFields.Field>
// Assume list will be well ordered and just add nonzero // Assume list will be well ordered and just add nonzero
while (e.hasMoreElements()) while (e.hasMoreElements())
{ {
String v = e.nextElement().toString(); String v = e.nextElement();
Float q = getQuality(v); Float q = getQuality(v);
if (q.floatValue() >= 0.001) if (q >= 0.001)
{ {
list = LazyList.add(list, v); list = LazyList.add(list, v);
qual = LazyList.add(qual, q); qual = LazyList.add(qual, q);
@ -1136,9 +1077,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return vl; return vl;
} }
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
public static final class Field public static final class Field
{ {
private final HttpHeader _header; private final HttpHeader _header;
@ -1146,7 +1084,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
private final String _value; private final String _value;
private Field _next; private Field _next;
/* ------------------------------------------------------------ */
private Field(HttpHeader header, String value) private Field(HttpHeader header, String value)
{ {
_header = header; _header = header;
@ -1155,7 +1092,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
_next = null; _next = null;
} }
/* ------------------------------------------------------------ */
private Field(String name, String value) private Field(String name, String value)
{ {
_header = HttpHeader.CACHE.get(name); _header = HttpHeader.CACHE.get(name);
@ -1164,7 +1100,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
_next = null; _next = null;
} }
/* ------------------------------------------------------------ */
private byte[] toSanitisedName(String s) private byte[] toSanitisedName(String s)
{ {
byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET); byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET);
@ -1181,7 +1116,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return bytes; return bytes;
} }
/* ------------------------------------------------------------ */
private byte[] toSanitisedValue(String s) private byte[] toSanitisedValue(String s)
{ {
byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET); byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET);
@ -1197,7 +1131,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
return bytes; return bytes;
} }
/* ------------------------------------------------------------ */
public void putTo(ByteBuffer bufferInFillMode) public void putTo(ByteBuffer bufferInFillMode)
{ {
HttpHeader header = HttpHeader.CACHE.get(_name); HttpHeader header = HttpHeader.CACHE.get(_name);
@ -1226,50 +1159,42 @@ public class HttpFields implements Iterable<HttpFields.Field>
BufferUtil.putCRLF(bufferInFillMode); BufferUtil.putCRLF(bufferInFillMode);
} }
/* ------------------------------------------------------------ */
public void putValueTo(ByteBuffer buffer) public void putValueTo(ByteBuffer buffer)
{ {
buffer.put(toSanitisedValue(_value)); buffer.put(toSanitisedValue(_value));
} }
/* ------------------------------------------------------------ */
public HttpHeader getHeader() public HttpHeader getHeader()
{ {
return _header; return _header;
} }
/* ------------------------------------------------------------ */
public String getName() public String getName()
{ {
return _name; return _name;
} }
/* ------------------------------------------------------------ */
public String getValue() public String getValue()
{ {
return _value; return _value;
} }
/* ------------------------------------------------------------ */
public int getIntValue() public int getIntValue()
{ {
return StringUtil.toInt(_value); return StringUtil.toInt(_value);
} }
/* ------------------------------------------------------------ */
public long getLongValue() public long getLongValue()
{ {
return StringUtil.toLong(_value); return StringUtil.toLong(_value);
} }
/* ------------------------------------------------------------ */
@Override @Override
public String toString() public String toString()
{ {
return ("[" + getName() + "=" + _value + (_next == null ? "" : "->") + "]"); return ("[" + getName() + "=" + _value + (_next == null ? "" : "->") + "]");
} }
/* ------------------------------------------------------------ */
public boolean contains(String value) public boolean contains(String value)
{ {
if (_value==null) if (_value==null)
@ -1292,7 +1217,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
} }
} }
/* ------------------------------------------------------------ */
public boolean contains(HttpHeader header, String value) public boolean contains(HttpHeader header, String value)
{ {
Field field = getField(header); Field field = getField(header);

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.spdy.api; package org.eclipse.jetty.spdy.api;
import org.eclipse.jetty.util.Fields;
/** /**
* <p>A container for HEADERS frame metadata and headers.</p> * <p>A container for HEADERS frame metadata and headers.</p>
*/ */
@ -40,16 +42,16 @@ public class HeadersInfo
private final boolean close; private final boolean close;
private final boolean resetCompression; private final boolean resetCompression;
private final Headers headers; private final Fields headers;
/** /**
* <p>Creates a new {@link HeadersInfo} instance with the given headers, * <p>Creates a new {@link HeadersInfo} instance with the given headers,
* the given close flag and no reset compression flag</p> * the given close flag and no reset compression flag</p>
* *
* @param headers the {@link Headers} * @param headers the {@link Fields}
* @param close the value of the close flag * @param close the value of the close flag
*/ */
public HeadersInfo(Headers headers, boolean close) public HeadersInfo(Fields headers, boolean close)
{ {
this(headers, close, false); this(headers, close, false);
} }
@ -58,11 +60,11 @@ public class HeadersInfo
* <p>Creates a new {@link HeadersInfo} instance with the given headers, * <p>Creates a new {@link HeadersInfo} instance with the given headers,
* the given close flag and the given reset compression flag</p> * the given close flag and the given reset compression flag</p>
* *
* @param headers the {@link Headers} * @param headers the {@link Fields}
* @param close the value of the close flag * @param close the value of the close flag
* @param resetCompression the value of the reset compression flag * @param resetCompression the value of the reset compression flag
*/ */
public HeadersInfo(Headers headers, boolean close, boolean resetCompression) public HeadersInfo(Fields headers, boolean close, boolean resetCompression)
{ {
this.headers = headers; this.headers = headers;
this.close = close; this.close = close;
@ -86,9 +88,9 @@ public class HeadersInfo
} }
/** /**
* @return the {@link Headers} * @return the {@link Fields}
*/ */
public Headers getHeaders() public Fields getHeaders()
{ {
return headers; return headers;
} }

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.spdy.api; package org.eclipse.jetty.spdy.api;
import org.eclipse.jetty.util.Fields;
/** /**
* <p>A container for SYN_REPLY frames metadata and headers.</p> * <p>A container for SYN_REPLY frames metadata and headers.</p>
*/ */
@ -31,7 +33,7 @@ public class ReplyInfo
*/ */
public static final byte FLAG_CLOSE = 1; public static final byte FLAG_CLOSE = 1;
private final Headers headers; private final Fields headers;
private final boolean close; private final boolean close;
/** /**
@ -41,25 +43,25 @@ public class ReplyInfo
*/ */
public ReplyInfo(boolean close) public ReplyInfo(boolean close)
{ {
this(new Headers(), close); this(new Fields(), close);
} }
/** /**
* <p>Creates a {@link ReplyInfo} instance with the given headers and the given close flag.</p> * <p>Creates a {@link ReplyInfo} instance with the given headers and the given close flag.</p>
* *
* @param headers the {@link Headers} * @param headers the {@link Fields}
* @param close the value of the close flag * @param close the value of the close flag
*/ */
public ReplyInfo(Headers headers, boolean close) public ReplyInfo(Fields headers, boolean close)
{ {
this.headers = headers; this.headers = headers;
this.close = close; this.close = close;
} }
/** /**
* @return the {@link Headers} * @return the {@link Fields}
*/ */
public Headers getHeaders() public Fields getHeaders()
{ {
return headers; return headers;
} }

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.spdy.api; package org.eclipse.jetty.spdy.api;
import org.eclipse.jetty.util.Fields;
/** /**
* <p>A container for SYN_STREAM frames metadata and data.</p> * <p>A container for SYN_STREAM frames metadata and data.</p>
*/ */
@ -33,7 +35,7 @@ public class SynInfo
private final boolean close; private final boolean close;
private final byte priority; private final byte priority;
private final Headers headers; private final Fields headers;
/** /**
* <p>Creates a new {@link SynInfo} instance with empty headers and the given close flag, * <p>Creates a new {@link SynInfo} instance with empty headers and the given close flag,
@ -43,17 +45,17 @@ public class SynInfo
*/ */
public SynInfo(boolean close) public SynInfo(boolean close)
{ {
this(new Headers(), close); this(new Fields(), close);
} }
/** /**
* <p>Creates a {@link ReplyInfo} instance with the given headers and the given close flag, * <p>Creates a {@link ReplyInfo} instance with the given headers and the given close flag,
* not unidirectional, without associated stream, and with default priority.</p> * not unidirectional, without associated stream, and with default priority.</p>
* *
* @param headers the {@link Headers} * @param headers the {@link Fields}
* @param close the value of the close flag * @param close the value of the close flag
*/ */
public SynInfo(Headers headers, boolean close) public SynInfo(Fields headers, boolean close)
{ {
this(headers, close, (byte)0); this(headers, close, (byte)0);
} }
@ -64,13 +66,13 @@ public class SynInfo
* </p> * </p>
* *
* @param headers * @param headers
* the {@link Headers} * the {@link Fields}
* @param close * @param close
* the value of the close flag * the value of the close flag
* @param priority * @param priority
* the priority * the priority
*/ */
public SynInfo(Headers headers, boolean close, byte priority) public SynInfo(Fields headers, boolean close, byte priority)
{ {
this.close = close; this.close = close;
this.priority = priority; this.priority = priority;
@ -94,9 +96,9 @@ public class SynInfo
} }
/** /**
* @return the {@link Headers} * @return the {@link Fields}
*/ */
public Headers getHeaders() public Fields getHeaders()
{ {
return headers; return headers;
} }

View File

@ -18,15 +18,15 @@
package org.eclipse.jetty.spdy.frames; package org.eclipse.jetty.spdy.frames;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo; import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.util.Fields;
public class HeadersFrame extends ControlFrame public class HeadersFrame extends ControlFrame
{ {
private final int streamId; private final int streamId;
private final Headers headers; private final Fields headers;
public HeadersFrame(short version, byte flags, int streamId, Headers headers) public HeadersFrame(short version, byte flags, int streamId, Fields headers)
{ {
super(version, ControlFrameType.HEADERS, flags); super(version, ControlFrameType.HEADERS, flags);
this.streamId = streamId; this.streamId = streamId;
@ -38,7 +38,7 @@ public class HeadersFrame extends ControlFrame
return streamId; return streamId;
} }
public Headers getHeaders() public Fields getHeaders()
{ {
return headers; return headers;
} }

View File

@ -18,15 +18,15 @@
package org.eclipse.jetty.spdy.frames; package org.eclipse.jetty.spdy.frames;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.util.Fields;
public class SynReplyFrame extends ControlFrame public class SynReplyFrame extends ControlFrame
{ {
private final int streamId; private final int streamId;
private final Headers headers; private final Fields headers;
public SynReplyFrame(short version, byte flags, int streamId, Headers headers) public SynReplyFrame(short version, byte flags, int streamId, Fields headers)
{ {
super(version, ControlFrameType.SYN_REPLY, flags); super(version, ControlFrameType.SYN_REPLY, flags);
this.streamId = streamId; this.streamId = streamId;
@ -38,7 +38,7 @@ public class SynReplyFrame extends ControlFrame
return streamId; return streamId;
} }
public Headers getHeaders() public Fields getHeaders()
{ {
return headers; return headers;
} }

View File

@ -19,8 +19,8 @@
package org.eclipse.jetty.spdy.frames; package org.eclipse.jetty.spdy.frames;
import org.eclipse.jetty.spdy.PushSynInfo; import org.eclipse.jetty.spdy.PushSynInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.util.Fields;
public class SynStreamFrame extends ControlFrame public class SynStreamFrame extends ControlFrame
{ {
@ -28,9 +28,9 @@ public class SynStreamFrame extends ControlFrame
private final int associatedStreamId; private final int associatedStreamId;
private final byte priority; private final byte priority;
private final short slot; private final short slot;
private final Headers headers; private final Fields headers;
public SynStreamFrame(short version, byte flags, int streamId, int associatedStreamId, byte priority, short slot, Headers headers) public SynStreamFrame(short version, byte flags, int streamId, int associatedStreamId, byte priority, short slot, Fields headers)
{ {
super(version, ControlFrameType.SYN_STREAM, flags); super(version, ControlFrameType.SYN_STREAM, flags);
this.streamId = streamId; this.streamId = streamId;
@ -60,7 +60,7 @@ public class SynStreamFrame extends ControlFrame
return slot; return slot;
} }
public Headers getHeaders() public Fields getHeaders()
{ {
return headers; return headers;
} }

View File

@ -24,8 +24,8 @@ import java.nio.charset.Charset;
import org.eclipse.jetty.spdy.CompressionDictionary; import org.eclipse.jetty.spdy.CompressionDictionary;
import org.eclipse.jetty.spdy.CompressionFactory; import org.eclipse.jetty.spdy.CompressionFactory;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.util.Fields;
public class HeadersBlockGenerator public class HeadersBlockGenerator
{ {
@ -37,13 +37,13 @@ public class HeadersBlockGenerator
this.compressor = compressor; this.compressor = compressor;
} }
public ByteBuffer generate(short version, Headers headers) public ByteBuffer generate(short version, Fields headers)
{ {
// TODO: ByteArrayOutputStream is quite inefficient, but grows on demand; optimize using ByteBuffer ? // TODO: ByteArrayOutputStream is quite inefficient, but grows on demand; optimize using ByteBuffer ?
Charset iso1 = Charset.forName("ISO-8859-1"); Charset iso1 = Charset.forName("ISO-8859-1");
ByteArrayOutputStream buffer = new ByteArrayOutputStream(headers.size() * 64); ByteArrayOutputStream buffer = new ByteArrayOutputStream(headers.size() * 64);
writeCount(version, buffer, headers.size()); writeCount(version, buffer, headers.size());
for (Headers.Header header : headers) for (Fields.Field header : headers)
{ {
String name = header.name().toLowerCase(); String name = header.name().toLowerCase();
byte[] nameBytes = name.getBytes(iso1); byte[] nameBytes = name.getBytes(iso1);

View File

@ -21,15 +21,15 @@ package org.eclipse.jetty.spdy.parser;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.CompressionFactory; import org.eclipse.jetty.spdy.CompressionFactory;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo; import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.frames.ControlFrameType; import org.eclipse.jetty.spdy.frames.ControlFrameType;
import org.eclipse.jetty.spdy.frames.HeadersFrame; import org.eclipse.jetty.spdy.frames.HeadersFrame;
import org.eclipse.jetty.util.Fields;
public class HeadersBodyParser extends ControlFrameBodyParser public class HeadersBodyParser extends ControlFrameBodyParser
{ {
private final Headers headers = new Headers(); private final Fields headers = new Fields();
private final ControlFrameParser controlFrameParser; private final ControlFrameParser controlFrameParser;
private final HeadersBlockParser headersBlockParser; private final HeadersBlockParser headersBlockParser;
private State state = State.STREAM_ID; private State state = State.STREAM_ID;
@ -126,7 +126,7 @@ public class HeadersBodyParser extends ControlFrameBodyParser
if (flags != 0 && flags != HeadersInfo.FLAG_CLOSE && flags != HeadersInfo.FLAG_RESET_COMPRESSION) if (flags != 0 && flags != HeadersInfo.FLAG_CLOSE && flags != HeadersInfo.FLAG_RESET_COMPRESSION)
throw new IllegalArgumentException("Invalid flag " + flags + " for frame " + ControlFrameType.HEADERS); throw new IllegalArgumentException("Invalid flag " + flags + " for frame " + ControlFrameType.HEADERS);
HeadersFrame frame = new HeadersFrame(version, flags, streamId, new Headers(headers, true)); HeadersFrame frame = new HeadersFrame(version, flags, streamId, new Fields(headers, true));
controlFrameParser.onControlFrame(frame); controlFrameParser.onControlFrame(frame);
reset(); reset();

View File

@ -21,15 +21,15 @@ package org.eclipse.jetty.spdy.parser;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.CompressionFactory; import org.eclipse.jetty.spdy.CompressionFactory;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.frames.ControlFrameType; import org.eclipse.jetty.spdy.frames.ControlFrameType;
import org.eclipse.jetty.spdy.frames.SynReplyFrame; import org.eclipse.jetty.spdy.frames.SynReplyFrame;
import org.eclipse.jetty.util.Fields;
public class SynReplyBodyParser extends ControlFrameBodyParser public class SynReplyBodyParser extends ControlFrameBodyParser
{ {
private final Headers headers = new Headers(); private final Fields headers = new Fields();
private final ControlFrameParser controlFrameParser; private final ControlFrameParser controlFrameParser;
private final HeadersBlockParser headersBlockParser; private final HeadersBlockParser headersBlockParser;
private State state = State.STREAM_ID; private State state = State.STREAM_ID;
@ -124,7 +124,7 @@ public class SynReplyBodyParser extends ControlFrameBodyParser
if (flags != 0 && flags != ReplyInfo.FLAG_CLOSE) if (flags != 0 && flags != ReplyInfo.FLAG_CLOSE)
throw new IllegalArgumentException("Invalid flag " + flags + " for frame " + ControlFrameType.SYN_REPLY); throw new IllegalArgumentException("Invalid flag " + flags + " for frame " + ControlFrameType.SYN_REPLY);
SynReplyFrame frame = new SynReplyFrame(version, flags, streamId, new Headers(headers, true)); SynReplyFrame frame = new SynReplyFrame(version, flags, streamId, new Fields(headers, true));
controlFrameParser.onControlFrame(frame); controlFrameParser.onControlFrame(frame);
reset(); reset();

View File

@ -23,16 +23,16 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.CompressionFactory; import org.eclipse.jetty.spdy.CompressionFactory;
import org.eclipse.jetty.spdy.PushSynInfo; import org.eclipse.jetty.spdy.PushSynInfo;
import org.eclipse.jetty.spdy.StreamException; import org.eclipse.jetty.spdy.StreamException;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.StreamStatus; import org.eclipse.jetty.spdy.api.StreamStatus;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.frames.ControlFrameType; import org.eclipse.jetty.spdy.frames.ControlFrameType;
import org.eclipse.jetty.spdy.frames.SynStreamFrame; import org.eclipse.jetty.spdy.frames.SynStreamFrame;
import org.eclipse.jetty.util.Fields;
public class SynStreamBodyParser extends ControlFrameBodyParser public class SynStreamBodyParser extends ControlFrameBodyParser
{ {
private final Headers headers = new Headers(); private final Fields headers = new Fields();
private final ControlFrameParser controlFrameParser; private final ControlFrameParser controlFrameParser;
private final HeadersBlockParser headersBlockParser; private final HeadersBlockParser headersBlockParser;
private State state = State.STREAM_ID; private State state = State.STREAM_ID;
@ -139,7 +139,7 @@ public class SynStreamBodyParser extends ControlFrameBodyParser
if (flags > (SynInfo.FLAG_CLOSE | PushSynInfo.FLAG_UNIDIRECTIONAL)) if (flags > (SynInfo.FLAG_CLOSE | PushSynInfo.FLAG_UNIDIRECTIONAL))
throw new IllegalArgumentException("Invalid flag " + flags + " for frame " + ControlFrameType.SYN_STREAM); throw new IllegalArgumentException("Invalid flag " + flags + " for frame " + ControlFrameType.SYN_STREAM);
SynStreamFrame frame = new SynStreamFrame(version, flags, streamId, associatedStreamId, priority, slot, new Headers(headers, true)); SynStreamFrame frame = new SynStreamFrame(version, flags, streamId, associatedStreamId, priority, slot, new Fields(headers, true));
controlFrameParser.onControlFrame(frame); controlFrameParser.onControlFrame(frame);
reset(); reset();

View File

@ -32,7 +32,6 @@ import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.spdy.StandardSession.FrameBytes; import org.eclipse.jetty.spdy.StandardSession.FrameBytes;
import org.eclipse.jetty.spdy.api.ByteBufferDataInfo; import org.eclipse.jetty.spdy.api.ByteBufferDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo; import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.RstInfo; import org.eclipse.jetty.spdy.api.RstInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
@ -47,6 +46,7 @@ import org.eclipse.jetty.spdy.frames.SynReplyFrame;
import org.eclipse.jetty.spdy.frames.SynStreamFrame; import org.eclipse.jetty.spdy.frames.SynStreamFrame;
import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.util.thread.TimerScheduler; import org.eclipse.jetty.util.thread.TimerScheduler;
import org.junit.After; import org.junit.After;
@ -79,7 +79,7 @@ public class StandardSessionTest
private StandardSession session; private StandardSession session;
private Generator generator; private Generator generator;
private Scheduler scheduler; private Scheduler scheduler;
private Headers headers; private Fields headers;
@Before @Before
public void setUp() throws Exception public void setUp() throws Exception
@ -90,7 +90,7 @@ public class StandardSessionTest
scheduler.start(); scheduler.start();
generator = new Generator(bufferPool, new StandardCompressionFactory.StandardCompressor()); generator = new Generator(bufferPool, new StandardCompressionFactory.StandardCompressor());
session = new StandardSession(SPDY.V2,bufferPool,threadPool,scheduler,controller,null,1,null,generator,new FlowControlStrategy.None()); session = new StandardSession(SPDY.V2,bufferPool,threadPool,scheduler,controller,null,1,null,generator,new FlowControlStrategy.None());
headers = new Headers(); headers = new Fields();
} }
@After @After

View File

@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.spdy.StandardSession; import org.eclipse.jetty.spdy.StandardSession;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -119,7 +120,7 @@ public class ClientUsageTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
// Do something with the response // Do something with the response
Headers headers = replyInfo.getHeaders(); Fields headers = replyInfo.getHeaders();
int contentLength = headers.get("content-length").valueAsInt(); int contentLength = headers.get("content-length").valueAsInt();
stream.setAttribute("content-length", contentLength); stream.setAttribute("content-length", contentLength);
if (!replyInfo.isClose()) if (!replyInfo.isClose())

View File

@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -36,12 +37,12 @@ public class ServerUsageTest
@Override @Override
public StreamFrameListener onSyn(Stream stream, SynInfo streamInfo) public StreamFrameListener onSyn(Stream stream, SynInfo streamInfo)
{ {
Headers synHeaders = streamInfo.getHeaders(); Fields synHeaders = streamInfo.getHeaders();
// Do something with headers, for example extract them and // Do something with headers, for example extract them and
// perform an http request via Jetty's LocalConnector // perform an http request via Jetty's LocalConnector
// Get the http response, fill headers and data // Get the http response, fill headers and data
Headers replyHeaders = new Headers(); Fields replyHeaders = new Fields();
replyHeaders.put(synHeaders.get("host")); replyHeaders.put(synHeaders.get("host"));
// Sends a reply // Sends a reply
stream.reply(new ReplyInfo(replyHeaders, false)); stream.reply(new ReplyInfo(replyHeaders, false));
@ -82,7 +83,7 @@ public class ServerUsageTest
// the client sends a rst frame. // the client sends a rst frame.
// We have to atomically set some flag on the stream to signal it's closed // We have to atomically set some flag on the stream to signal it's closed
// and any operation on it will throw // and any operation on it will throw
stream.headers(new HeadersInfo(new Headers(), true)); stream.headers(new HeadersInfo(new Fields(), true));
} }
}); });
} }
@ -102,7 +103,7 @@ public class ServerUsageTest
Session session = stream.getSession(); Session session = stream.getSession();
// Since it's unidirectional, no need to pass the listener // Since it's unidirectional, no need to pass the listener
session.syn(new SynInfo(new Headers(), false, (byte)0), null, 0, TimeUnit.MILLISECONDS, new Callback.Empty<Stream>() session.syn(new SynInfo(new Fields(), false, (byte)0), null, 0, TimeUnit.MILLISECONDS, new Callback.Empty<Stream>()
{ {
@Override @Override
public void completed(Stream pushStream) public void completed(Stream pushStream)

View File

@ -22,11 +22,11 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.spdy.StandardCompressionFactory; import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo; import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser; import org.eclipse.jetty.spdy.parser.Parser;
import org.eclipse.jetty.util.Fields;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -37,7 +37,7 @@ import static org.junit.Assert.assertThat;
public class HeadersGenerateParseTest public class HeadersGenerateParseTest
{ {
private Headers headers = new Headers(); private Fields headers = new Fields();
private int streamId = 13; private int streamId = 13;
private byte flags = HeadersInfo.FLAG_RESET_COMPRESSION; private byte flags = HeadersInfo.FLAG_RESET_COMPRESSION;
private final TestSPDYParserListener listener = new TestSPDYParserListener(); private final TestSPDYParserListener listener = new TestSPDYParserListener();
@ -52,7 +52,7 @@ public class HeadersGenerateParseTest
buffer = createHeadersFrameBuffer(headers); buffer = createHeadersFrameBuffer(headers);
} }
private ByteBuffer createHeadersFrameBuffer(Headers headers) private ByteBuffer createHeadersFrameBuffer(Fields headers)
{ {
HeadersFrame frame1 = new HeadersFrame(SPDY.V2, flags, streamId, headers); HeadersFrame frame1 = new HeadersFrame(SPDY.V2, flags, streamId, headers);
Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory().newCompressor()); Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory().newCompressor());
@ -80,15 +80,15 @@ public class HeadersGenerateParseTest
@Test @Test
public void testHeadersAreTranslatedToLowerCase() public void testHeadersAreTranslatedToLowerCase()
{ {
Headers headers = new Headers(); Fields headers = new Fields();
headers.put("Via","localhost"); headers.put("Via","localhost");
parser.parse(createHeadersFrameBuffer(headers)); parser.parse(createHeadersFrameBuffer(headers));
HeadersFrame parsedHeadersFrame = assertExpectationsAreMet(headers); HeadersFrame parsedHeadersFrame = assertExpectationsAreMet(headers);
Headers.Header viaHeader = parsedHeadersFrame.getHeaders().get("via"); Fields.Field viaHeader = parsedHeadersFrame.getHeaders().get("via");
assertThat("Via Header name is lowercase", viaHeader.name(), is("via")); assertThat("Via Header name is lowercase", viaHeader.name(), is("via"));
} }
private HeadersFrame assertExpectationsAreMet(Headers headers) private HeadersFrame assertExpectationsAreMet(Fields headers)
{ {
ControlFrame parsedControlFrame = listener.getControlFrame(); ControlFrame parsedControlFrame = listener.getControlFrame();
assertThat("listener received controlFrame", parsedControlFrame, notNullValue()); assertThat("listener received controlFrame", parsedControlFrame, notNullValue());

View File

@ -22,11 +22,11 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.spdy.StandardCompressionFactory; import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser; import org.eclipse.jetty.spdy.parser.Parser;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -37,7 +37,7 @@ public class SynReplyGenerateParseTest
{ {
byte flags = ReplyInfo.FLAG_CLOSE; byte flags = ReplyInfo.FLAG_CLOSE;
int streamId = 13; int streamId = 13;
Headers headers = new Headers(); Fields headers = new Fields();
headers.put("a", "b"); headers.put("a", "b");
SynReplyFrame frame1 = new SynReplyFrame(SPDY.V2, flags, streamId, headers); SynReplyFrame frame1 = new SynReplyFrame(SPDY.V2, flags, streamId, headers);
Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory().newCompressor()); Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory().newCompressor());
@ -65,7 +65,7 @@ public class SynReplyGenerateParseTest
{ {
byte flags = ReplyInfo.FLAG_CLOSE; byte flags = ReplyInfo.FLAG_CLOSE;
int streamId = 13; int streamId = 13;
Headers headers = new Headers(); Fields headers = new Fields();
headers.put("a", "b"); headers.put("a", "b");
SynReplyFrame frame1 = new SynReplyFrame(SPDY.V2, flags, streamId, headers); SynReplyFrame frame1 = new SynReplyFrame(SPDY.V2, flags, streamId, headers);
Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory().newCompressor()); Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory().newCompressor());

View File

@ -22,11 +22,11 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.spdy.StandardCompressionFactory; import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser; import org.eclipse.jetty.spdy.parser.Parser;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -40,7 +40,7 @@ public class SynStreamGenerateParseTest
int associatedStreamId = 11; int associatedStreamId = 11;
byte priority = 3; byte priority = 3;
short slot = 5; short slot = 5;
Headers headers = new Headers(); Fields headers = new Fields();
headers.put("a", "b"); headers.put("a", "b");
headers.put("c", "d"); headers.put("c", "d");
SynStreamFrame frame1 = new SynStreamFrame(SPDY.V2, flags, streamId, associatedStreamId, priority, slot, headers); SynStreamFrame frame1 = new SynStreamFrame(SPDY.V2, flags, streamId, associatedStreamId, priority, slot, headers);
@ -75,7 +75,7 @@ public class SynStreamGenerateParseTest
int associatedStreamId = 11; int associatedStreamId = 11;
byte priority = 3; byte priority = 3;
short slot = 5; short slot = 5;
Headers headers = new Headers(); Fields headers = new Fields();
headers.put("a", "b"); headers.put("a", "b");
headers.put("c", "d"); headers.put("c", "d");
SynStreamFrame frame1 = new SynStreamFrame(SPDY.V2, flags, streamId, associatedStreamId, priority, slot, headers); SynStreamFrame frame1 = new SynStreamFrame(SPDY.V2, flags, streamId, associatedStreamId, priority, slot, headers);

View File

@ -26,13 +26,13 @@ import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.spdy.SessionException; import org.eclipse.jetty.spdy.SessionException;
import org.eclipse.jetty.spdy.StandardCompressionFactory; import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.StreamException; import org.eclipse.jetty.spdy.StreamException;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.frames.ControlFrame; import org.eclipse.jetty.spdy.frames.ControlFrame;
import org.eclipse.jetty.spdy.frames.DataFrame; import org.eclipse.jetty.spdy.frames.DataFrame;
import org.eclipse.jetty.spdy.frames.SynStreamFrame; import org.eclipse.jetty.spdy.frames.SynStreamFrame;
import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -41,7 +41,7 @@ public class UnknownControlFrameTest
@Test @Test
public void testUnknownControlFrame() throws Exception public void testUnknownControlFrame() throws Exception
{ {
SynStreamFrame frame = new SynStreamFrame(SPDY.V2, SynInfo.FLAG_CLOSE, 1, 0, (byte)0, (short)0, new Headers()); SynStreamFrame frame = new SynStreamFrame(SPDY.V2, SynInfo.FLAG_CLOSE, 1, 0, (byte)0, (short)0, new Fields());
Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor()); Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor());
ByteBuffer buffer = generator.control(frame); ByteBuffer buffer = generator.control(frame);
// Change the frame type to unknown // Change the frame type to unknown

View File

@ -32,8 +32,8 @@ import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpTransport; import org.eclipse.jetty.server.HttpTransport;
import org.eclipse.jetty.spdy.api.ByteBufferDataInfo; import org.eclipse.jetty.spdy.api.ByteBufferDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -97,13 +97,13 @@ public class HttpChannelOverSPDY extends HttpChannel<DataInfo>
} }
} }
public void requestStart(final Headers headers, final boolean endRequest) public void requestStart(final Fields headers, final boolean endRequest)
{ {
if (!headers.isEmpty()) if (!headers.isEmpty())
requestHeaders(headers, endRequest); requestHeaders(headers, endRequest);
} }
public void requestHeaders(Headers headers, boolean endRequest) public void requestHeaders(Fields headers, boolean endRequest)
{ {
boolean proceed = performBeginRequest(headers); boolean proceed = performBeginRequest(headers);
if (!proceed) if (!proceed)
@ -155,12 +155,12 @@ public class HttpChannelOverSPDY extends HttpChannel<DataInfo>
} }
} }
private boolean performBeginRequest(Headers headers) private boolean performBeginRequest(Fields headers)
{ {
short version = stream.getSession().getVersion(); short version = stream.getSession().getVersion();
Headers.Header methodHeader = headers.get(HTTPSPDYHeader.METHOD.name(version)); Fields.Field methodHeader = headers.get(HTTPSPDYHeader.METHOD.name(version));
Headers.Header uriHeader = headers.get(HTTPSPDYHeader.URI.name(version)); Fields.Field uriHeader = headers.get(HTTPSPDYHeader.URI.name(version));
Headers.Header versionHeader = headers.get(HTTPSPDYHeader.VERSION.name(version)); Fields.Field versionHeader = headers.get(HTTPSPDYHeader.VERSION.name(version));
if (methodHeader == null || uriHeader == null || versionHeader == null) if (methodHeader == null || uriHeader == null || versionHeader == null)
{ {
@ -175,15 +175,15 @@ public class HttpChannelOverSPDY extends HttpChannel<DataInfo>
LOG.debug("HTTP > {} {} {}", httpMethod, uriString, httpVersion); LOG.debug("HTTP > {} {} {}", httpMethod, uriString, httpVersion);
startRequest(httpMethod, httpMethod.asString(), uriString, httpVersion); startRequest(httpMethod, httpMethod.asString(), uriString, httpVersion);
Headers.Header schemeHeader = headers.get(HTTPSPDYHeader.SCHEME.name(version)); Fields.Field schemeHeader = headers.get(HTTPSPDYHeader.SCHEME.name(version));
if (schemeHeader != null) if (schemeHeader != null)
getRequest().setScheme(schemeHeader.value()); getRequest().setScheme(schemeHeader.value());
return true; return true;
} }
private void performHeaders(Headers headers) private void performHeaders(Fields headers)
{ {
for (Headers.Header header : headers) for (Fields.Field header : headers)
{ {
String name = header.name(); String name = header.name();
HttpHeader httpHeader = HttpHeader.CACHE.get(name); HttpHeader httpHeader = HttpHeader.CACHE.get(name);

View File

@ -32,13 +32,13 @@ import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpTransport; import org.eclipse.jetty.server.HttpTransport;
import org.eclipse.jetty.spdy.api.ByteBufferDataInfo; import org.eclipse.jetty.spdy.api.ByteBufferDataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -51,9 +51,9 @@ public class HttpTransportOverSPDY implements HttpTransport
private final EndPoint endPoint; private final EndPoint endPoint;
private final PushStrategy pushStrategy; private final PushStrategy pushStrategy;
private final Stream stream; private final Stream stream;
private final Headers requestHeaders; private final Fields requestHeaders;
public HttpTransportOverSPDY(Connector connector, HttpConfiguration configuration, EndPoint endPoint, PushStrategy pushStrategy, Stream stream, Headers requestHeaders) public HttpTransportOverSPDY(Connector connector, HttpConfiguration configuration, EndPoint endPoint, PushStrategy pushStrategy, Stream stream, Fields requestHeaders)
{ {
this.connector = connector; this.connector = connector;
this.configuration = configuration; this.configuration = configuration;
@ -67,7 +67,7 @@ public class HttpTransportOverSPDY implements HttpTransport
public void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent) throws IOException public void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent) throws IOException
{ {
short version = stream.getSession().getVersion(); short version = stream.getSession().getVersion();
Headers headers = new Headers(); Fields headers = new Fields();
HttpVersion httpVersion = HttpVersion.HTTP_1_1; HttpVersion httpVersion = HttpVersion.HTTP_1_1;
headers.put(HTTPSPDYHeader.VERSION.name(version), httpVersion.asString()); headers.put(HTTPSPDYHeader.VERSION.name(version), httpVersion.asString());
@ -126,20 +126,20 @@ public class HttpTransportOverSPDY implements HttpTransport
if (!stream.isUnidirectional()) if (!stream.isUnidirectional())
stream.reply(replyInfo); stream.reply(replyInfo);
Headers responseHeaders = replyInfo.getHeaders(); Fields responseHeaders = replyInfo.getHeaders();
short version = stream.getSession().getVersion(); short version = stream.getSession().getVersion();
if (responseHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().startsWith("200") && !stream.isClosed()) if (responseHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().startsWith("200") && !stream.isClosed())
{ {
// We have a 200 OK with some content to send, check the push strategy // We have a 200 OK with some content to send, check the push strategy
Headers.Header scheme = requestHeaders.get(HTTPSPDYHeader.SCHEME.name(version)); Fields.Field scheme = requestHeaders.get(HTTPSPDYHeader.SCHEME.name(version));
Headers.Header host = requestHeaders.get(HTTPSPDYHeader.HOST.name(version)); Fields.Field host = requestHeaders.get(HTTPSPDYHeader.HOST.name(version));
Headers.Header uri = requestHeaders.get(HTTPSPDYHeader.URI.name(version)); Fields.Field uri = requestHeaders.get(HTTPSPDYHeader.URI.name(version));
Set<String> pushResources = pushStrategy.apply(stream, requestHeaders, responseHeaders); Set<String> pushResources = pushStrategy.apply(stream, requestHeaders, responseHeaders);
for (String pushResource : pushResources) for (String pushResource : pushResources)
{ {
Headers pushHeaders = createPushHeaders(scheme, host, pushResource); Fields pushHeaders = createPushHeaders(scheme, host, pushResource);
final Headers pushRequestHeaders = createRequestHeaders(scheme, host, uri, pushResource); final Fields pushRequestHeaders = createRequestHeaders(scheme, host, uri, pushResource);
// TODO: handle the timeout better // TODO: handle the timeout better
stream.syn(new SynInfo(pushHeaders, false), 0, TimeUnit.MILLISECONDS, new Callback.Empty<Stream>() stream.syn(new SynInfo(pushHeaders, false), 0, TimeUnit.MILLISECONDS, new Callback.Empty<Stream>()
@ -155,9 +155,9 @@ public class HttpTransportOverSPDY implements HttpTransport
} }
} }
private Headers createRequestHeaders(Headers.Header scheme, Headers.Header host, Headers.Header uri, String pushResourcePath) private Fields createRequestHeaders(Fields.Field scheme, Fields.Field host, Fields.Field uri, String pushResourcePath)
{ {
final Headers requestHeaders = new Headers(); final Fields requestHeaders = new Fields();
short version = stream.getSession().getVersion(); short version = stream.getSession().getVersion();
requestHeaders.put(HTTPSPDYHeader.METHOD.name(version), "GET"); requestHeaders.put(HTTPSPDYHeader.METHOD.name(version), "GET");
requestHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); requestHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -172,9 +172,9 @@ public class HttpTransportOverSPDY implements HttpTransport
return requestHeaders; return requestHeaders;
} }
private Headers createPushHeaders(Headers.Header scheme, Headers.Header host, String pushResourcePath) private Fields createPushHeaders(Fields.Field scheme, Fields.Field host, String pushResourcePath)
{ {
final Headers pushHeaders = new Headers(); final Fields pushHeaders = new Fields();
short version = stream.getSession().getVersion(); short version = stream.getSession().getVersion();
if (version == SPDY.V2) if (version == SPDY.V2)
pushHeaders.put(HTTPSPDYHeader.URI.name(version), scheme.value() + "://" + host.value() + pushResourcePath); pushHeaders.put(HTTPSPDYHeader.URI.name(version), scheme.value() + "://" + host.value() + pushResourcePath);
@ -189,7 +189,7 @@ public class HttpTransportOverSPDY implements HttpTransport
return pushHeaders; return pushHeaders;
} }
private HttpChannelOverSPDY newHttpChannelOverSPDY(Stream pushStream, Headers pushRequestHeaders) private HttpChannelOverSPDY newHttpChannelOverSPDY(Stream pushStream, Fields pushRequestHeaders)
{ {
HttpTransport transport = new HttpTransportOverSPDY(connector, configuration, endPoint, pushStrategy, pushStream, pushRequestHeaders); HttpTransport transport = new HttpTransportOverSPDY(connector, configuration, endPoint, pushStrategy, pushStream, pushRequestHeaders);
HttpInputOverSPDY input = new HttpInputOverSPDY(); HttpInputOverSPDY input = new HttpInputOverSPDY();

View File

@ -22,8 +22,8 @@ package org.eclipse.jetty.spdy.http;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.util.Fields;
/** /**
* <p>{@link PushStrategy} encapsulates the decisions about performing * <p>{@link PushStrategy} encapsulates the decisions about performing
@ -39,7 +39,7 @@ public interface PushStrategy
* @param responseHeaders the primary resource response headers * @param responseHeaders the primary resource response headers
* @return a list of secondary resource URIs to push * @return a list of secondary resource URIs to push
*/ */
public Set<String> apply(Stream stream, Headers requestHeaders, Headers responseHeaders); public Set<String> apply(Stream stream, Fields requestHeaders, Fields responseHeaders);
/** /**
* An implementation that returns an empty list of secondary resources * An implementation that returns an empty list of secondary resources
@ -47,7 +47,7 @@ public interface PushStrategy
public static class None implements PushStrategy public static class None implements PushStrategy
{ {
@Override @Override
public Set<String> apply(Stream stream, Headers requestHeaders, Headers responseHeaders) public Set<String> apply(Stream stream, Fields requestHeaders, Fields responseHeaders)
{ {
return Collections.emptySet(); return Collections.emptySet();
} }

View File

@ -30,8 +30,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -119,7 +119,7 @@ public class ReferrerPushStrategy implements PushStrategy
} }
@Override @Override
public Set<String> apply(Stream stream, Headers requestHeaders, Headers responseHeaders) public Set<String> apply(Stream stream, Fields requestHeaders, Fields responseHeaders)
{ {
Set<String> result = Collections.<String>emptySet(); Set<String> result = Collections.<String>emptySet();
short version = stream.getSession().getVersion(); short version = stream.getSession().getVersion();
@ -138,7 +138,7 @@ public class ReferrerPushStrategy implements PushStrategy
} }
else if (isPushResource(url, responseHeaders)) else if (isPushResource(url, responseHeaders))
{ {
Headers.Header referrerHeader = requestHeaders.get("referer"); Fields.Field referrerHeader = requestHeaders.get("referer");
if (referrerHeader != null) if (referrerHeader != null)
{ {
String referrer = referrerHeader.value(); String referrer = referrerHeader.value();
@ -180,7 +180,7 @@ public class ReferrerPushStrategy implements PushStrategy
return mainResource; return mainResource;
} }
private boolean isIfModifiedSinceHeaderPresent(Headers headers) private boolean isIfModifiedSinceHeaderPresent(Fields headers)
{ {
return headers.get("if-modified-since") != null; return headers.get("if-modified-since") != null;
} }
@ -190,18 +190,18 @@ public class ReferrerPushStrategy implements PushStrategy
return "GET".equalsIgnoreCase(method); return "GET".equalsIgnoreCase(method);
} }
private boolean isMainResource(String url, Headers responseHeaders) private boolean isMainResource(String url, Fields responseHeaders)
{ {
return !isPushResource(url, responseHeaders); return !isPushResource(url, responseHeaders);
} }
private boolean isPushResource(String url, Headers responseHeaders) private boolean isPushResource(String url, Fields responseHeaders)
{ {
for (Pattern pushRegexp : pushRegexps) for (Pattern pushRegexp : pushRegexps)
{ {
if (pushRegexp.matcher(url).matches()) if (pushRegexp.matcher(url).matches())
{ {
Headers.Header header = responseHeaders.get("content-type"); Fields.Field header = responseHeaders.get("content-type");
if (header == null) if (header == null)
return true; return true;

View File

@ -27,13 +27,13 @@ import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.spdy.ServerSPDYConnectionFactory; import org.eclipse.jetty.spdy.ServerSPDYConnectionFactory;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo; import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.util.thread.Scheduler;
@ -81,7 +81,7 @@ public class ServerHTTPSPDYConnectionFactory extends ServerSPDYConnectionFactory
logger.debug("Received {} on {}", synInfo, stream); logger.debug("Received {} on {}", synInfo, stream);
Headers headers = synInfo.getHeaders(); Fields headers = synInfo.getHeaders();
HttpTransportOverSPDY transport = new HttpTransportOverSPDY(connector, configuration, endPoint, pushStrategy, stream, headers); HttpTransportOverSPDY transport = new HttpTransportOverSPDY(connector, configuration, endPoint, pushStrategy, stream, headers);
HttpInputOverSPDY input = new HttpInputOverSPDY(); HttpInputOverSPDY input = new HttpInputOverSPDY();
HttpChannelOverSPDY channel = new HttpChannelOverSPDY(connector, configuration, endPoint, transport, input, stream); HttpChannelOverSPDY channel = new HttpChannelOverSPDY(connector, configuration, endPoint, transport, input, stream);

View File

@ -23,10 +23,10 @@ import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -71,7 +71,7 @@ public abstract class ProxyEngine
return name; return name;
} }
protected void addRequestProxyHeaders(Stream stream, Headers headers) protected void addRequestProxyHeaders(Stream stream, Fields headers)
{ {
addViaHeader(headers); addViaHeader(headers);
InetSocketAddress address = (InetSocketAddress)stream.getSession().getAttribute("org.eclipse.jetty.spdy.remoteAddress"); InetSocketAddress address = (InetSocketAddress)stream.getSession().getAttribute("org.eclipse.jetty.spdy.remoteAddress");
@ -79,21 +79,21 @@ public abstract class ProxyEngine
headers.add("X-Forwarded-For", address.getHostName()); headers.add("X-Forwarded-For", address.getHostName());
} }
protected void addResponseProxyHeaders(Stream stream, Headers headers) protected void addResponseProxyHeaders(Stream stream, Fields headers)
{ {
addViaHeader(headers); addViaHeader(headers);
} }
private void addViaHeader(Headers headers) private void addViaHeader(Fields headers)
{ {
headers.add("Via", "http/1.1 " + getName()); headers.add("Via", "http/1.1 " + getName());
} }
protected void customizeRequestHeaders(Stream stream, Headers headers) protected void customizeRequestHeaders(Stream stream, Fields headers)
{ {
} }
protected void customizeResponseHeaders(Stream stream, Headers headers) protected void customizeResponseHeaders(Stream stream, Fields headers)
{ {
} }

View File

@ -24,7 +24,6 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jetty.spdy.api.GoAwayInfo; import org.eclipse.jetty.spdy.api.GoAwayInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.PingInfo; import org.eclipse.jetty.spdy.api.PingInfo;
import org.eclipse.jetty.spdy.api.RstInfo; import org.eclipse.jetty.spdy.api.RstInfo;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
@ -34,6 +33,7 @@ import org.eclipse.jetty.spdy.api.StreamStatus;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.eclipse.jetty.spdy.http.HTTPSPDYHeader; import org.eclipse.jetty.spdy.http.HTTPSPDYHeader;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -60,9 +60,9 @@ public class ProxyEngineSelector extends ServerSessionFrameListener.Adapter
final Session clientSession = clientStream.getSession(); final Session clientSession = clientStream.getSession();
short clientVersion = clientSession.getVersion(); short clientVersion = clientSession.getVersion();
Headers headers = new Headers(clientSynInfo.getHeaders(), false); Fields headers = new Fields(clientSynInfo.getHeaders(), false);
Headers.Header hostHeader = headers.get(HTTPSPDYHeader.HOST.name(clientVersion)); Fields.Field hostHeader = headers.get(HTTPSPDYHeader.HOST.name(clientVersion));
if (hostHeader == null) if (hostHeader == null)
{ {
logger.debug("No host header found: " + headers); logger.debug("No host header found: " + headers);

View File

@ -41,7 +41,6 @@ import org.eclipse.jetty.spdy.StandardStream;
import org.eclipse.jetty.spdy.api.ByteBufferDataInfo; import org.eclipse.jetty.spdy.api.ByteBufferDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.GoAwayInfo; import org.eclipse.jetty.spdy.api.GoAwayInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo; import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.RstInfo; import org.eclipse.jetty.spdy.api.RstInfo;
@ -51,11 +50,12 @@ import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.http.HTTPSPDYHeader; import org.eclipse.jetty.spdy.http.HTTPSPDYHeader;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParser.RequestHandler<ByteBuffer> public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParser.RequestHandler<ByteBuffer>
{ {
private final short version; private final short version;
private final Headers headers = new Headers(); private final Fields headers = new Fields();
private final ProxyEngineSelector proxyEngineSelector; private final ProxyEngineSelector proxyEngineSelector;
private final ISession session; private final ISession session;
private HTTPStream stream; private HTTPStream stream;
@ -230,7 +230,7 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
{ {
try try
{ {
Headers headers = new Headers(replyInfo.getHeaders(), false); Fields headers = new Fields(replyInfo.getHeaders(), false);
headers.remove(HTTPSPDYHeader.SCHEME.name(version)); headers.remove(HTTPSPDYHeader.SCHEME.name(version));
@ -243,12 +243,12 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
HttpVersion httpVersion = HttpVersion.fromString(headers.remove(HTTPSPDYHeader.VERSION.name(version)).value()); HttpVersion httpVersion = HttpVersion.fromString(headers.remove(HTTPSPDYHeader.VERSION.name(version)).value());
// Convert the Host header from a SPDY special header to a normal header // Convert the Host header from a SPDY special header to a normal header
Headers.Header host = headers.remove(HTTPSPDYHeader.HOST.name(version)); Fields.Field host = headers.remove(HTTPSPDYHeader.HOST.name(version));
if (host != null) if (host != null)
headers.put("host", host.value()); headers.put("host", host.value());
HttpFields fields = new HttpFields(); HttpFields fields = new HttpFields();
for (Headers.Header header : headers) for (Fields.Field header : headers)
{ {
String name = camelize(header.name()); String name = camelize(header.name());
fields.put(name, header.value()); fields.put(name, header.value());

View File

@ -30,7 +30,6 @@ import org.eclipse.jetty.spdy.SPDYClient;
import org.eclipse.jetty.spdy.api.ByteBufferDataInfo; import org.eclipse.jetty.spdy.api.ByteBufferDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.GoAwayInfo; import org.eclipse.jetty.spdy.api.GoAwayInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo; import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.RstInfo; import org.eclipse.jetty.spdy.api.RstInfo;
@ -43,6 +42,7 @@ import org.eclipse.jetty.spdy.api.StreamStatus;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.http.HTTPSPDYHeader; import org.eclipse.jetty.spdy.http.HTTPSPDYHeader;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
/** /**
* <p>{@link SPDYProxyEngine} implements a SPDY to SPDY proxy, that is, converts SPDY events received by * <p>{@link SPDYProxyEngine} implements a SPDY to SPDY proxy, that is, converts SPDY events received by
@ -86,7 +86,7 @@ public class SPDYProxyEngine extends ProxyEngine implements StreamFrameListener
public StreamFrameListener proxy(final Stream clientStream, SynInfo clientSynInfo, ProxyEngineSelector.ProxyServerInfo proxyServerInfo) public StreamFrameListener proxy(final Stream clientStream, SynInfo clientSynInfo, ProxyEngineSelector.ProxyServerInfo proxyServerInfo)
{ {
Headers headers = new Headers(clientSynInfo.getHeaders(), false); Fields headers = new Fields(clientSynInfo.getHeaders(), false);
short serverVersion = getVersion(proxyServerInfo.getProtocol()); short serverVersion = getVersion(proxyServerInfo.getProtocol());
InetSocketAddress address = proxyServerInfo.getAddress(); InetSocketAddress address = proxyServerInfo.getAddress();
@ -182,13 +182,13 @@ public class SPDYProxyEngine extends ProxyEngine implements StreamFrameListener
} }
} }
private void convert(short fromVersion, short toVersion, Headers headers) private void convert(short fromVersion, short toVersion, Fields headers)
{ {
if (fromVersion != toVersion) if (fromVersion != toVersion)
{ {
for (HTTPSPDYHeader httpHeader : HTTPSPDYHeader.values()) for (HTTPSPDYHeader httpHeader : HTTPSPDYHeader.values())
{ {
Headers.Header header = headers.remove(httpHeader.name(fromVersion)); Fields.Field header = headers.remove(httpHeader.name(fromVersion));
if (header != null) if (header != null)
{ {
String toName = httpHeader.name(toVersion); String toName = httpHeader.name(toVersion);
@ -221,7 +221,7 @@ public class SPDYProxyEngine extends ProxyEngine implements StreamFrameListener
logger.debug("S -> P {} on {}", replyInfo, stream); logger.debug("S -> P {} on {}", replyInfo, stream);
short serverVersion = stream.getSession().getVersion(); short serverVersion = stream.getSession().getVersion();
Headers headers = new Headers(replyInfo.getHeaders(), false); Fields headers = new Fields(replyInfo.getHeaders(), false);
addResponseProxyHeaders(stream, headers); addResponseProxyHeaders(stream, headers);
customizeResponseHeaders(stream, headers); customizeResponseHeaders(stream, headers);
@ -449,7 +449,7 @@ public class SPDYProxyEngine extends ProxyEngine implements StreamFrameListener
{ {
logger.debug("S -> P pushed {} on {}", serverSynInfo, serverStream); logger.debug("S -> P pushed {} on {}", serverSynInfo, serverStream);
Headers headers = new Headers(serverSynInfo.getHeaders(), false); Fields headers = new Fields(serverSynInfo.getHeaders(), false);
addResponseProxyHeaders(serverStream, headers); addResponseProxyHeaders(serverStream, headers);
customizeResponseHeaders(serverStream, headers); customizeResponseHeaders(serverStream, headers);

View File

@ -27,12 +27,12 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -79,7 +79,7 @@ public class ConcurrentStreamsTest extends AbstractHTTPSPDYTest
}), null); }), null);
// Perform slow request. This will wait on server side until the fast request wakes it up // Perform slow request. This will wait on server side until the fast request wakes it up
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/slow"); headers.put(HTTPSPDYHeader.URI.name(version), "/slow");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -90,7 +90,7 @@ public class ConcurrentStreamsTest extends AbstractHTTPSPDYTest
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
slowClientLatch.countDown(); slowClientLatch.countDown();
} }
@ -108,7 +108,7 @@ public class ConcurrentStreamsTest extends AbstractHTTPSPDYTest
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
fastClientLatch.countDown(); fastClientLatch.countDown();
} }

View File

@ -36,13 +36,13 @@ import junit.framework.Assert;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.SessionFrameListener; import org.eclipse.jetty.spdy.api.SessionFrameListener;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.util.Fields;
import org.junit.Ignore; import org.junit.Ignore;
@Ignore // TODO: update when jetty client is available @Ignore // TODO: update when jetty client is available
@ -215,7 +215,7 @@ public class PushStrategyBenchmarkTest extends AbstractHTTPSPDYTest
String primaryPath = "/" + j + ".html"; String primaryPath = "/" + j + ".html";
String referrer = new StringBuilder("http://localhost:").append(connector.getLocalPort()).append(primaryPath).toString(); String referrer = new StringBuilder("http://localhost:").append(connector.getLocalPort()).append(primaryPath).toString();
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), primaryPath); headers.put(HTTPSPDYHeader.URI.name(version), primaryPath);
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -270,10 +270,10 @@ public class PushStrategyBenchmarkTest extends AbstractHTTPSPDYTest
return result; return result;
} }
private Headers createRequestHeaders(String referrer, String path) private Fields createRequestHeaders(String referrer, String path)
{ {
Headers headers; Fields headers;
headers = new Headers(); headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), path); headers.put(HTTPSPDYHeader.URI.name(version), path);
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");

View File

@ -32,7 +32,6 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.spdy.SPDYServerConnector; import org.eclipse.jetty.spdy.SPDYServerConnector;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
@ -40,6 +39,7 @@ import org.eclipse.jetty.spdy.api.SessionFrameListener;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -73,7 +73,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
ConnectionFactory defaultFactory = new ServerHTTPSPDYConnectionFactory(version, connector.getByteBufferPool(), connector.getExecutor(), connector.getScheduler(), connector, pushStrategy); ConnectionFactory defaultFactory = new ServerHTTPSPDYConnectionFactory(version, connector.getByteBufferPool(), connector.getExecutor(), connector.getScheduler(), connector, pushStrategy);
connector.setDefaultConnectionFactory(defaultFactory); connector.setDefaultConnectionFactory(defaultFactory);
Headers mainRequestHeaders = createHeadersWithoutReferrer(mainResource); Fields mainRequestHeaders = createHeadersWithoutReferrer(mainResource);
Session session1 = sendMainRequestAndCSSRequest(address, mainRequestHeaders); Session session1 = sendMainRequestAndCSSRequest(address, mainRequestHeaders);
// Sleep for pushPeriod This should prevent application.js from being mapped as pushResource // Sleep for pushPeriod This should prevent application.js from being mapped as pushResource
@ -96,7 +96,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
connector.getByteBufferPool(), connector.getExecutor(), connector.getScheduler(), connector, pushStrategy); connector.getByteBufferPool(), connector.getExecutor(), connector.getScheduler(), connector, pushStrategy);
connector.setDefaultConnectionFactory(defaultFactory); connector.setDefaultConnectionFactory(defaultFactory);
Headers mainRequestHeaders = createHeadersWithoutReferrer(mainResource); Fields mainRequestHeaders = createHeadersWithoutReferrer(mainResource);
Session session1 = sendMainRequestAndCSSRequest(address, mainRequestHeaders); Session session1 = sendMainRequestAndCSSRequest(address, mainRequestHeaders);
// Sleep for pushPeriod This should prevent application.js from being mapped as pushResource // Sleep for pushPeriod This should prevent application.js from being mapped as pushResource
@ -118,7 +118,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
connector.getByteBufferPool(), connector.getExecutor(), connector.getScheduler(), connector, pushStrategy); connector.getByteBufferPool(), connector.getExecutor(), connector.getScheduler(), connector, pushStrategy);
connector.setDefaultConnectionFactory(defaultFactory); connector.setDefaultConnectionFactory(defaultFactory);
Headers mainRequestHeaders = createHeadersWithoutReferrer(mainResource); Fields mainRequestHeaders = createHeadersWithoutReferrer(mainResource);
Session session1 = sendMainRequestAndCSSRequest(address, mainRequestHeaders); Session session1 = sendMainRequestAndCSSRequest(address, mainRequestHeaders);
sendJSRequest(session1); sendJSRequest(session1);
@ -146,7 +146,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
}); });
} }
private Session sendMainRequestAndCSSRequest(InetSocketAddress address, Headers mainRequestHeaders) throws Exception private Session sendMainRequestAndCSSRequest(InetSocketAddress address, Fields mainRequestHeaders) throws Exception
{ {
Session session1 = startClient(version, address, null); Session session1 = startClient(version, address, null);
@ -164,7 +164,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Assert.assertTrue(mainResourceLatch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(mainResourceLatch.await(5, TimeUnit.SECONDS));
final CountDownLatch associatedResourceLatch1 = new CountDownLatch(1); final CountDownLatch associatedResourceLatch1 = new CountDownLatch(1);
Headers associatedRequestHeaders1 = createHeaders(cssResource); Fields associatedRequestHeaders1 = createHeaders(cssResource);
session1.syn(new SynInfo(associatedRequestHeaders1, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(associatedRequestHeaders1, true), new StreamFrameListener.Adapter()
{ {
@Override @Override
@ -184,7 +184,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
{ {
final CountDownLatch associatedResourceLatch2 = new CountDownLatch(1); final CountDownLatch associatedResourceLatch2 = new CountDownLatch(1);
String jsResource = "/application.js"; String jsResource = "/application.js";
Headers associatedRequestHeaders2 = createHeaders(jsResource); Fields associatedRequestHeaders2 = createHeaders(jsResource);
session1.syn(new SynInfo(associatedRequestHeaders2, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(associatedRequestHeaders2, true), new StreamFrameListener.Adapter()
{ {
@Override @Override
@ -198,7 +198,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Assert.assertTrue(associatedResourceLatch2.await(5, TimeUnit.SECONDS)); Assert.assertTrue(associatedResourceLatch2.await(5, TimeUnit.SECONDS));
} }
private void run2ndClientRequests(InetSocketAddress address, Headers mainRequestHeaders, final boolean validateHeaders) throws Exception private void run2ndClientRequests(InetSocketAddress address, Fields mainRequestHeaders, final boolean validateHeaders) throws Exception
{ {
// Create another client, and perform the same request for the main resource, // Create another client, and perform the same request for the main resource,
// we expect the css being pushed, but not the js // we expect the css being pushed, but not the js
@ -273,7 +273,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Session session1 = startClient(version, address, null); Session session1 = startClient(version, address, null);
final CountDownLatch mainResourceLatch = new CountDownLatch(1); final CountDownLatch mainResourceLatch = new CountDownLatch(1);
Headers mainRequestHeaders = createHeadersWithoutReferrer(mainResource); Fields mainRequestHeaders = createHeadersWithoutReferrer(mainResource);
session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@ -288,7 +288,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Assert.assertTrue(mainResourceLatch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(mainResourceLatch.await(5, TimeUnit.SECONDS));
final CountDownLatch associatedResourceLatch = new CountDownLatch(1); final CountDownLatch associatedResourceLatch = new CountDownLatch(1);
Headers associatedRequestHeaders = createHeaders(cssResource); Fields associatedRequestHeaders = createHeaders(cssResource);
session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@Override @Override
@ -377,7 +377,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Session session1 = startClient(version, address, null); Session session1 = startClient(version, address, null);
final CountDownLatch mainResourceLatch = new CountDownLatch(1); final CountDownLatch mainResourceLatch = new CountDownLatch(1);
Headers mainRequestHeaders = createHeadersWithoutReferrer(mainResource); Fields mainRequestHeaders = createHeadersWithoutReferrer(mainResource);
session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@ -393,7 +393,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
final CountDownLatch associatedResourceLatch = new CountDownLatch(1); final CountDownLatch associatedResourceLatch = new CountDownLatch(1);
String cssResource = "/stylesheet.css"; String cssResource = "/stylesheet.css";
Headers associatedRequestHeaders = createHeaders(cssResource); Fields associatedRequestHeaders = createHeaders(cssResource);
session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@Override @Override
@ -407,7 +407,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Assert.assertTrue(associatedResourceLatch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(associatedResourceLatch.await(5, TimeUnit.SECONDS));
final CountDownLatch fakeAssociatedResourceLatch = new CountDownLatch(1); final CountDownLatch fakeAssociatedResourceLatch = new CountDownLatch(1);
Headers fakeAssociatedRequestHeaders = createHeaders(fakeResource); Fields fakeAssociatedRequestHeaders = createHeaders(fakeResource);
session1.syn(new SynInfo(fakeAssociatedRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(fakeAssociatedRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@Override @Override
@ -488,7 +488,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Session session1 = startClient(version, address, null); Session session1 = startClient(version, address, null);
final CountDownLatch mainResourceLatch = new CountDownLatch(1); final CountDownLatch mainResourceLatch = new CountDownLatch(1);
Headers mainRequestHeaders = createHeadersWithoutReferrer(mainResource); Fields mainRequestHeaders = createHeadersWithoutReferrer(mainResource);
session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@ -503,7 +503,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Assert.assertTrue(mainResourceLatch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(mainResourceLatch.await(5, TimeUnit.SECONDS));
final CountDownLatch associatedResourceLatch = new CountDownLatch(1); final CountDownLatch associatedResourceLatch = new CountDownLatch(1);
Headers associatedRequestHeaders = createHeaders(cssResource); Fields associatedRequestHeaders = createHeaders(cssResource);
session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@Override @Override
@ -518,7 +518,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
final CountDownLatch nestedResourceLatch = new CountDownLatch(1); final CountDownLatch nestedResourceLatch = new CountDownLatch(1);
String imageUrl = "/image.gif"; String imageUrl = "/image.gif";
Headers nestedRequestHeaders = createHeaders(imageUrl, cssResource); Fields nestedRequestHeaders = createHeaders(imageUrl, cssResource);
session1.syn(new SynInfo(nestedRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(nestedRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@ -594,7 +594,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Session session1 = startClient(version, address, null); Session session1 = startClient(version, address, null);
final CountDownLatch mainResourceLatch = new CountDownLatch(1); final CountDownLatch mainResourceLatch = new CountDownLatch(1);
Headers mainRequestHeaders = createHeadersWithoutReferrer(mainResource); Fields mainRequestHeaders = createHeadersWithoutReferrer(mainResource);
session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@ -610,7 +610,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
final CountDownLatch associatedResourceLatch = new CountDownLatch(1); final CountDownLatch associatedResourceLatch = new CountDownLatch(1);
String associatedResource = "/home.html"; String associatedResource = "/home.html";
Headers associatedRequestHeaders = createHeaders(associatedResource); Fields associatedRequestHeaders = createHeaders(associatedResource);
session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@ -679,7 +679,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Session session1 = startClient(version, address, null); Session session1 = startClient(version, address, null);
final CountDownLatch mainResourceLatch = new CountDownLatch(1); final CountDownLatch mainResourceLatch = new CountDownLatch(1);
Headers mainRequestHeaders = createHeaders(mainResource); Fields mainRequestHeaders = createHeaders(mainResource);
mainRequestHeaders.put("If-Modified-Since", "Tue, 27 Mar 2012 16:36:52 GMT"); mainRequestHeaders.put("If-Modified-Since", "Tue, 27 Mar 2012 16:36:52 GMT");
session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@ -694,7 +694,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Assert.assertTrue(mainResourceLatch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(mainResourceLatch.await(5, TimeUnit.SECONDS));
final CountDownLatch associatedResourceLatch = new CountDownLatch(1); final CountDownLatch associatedResourceLatch = new CountDownLatch(1);
Headers associatedRequestHeaders = createHeaders(cssResource); Fields associatedRequestHeaders = createHeaders(cssResource);
session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter() session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter()
{ {
@Override @Override
@ -752,7 +752,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Assert.assertFalse("We don't expect data to be pushed as the main request contained an if-modified-since header",pushDataLatch.await(1, TimeUnit.SECONDS)); Assert.assertFalse("We don't expect data to be pushed as the main request contained an if-modified-since header",pushDataLatch.await(1, TimeUnit.SECONDS));
} }
private void validateHeaders(Headers headers, CountDownLatch pushSynHeadersValid) private void validateHeaders(Fields headers, CountDownLatch pushSynHeadersValid)
{ {
if (validateHeader(headers, HTTPSPDYHeader.STATUS.name(version), "200") if (validateHeader(headers, HTTPSPDYHeader.STATUS.name(version), "200")
&& validateHeader(headers, HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1") && validateHeader(headers, HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1")
@ -760,18 +760,18 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
pushSynHeadersValid.countDown(); pushSynHeadersValid.countDown();
} }
private boolean validateHeader(Headers headers, String name, String expectedValue) private boolean validateHeader(Fields headers, String name, String expectedValue)
{ {
Headers.Header header = headers.get(name); Fields.Field header = headers.get(name);
if (header != null && expectedValue.equals(header.value())) if (header != null && expectedValue.equals(header.value()))
return true; return true;
System.out.println(name + " not valid! " + headers); System.out.println(name + " not valid! " + headers);
return false; return false;
} }
private boolean validateUriHeader(Headers headers) private boolean validateUriHeader(Fields headers)
{ {
Headers.Header uriHeader = headers.get(HTTPSPDYHeader.URI.name(version)); Fields.Field uriHeader = headers.get(HTTPSPDYHeader.URI.name(version));
if (uriHeader != null) if (uriHeader != null)
if (version == SPDY.V2 && uriHeader.value().startsWith("http://")) if (version == SPDY.V2 && uriHeader.value().startsWith("http://"))
return true; return true;
@ -782,21 +782,21 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
return false; return false;
} }
private Headers createHeaders(String resource) private Fields createHeaders(String resource)
{ {
return createHeaders(resource, mainResource); return createHeaders(resource, mainResource);
} }
private Headers createHeaders(String resource, String referrer) private Fields createHeaders(String resource, String referrer)
{ {
Headers associatedRequestHeaders = createHeadersWithoutReferrer(resource); Fields associatedRequestHeaders = createHeadersWithoutReferrer(resource);
associatedRequestHeaders.put("referer", "http://localhost:" + connector.getLocalPort() + referrer); associatedRequestHeaders.put("referer", "http://localhost:" + connector.getLocalPort() + referrer);
return associatedRequestHeaders; return associatedRequestHeaders;
} }
private Headers createHeadersWithoutReferrer(String resource) private Fields createHeadersWithoutReferrer(String resource)
{ {
Headers associatedRequestHeaders = new Headers(); Fields associatedRequestHeaders = new Fields();
associatedRequestHeaders.put(HTTPSPDYHeader.METHOD.name(version), "GET"); associatedRequestHeaders.put(HTTPSPDYHeader.METHOD.name(version), "GET");
associatedRequestHeaders.put(HTTPSPDYHeader.URI.name(version), resource); associatedRequestHeaders.put(HTTPSPDYHeader.URI.name(version), resource);
associatedRequestHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); associatedRequestHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");

View File

@ -20,10 +20,10 @@ package org.eclipse.jetty.spdy.http;
import java.util.Set; import java.util.Set;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.util.Fields;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -61,7 +61,7 @@ public class ReferrerPushStrategyUnitTest
@Test @Test
public void testReferrerCallsAfterTimeoutAreNotAddedAsPushResources() throws InterruptedException public void testReferrerCallsAfterTimeoutAreNotAddedAsPushResources() throws InterruptedException
{ {
Headers requestHeaders = getBaseHeaders(VERSION); Fields requestHeaders = getBaseHeaders(VERSION);
int referrerCallTimeout = 1000; int referrerCallTimeout = 1000;
referrerPushStrategy.setReferrerPushPeriod(referrerCallTimeout); referrerPushStrategy.setReferrerPushPeriod(referrerCallTimeout);
setMockExpectations(); setMockExpectations();
@ -74,18 +74,18 @@ public class ReferrerPushStrategyUnitTest
requestHeaders.put(HTTPSPDYHeader.URI.name(VERSION), "image2.jpg"); requestHeaders.put(HTTPSPDYHeader.URI.name(VERSION), "image2.jpg");
requestHeaders.put("referer", referrerUrl); requestHeaders.put("referer", referrerUrl);
pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Headers()); pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Fields());
assertThat("pushResources is empty", pushResources.size(), is(0)); assertThat("pushResources is empty", pushResources.size(), is(0));
requestHeaders.put(HTTPSPDYHeader.URI.name(VERSION), MAIN_URI); requestHeaders.put(HTTPSPDYHeader.URI.name(VERSION), MAIN_URI);
pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Headers()); pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Fields());
// as the image2.jpg request has been a link and not a subresource, we expect that pushResources.size() is still 2 // as the image2.jpg request has been a link and not a subresource, we expect that pushResources.size() is still 2
assertThat("pushResources contains two elements image.jpg and style.css", pushResources.size(), is(2)); assertThat("pushResources contains two elements image.jpg and style.css", pushResources.size(), is(2));
} }
private Headers getBaseHeaders(short version) private Fields getBaseHeaders(short version)
{ {
Headers requestHeaders = new Headers(); Fields requestHeaders = new Fields();
requestHeaders.put(HTTPSPDYHeader.SCHEME.name(version), SCHEME); requestHeaders.put(HTTPSPDYHeader.SCHEME.name(version), SCHEME);
requestHeaders.put(HTTPSPDYHeader.HOST.name(version), HOST); requestHeaders.put(HTTPSPDYHeader.HOST.name(version), HOST);
requestHeaders.put(HTTPSPDYHeader.URI.name(version), MAIN_URI); requestHeaders.put(HTTPSPDYHeader.URI.name(version), MAIN_URI);
@ -99,9 +99,9 @@ public class ReferrerPushStrategyUnitTest
when(session.getVersion()).thenReturn(VERSION); when(session.getVersion()).thenReturn(VERSION);
} }
private String fillPushStrategyCache(Headers requestHeaders) private String fillPushStrategyCache(Fields requestHeaders)
{ {
Set<String> pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Headers()); Set<String> pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Fields());
assertThat("pushResources is empty", pushResources.size(), is(0)); assertThat("pushResources is empty", pushResources.size(), is(0));
String origin = SCHEME + "://" + HOST; String origin = SCHEME + "://" + HOST;
@ -109,15 +109,15 @@ public class ReferrerPushStrategyUnitTest
requestHeaders.put(HTTPSPDYHeader.URI.name(VERSION), "image.jpg"); requestHeaders.put(HTTPSPDYHeader.URI.name(VERSION), "image.jpg");
requestHeaders.put("referer", referrerUrl); requestHeaders.put("referer", referrerUrl);
pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Headers()); pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Fields());
assertThat("pushResources is empty", pushResources.size(), is(0)); assertThat("pushResources is empty", pushResources.size(), is(0));
requestHeaders.put(HTTPSPDYHeader.URI.name(VERSION), "style.css"); requestHeaders.put(HTTPSPDYHeader.URI.name(VERSION), "style.css");
pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Headers()); pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Fields());
assertThat("pushResources is empty", pushResources.size(), is(0)); assertThat("pushResources is empty", pushResources.size(), is(0));
requestHeaders.put(HTTPSPDYHeader.URI.name(VERSION), MAIN_URI); requestHeaders.put(HTTPSPDYHeader.URI.name(VERSION), MAIN_URI);
pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Headers()); pushResources = referrerPushStrategy.apply(stream, requestHeaders, new Fields());
assertThat("pushResources contains two elements image.jpg and style.css", pushResources.size(), is(2)); assertThat("pushResources contains two elements image.jpg and style.css", pushResources.size(), is(2));
return referrerUrl; return referrerUrl;
} }

View File

@ -28,12 +28,12 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.eclipse.jetty.spdy.SPDYClient; import org.eclipse.jetty.spdy.SPDYClient;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Assume; import org.junit.Assume;
@ -75,7 +75,7 @@ public class SSLExternalServerTest extends AbstractHTTPSPDYTest
} }
Session session = startClient(version, address, null); Session session = startClient(version, address, null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.SCHEME.name(version), "https"); headers.put(HTTPSPDYHeader.SCHEME.name(version), "https");
headers.put(HTTPSPDYHeader.HOST.name(version), host + ":" + port); headers.put(HTTPSPDYHeader.HOST.name(version), host + ":" + port);
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
@ -87,8 +87,8 @@ public class SSLExternalServerTest extends AbstractHTTPSPDYTest
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Headers headers = replyInfo.getHeaders(); Fields headers = replyInfo.getHeaders();
Headers.Header versionHeader = headers.get(HTTPSPDYHeader.STATUS.name(version)); Fields.Field versionHeader = headers.get(HTTPSPDYHeader.STATUS.name(version));
if (versionHeader != null) if (versionHeader != null)
{ {
Matcher matcher = Pattern.compile("(\\d{3}).*").matcher(versionHeader.value()); Matcher matcher = Pattern.compile("(\\d{3}).*").matcher(versionHeader.value());

View File

@ -40,13 +40,13 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.spdy.api.BytesDataInfo; import org.eclipse.jetty.spdy.api.BytesDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.StringDataInfo; import org.eclipse.jetty.spdy.api.StringDataInfo;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -78,7 +78,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), path); headers.put(HTTPSPDYHeader.URI.name(version), path);
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -91,7 +91,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertTrue(replyInfo.isClose()); Assert.assertTrue(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -122,7 +122,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), uri); headers.put(HTTPSPDYHeader.URI.name(version), uri);
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -135,7 +135,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertTrue(replyInfo.isClose()); Assert.assertTrue(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -163,7 +163,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "HEAD"); headers.put(HTTPSPDYHeader.METHOD.name(version), "HEAD");
headers.put(HTTPSPDYHeader.URI.name(version), path); headers.put(HTTPSPDYHeader.URI.name(version), path);
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -176,7 +176,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertTrue(replyInfo.isClose()); Assert.assertTrue(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -213,7 +213,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "POST"); headers.put(HTTPSPDYHeader.METHOD.name(version), "POST");
headers.put(HTTPSPDYHeader.URI.name(version), path); headers.put(HTTPSPDYHeader.URI.name(version), path);
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -227,7 +227,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertTrue(replyInfo.isClose()); Assert.assertTrue(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -259,7 +259,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "POST"); headers.put(HTTPSPDYHeader.METHOD.name(version), "POST");
headers.put(HTTPSPDYHeader.URI.name(version), path); headers.put(HTTPSPDYHeader.URI.name(version), path);
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -273,7 +273,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertTrue(replyInfo.isClose()); Assert.assertTrue(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -308,7 +308,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "POST"); headers.put(HTTPSPDYHeader.METHOD.name(version), "POST");
headers.put(HTTPSPDYHeader.URI.name(version), path); headers.put(HTTPSPDYHeader.URI.name(version), path);
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -322,7 +322,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertTrue(replyInfo.isClose()); Assert.assertTrue(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.toString(), replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.toString(), replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -354,7 +354,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -368,7 +368,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -405,7 +405,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -419,7 +419,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -461,7 +461,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -479,7 +479,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{ {
Assert.assertEquals(1, replyFrames.incrementAndGet()); Assert.assertEquals(1, replyFrames.incrementAndGet());
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -521,7 +521,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -537,7 +537,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -579,7 +579,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -595,7 +595,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -637,7 +637,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -653,7 +653,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -700,7 +700,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -716,7 +716,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -758,7 +758,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -774,7 +774,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{ {
Assert.assertEquals(1, replies.incrementAndGet()); Assert.assertEquals(1, replies.incrementAndGet());
Assert.assertTrue(replyInfo.isClose()); Assert.assertTrue(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("302")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("302"));
Assert.assertTrue(replyHeaders.get("location").value().endsWith(suffix)); Assert.assertTrue(replyHeaders.get("location").value().endsWith(suffix));
replyLatch.countDown(); replyLatch.countDown();
@ -800,7 +800,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -817,7 +817,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{ {
Assert.assertEquals(1, replies.incrementAndGet()); Assert.assertEquals(1, replies.incrementAndGet());
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("404")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("404"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -847,7 +847,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -863,7 +863,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertEquals(1, replies.incrementAndGet()); Assert.assertEquals(1, replies.incrementAndGet());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("500")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("500"));
replyLatch.countDown(); replyLatch.countDown();
if (replyInfo.isClose()) if (replyInfo.isClose())
@ -904,7 +904,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -922,7 +922,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{ {
Assert.assertEquals(1, replyFrames.incrementAndGet()); Assert.assertEquals(1, replyFrames.incrementAndGet());
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
Assert.assertTrue(replyHeaders.get("extra").value().contains("X")); Assert.assertTrue(replyHeaders.get("extra").value().contains("X"));
replyLatch.countDown(); replyLatch.countDown();
@ -991,7 +991,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -1009,7 +1009,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{ {
Assert.assertEquals(1, replyFrames.incrementAndGet()); Assert.assertEquals(1, replyFrames.incrementAndGet());
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -1052,7 +1052,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "GET"); headers.put(HTTPSPDYHeader.METHOD.name(version), "GET");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -1067,7 +1067,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Assert.assertFalse(replyInfo.isClose()); Assert.assertFalse(replyInfo.isClose());
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -1125,7 +1125,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "POST"); headers.put(HTTPSPDYHeader.METHOD.name(version), "POST");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -1137,7 +1137,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -1188,7 +1188,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "POST"); headers.put(HTTPSPDYHeader.METHOD.name(version), "POST");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -1200,7 +1200,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -1261,7 +1261,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "POST"); headers.put(HTTPSPDYHeader.METHOD.name(version), "POST");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -1273,7 +1273,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
responseLatch.countDown(); responseLatch.countDown();
} }
@ -1307,7 +1307,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
} }
}), null); }), null);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.METHOD.name(version), "POST"); headers.put(HTTPSPDYHeader.METHOD.name(version), "POST");
headers.put(HTTPSPDYHeader.URI.name(version), "/foo"); headers.put(HTTPSPDYHeader.URI.name(version), "/foo");
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
@ -1319,7 +1319,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Headers replyHeaders = replyInfo.getHeaders(); Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200")); Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
responseLatch.countDown(); responseLatch.countDown();
} }

View File

@ -37,7 +37,6 @@ import org.eclipse.jetty.spdy.ServerSPDYConnectionFactory;
import org.eclipse.jetty.spdy.api.BytesDataInfo; import org.eclipse.jetty.spdy.api.BytesDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.GoAwayInfo; import org.eclipse.jetty.spdy.api.GoAwayInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.PingInfo; import org.eclipse.jetty.spdy.api.PingInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.RstInfo; import org.eclipse.jetty.spdy.api.RstInfo;
@ -51,6 +50,7 @@ import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.eclipse.jetty.spdy.http.HTTPSPDYHeader; import org.eclipse.jetty.spdy.http.HTTPSPDYHeader;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -154,7 +154,7 @@ public class ProxyHTTPSPDYTest
@Override @Override
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{ {
Headers responseHeaders = new Headers(); Fields responseHeaders = new Fields();
responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK"); responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK");
stream.reply(new ReplyInfo(responseHeaders, true)); stream.reply(new ReplyInfo(responseHeaders, true));
@ -202,10 +202,10 @@ public class ProxyHTTPSPDYTest
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{ {
Assert.assertTrue(synInfo.isClose()); Assert.assertTrue(synInfo.isClose());
Headers requestHeaders = synInfo.getHeaders(); Fields requestHeaders = synInfo.getHeaders();
Assert.assertNotNull(requestHeaders.get("via")); Assert.assertNotNull(requestHeaders.get("via"));
Headers responseHeaders = new Headers(); Fields responseHeaders = new Fields();
responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK"); responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK");
ReplyInfo replyInfo = new ReplyInfo(responseHeaders, true); ReplyInfo replyInfo = new ReplyInfo(responseHeaders, true);
@ -263,10 +263,10 @@ public class ProxyHTTPSPDYTest
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{ {
Assert.assertTrue(synInfo.isClose()); Assert.assertTrue(synInfo.isClose());
Headers requestHeaders = synInfo.getHeaders(); Fields requestHeaders = synInfo.getHeaders();
Assert.assertNotNull(requestHeaders.get("via")); Assert.assertNotNull(requestHeaders.get("via"));
Headers responseHeaders = new Headers(); Fields responseHeaders = new Fields();
responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK"); responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK");
ReplyInfo replyInfo = new ReplyInfo(responseHeaders, false); ReplyInfo replyInfo = new ReplyInfo(responseHeaders, false);
@ -330,7 +330,7 @@ public class ProxyHTTPSPDYTest
dataInfo.consume(dataInfo.length()); dataInfo.consume(dataInfo.length());
if (dataInfo.isClose()) if (dataInfo.isClose())
{ {
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); headers.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
headers.put(HTTPSPDYHeader.STATUS.name(version), "303 See Other"); headers.put(HTTPSPDYHeader.STATUS.name(version), "303 See Other");
stream.reply(new ReplyInfo(headers, true)); stream.reply(new ReplyInfo(headers, true));
@ -393,7 +393,7 @@ public class ProxyHTTPSPDYTest
dataInfo.consume(dataInfo.length()); dataInfo.consume(dataInfo.length());
if (dataInfo.isClose()) if (dataInfo.isClose())
{ {
Headers responseHeaders = new Headers(); Fields responseHeaders = new Fields();
responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK"); responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK");
ReplyInfo replyInfo = new ReplyInfo(responseHeaders, false); ReplyInfo replyInfo = new ReplyInfo(responseHeaders, false);
@ -454,11 +454,11 @@ public class ProxyHTTPSPDYTest
@Override @Override
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{ {
Headers requestHeaders = synInfo.getHeaders(); Fields requestHeaders = synInfo.getHeaders();
Assert.assertNotNull(requestHeaders.get("via")); Assert.assertNotNull(requestHeaders.get("via"));
Assert.assertNotNull(requestHeaders.get(header)); Assert.assertNotNull(requestHeaders.get(header));
Headers responseHeaders = new Headers(); Fields responseHeaders = new Fields();
responseHeaders.put(header, "baz"); responseHeaders.put(header, "baz");
stream.reply(new ReplyInfo(responseHeaders, true)); stream.reply(new ReplyInfo(responseHeaders, true));
return null; return null;
@ -469,7 +469,7 @@ public class ProxyHTTPSPDYTest
Session client = factory.newSPDYClient(version).connect(proxyAddress, null).get(5, TimeUnit.SECONDS); Session client = factory.newSPDYClient(version).connect(proxyAddress, null).get(5, TimeUnit.SECONDS);
final CountDownLatch replyLatch = new CountDownLatch(1); final CountDownLatch replyLatch = new CountDownLatch(1);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.HOST.name(version), "localhost:" + proxyAddress.getPort()); headers.put(HTTPSPDYHeader.HOST.name(version), "localhost:" + proxyAddress.getPort());
headers.put(header, "bar"); headers.put(header, "bar");
client.syn(new SynInfo(headers, true), new StreamFrameListener.Adapter() client.syn(new SynInfo(headers, true), new StreamFrameListener.Adapter()
@ -477,7 +477,7 @@ public class ProxyHTTPSPDYTest
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Headers headers = replyInfo.getHeaders(); Fields headers = replyInfo.getHeaders();
Assert.assertNotNull(headers.get(header)); Assert.assertNotNull(headers.get(header));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -498,11 +498,11 @@ public class ProxyHTTPSPDYTest
@Override @Override
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{ {
Headers requestHeaders = synInfo.getHeaders(); Fields requestHeaders = synInfo.getHeaders();
Assert.assertNotNull(requestHeaders.get("via")); Assert.assertNotNull(requestHeaders.get("via"));
Assert.assertNotNull(requestHeaders.get(header)); Assert.assertNotNull(requestHeaders.get(header));
Headers responseHeaders = new Headers(); Fields responseHeaders = new Fields();
responseHeaders.put(header, "baz"); responseHeaders.put(header, "baz");
stream.reply(new ReplyInfo(responseHeaders, false)); stream.reply(new ReplyInfo(responseHeaders, false));
stream.data(new BytesDataInfo(data, true)); stream.data(new BytesDataInfo(data, true));
@ -515,7 +515,7 @@ public class ProxyHTTPSPDYTest
final CountDownLatch replyLatch = new CountDownLatch(1); final CountDownLatch replyLatch = new CountDownLatch(1);
final CountDownLatch dataLatch = new CountDownLatch(1); final CountDownLatch dataLatch = new CountDownLatch(1);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.HOST.name(version), "localhost:" + proxyAddress.getPort()); headers.put(HTTPSPDYHeader.HOST.name(version), "localhost:" + proxyAddress.getPort());
headers.put(header, "bar"); headers.put(header, "bar");
client.syn(new SynInfo(headers, true), new StreamFrameListener.Adapter() client.syn(new SynInfo(headers, true), new StreamFrameListener.Adapter()
@ -525,7 +525,7 @@ public class ProxyHTTPSPDYTest
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Headers headers = replyInfo.getHeaders(); Fields headers = replyInfo.getHeaders();
Assert.assertNotNull(headers.get(header)); Assert.assertNotNull(headers.get(header));
replyLatch.countDown(); replyLatch.countDown();
} }
@ -557,11 +557,11 @@ public class ProxyHTTPSPDYTest
@Override @Override
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{ {
Headers responseHeaders = new Headers(); Fields responseHeaders = new Fields();
responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK"); responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK");
Headers pushHeaders = new Headers(); Fields pushHeaders = new Fields();
pushHeaders.put(HTTPSPDYHeader.URI.name(version), "/push"); pushHeaders.put(HTTPSPDYHeader.URI.name(version), "/push");
stream.syn(new SynInfo(pushHeaders, false), 5, TimeUnit.SECONDS, new Callback.Empty<Stream>() stream.syn(new SynInfo(pushHeaders, false), 5, TimeUnit.SECONDS, new Callback.Empty<Stream>()
{ {
@ -609,12 +609,12 @@ public class ProxyHTTPSPDYTest
@Override @Override
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{ {
Headers responseHeaders = new Headers(); Fields responseHeaders = new Fields();
responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1"); responseHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK"); responseHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200 OK");
stream.reply(new ReplyInfo(responseHeaders, false)); stream.reply(new ReplyInfo(responseHeaders, false));
Headers pushHeaders = new Headers(); Fields pushHeaders = new Fields();
pushHeaders.put(HTTPSPDYHeader.URI.name(version), "/push"); pushHeaders.put(HTTPSPDYHeader.URI.name(version), "/push");
stream.syn(new SynInfo(pushHeaders, false), 5, TimeUnit.SECONDS, new Callback.Empty<Stream>() stream.syn(new SynInfo(pushHeaders, false), 5, TimeUnit.SECONDS, new Callback.Empty<Stream>()
{ {
@ -653,7 +653,7 @@ public class ProxyHTTPSPDYTest
} }
}).get(5, TimeUnit.SECONDS); }).get(5, TimeUnit.SECONDS);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.HOST.name(version), "localhost:" + proxyAddress.getPort()); headers.put(HTTPSPDYHeader.HOST.name(version), "localhost:" + proxyAddress.getPort());
final CountDownLatch replyLatch = new CountDownLatch(1); final CountDownLatch replyLatch = new CountDownLatch(1);
final CountDownLatch dataLatch = new CountDownLatch(1); final CountDownLatch dataLatch = new CountDownLatch(1);
@ -717,7 +717,7 @@ public class ProxyHTTPSPDYTest
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{ {
Assert.assertTrue(synInfo.isClose()); Assert.assertTrue(synInfo.isClose());
Headers requestHeaders = synInfo.getHeaders(); Fields requestHeaders = synInfo.getHeaders();
Assert.assertNotNull(requestHeaders.get("via")); Assert.assertNotNull(requestHeaders.get("via"));
stream.getSession().rst(new RstInfo(stream.getId(), StreamStatus.REFUSED_STREAM)); stream.getSession().rst(new RstInfo(stream.getId(), StreamStatus.REFUSED_STREAM));
@ -753,7 +753,7 @@ public class ProxyHTTPSPDYTest
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{ {
Assert.assertTrue(synInfo.isClose()); Assert.assertTrue(synInfo.isClose());
Headers requestHeaders = synInfo.getHeaders(); Fields requestHeaders = synInfo.getHeaders();
Assert.assertNotNull(requestHeaders.get("via")); Assert.assertNotNull(requestHeaders.get("via"));
stream.getSession().rst(new RstInfo(stream.getId(), StreamStatus.REFUSED_STREAM)); stream.getSession().rst(new RstInfo(stream.getId(), StreamStatus.REFUSED_STREAM));
@ -773,7 +773,7 @@ public class ProxyHTTPSPDYTest
} }
}).get(5, TimeUnit.SECONDS); }).get(5, TimeUnit.SECONDS);
Headers headers = new Headers(); Fields headers = new Fields();
headers.put(HTTPSPDYHeader.HOST.name(version), "localhost:" + proxyAddress.getPort()); headers.put(HTTPSPDYHeader.HOST.name(version), "localhost:" + proxyAddress.getPort());
client.syn(new SynInfo(headers, true), null); client.syn(new SynInfo(headers, true), null);

View File

@ -30,7 +30,6 @@ import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.spdy.api.BytesDataInfo; import org.eclipse.jetty.spdy.api.BytesDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.GoAwayInfo; import org.eclipse.jetty.spdy.api.GoAwayInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
@ -48,6 +47,7 @@ import org.eclipse.jetty.spdy.frames.SynStreamFrame;
import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser; import org.eclipse.jetty.spdy.parser.Parser;
import org.eclipse.jetty.spdy.parser.Parser.Listener; import org.eclipse.jetty.spdy.parser.Parser.Listener;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -85,7 +85,7 @@ public class ClosedStreamTest extends AbstractTest
Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor()); Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor());
ByteBuffer writeBuffer = generator.control(new SynReplyFrame(SPDY.V2, (byte)0, streamId, new Headers())); ByteBuffer writeBuffer = generator.control(new SynReplyFrame(SPDY.V2, (byte)0, streamId, new Fields()));
channel.write(writeBuffer); channel.write(writeBuffer);
Assert.assertThat(writeBuffer.hasRemaining(), is(false)); Assert.assertThat(writeBuffer.hasRemaining(), is(false));
@ -216,7 +216,7 @@ public class ClosedStreamTest extends AbstractTest
final Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory().newCompressor()); final Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory().newCompressor());
int streamId = 1; int streamId = 1;
ByteBuffer synData = generator.control(new SynStreamFrame(version,SynInfo.FLAG_CLOSE, streamId,0,(byte)0,(short)0,new Headers())); ByteBuffer synData = generator.control(new SynStreamFrame(version,SynInfo.FLAG_CLOSE, streamId,0,(byte)0,(short)0,new Fields()));
final SocketChannel socketChannel = SocketChannel.open(startServer); final SocketChannel socketChannel = SocketChannel.open(startServer);
socketChannel.write(synData); socketChannel.write(synData);

View File

@ -22,7 +22,6 @@ package org.eclipse.jetty.spdy;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo; import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
@ -30,6 +29,7 @@ import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -50,7 +50,7 @@ public class HeadersTest extends AbstractTest
public void onHeaders(Stream stream, HeadersInfo headersInfo) public void onHeaders(Stream stream, HeadersInfo headersInfo)
{ {
Assert.assertTrue(stream.isHalfClosed()); Assert.assertTrue(stream.isHalfClosed());
stream.headers(new HeadersInfo(new Headers(), true)); stream.headers(new HeadersInfo(new Fields(), true));
Assert.assertTrue(stream.isClosed()); Assert.assertTrue(stream.isClosed());
} }
}; };
@ -65,7 +65,7 @@ public class HeadersTest extends AbstractTest
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)
{ {
Headers headers = new Headers(); Fields headers = new Fields();
headers.put("foo", "bar"); headers.put("foo", "bar");
headers.put("baz", "woo"); headers.put("baz", "woo");
stream.headers(new HeadersInfo(headers, true)); stream.headers(new HeadersInfo(headers, true));

View File

@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.spdy.api.BytesDataInfo; import org.eclipse.jetty.spdy.api.BytesDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo; import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.RstInfo; import org.eclipse.jetty.spdy.api.RstInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
@ -43,6 +42,7 @@ import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.eclipse.jetty.spdy.frames.ControlFrameType; import org.eclipse.jetty.spdy.frames.ControlFrameType;
import org.eclipse.jetty.spdy.frames.SynReplyFrame; import org.eclipse.jetty.spdy.frames.SynReplyFrame;
import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -131,7 +131,7 @@ public class ProtocolViolationsTest extends AbstractTest
{ {
Session session = startClient(startServer(null), null); Session session = startClient(startServer(null), null);
Stream stream = session.syn(new SynInfo(true), null).get(5, TimeUnit.SECONDS); Stream stream = session.syn(new SynInfo(true), null).get(5, TimeUnit.SECONDS);
stream.headers(new HeadersInfo(new Headers(), true)); stream.headers(new HeadersInfo(new Fields(), true));
} }
@Test //TODO: throws an ISException in StandardStream.updateCloseState(). But instead we should send a rst or something to the server probably?! @Test //TODO: throws an ISException in StandardStream.updateCloseState(). But instead we should send a rst or something to the server probably?!
@ -159,7 +159,7 @@ public class ProtocolViolationsTest extends AbstractTest
Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor()); Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor());
ByteBuffer writeBuffer = generator.control(new SynReplyFrame(SPDY.V2, (byte)0, streamId, new Headers())); ByteBuffer writeBuffer = generator.control(new SynReplyFrame(SPDY.V2, (byte)0, streamId, new Fields()));
channel.write(writeBuffer); channel.write(writeBuffer);
assertThat("SynReply is fully written", writeBuffer.hasRemaining(), is(false)); assertThat("SynReply is fully written", writeBuffer.hasRemaining(), is(false));

View File

@ -37,7 +37,6 @@ import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.spdy.api.BytesDataInfo; import org.eclipse.jetty.spdy.api.BytesDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.GoAwayInfo; import org.eclipse.jetty.spdy.api.GoAwayInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.RstInfo; import org.eclipse.jetty.spdy.api.RstInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
@ -60,6 +59,7 @@ import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser; import org.eclipse.jetty.spdy.parser.Parser;
import org.eclipse.jetty.spdy.parser.Parser.Listener; import org.eclipse.jetty.spdy.parser.Parser.Listener;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -418,7 +418,7 @@ public class PushStreamTest extends AbstractTest
final SocketChannel channel = SocketChannel.open(serverAddress); final SocketChannel channel = SocketChannel.open(serverAddress);
final Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor()); final Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor());
int streamId = 1; int streamId = 1;
ByteBuffer writeBuffer = generator.control(new SynStreamFrame(version,(byte)0,streamId,0,(byte)0,(short)0,new Headers())); ByteBuffer writeBuffer = generator.control(new SynStreamFrame(version,(byte)0,streamId,0,(byte)0,(short)0,new Fields()));
channel.write(writeBuffer); channel.write(writeBuffer);
assertThat("writeBuffer is fully written",writeBuffer.hasRemaining(), is(false)); assertThat("writeBuffer is fully written",writeBuffer.hasRemaining(), is(false));

View File

@ -34,7 +34,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.spdy.api.ByteBufferDataInfo; import org.eclipse.jetty.spdy.api.ByteBufferDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
@ -43,6 +42,7 @@ import org.eclipse.jetty.spdy.api.StringDataInfo;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -73,7 +73,7 @@ public class SynDataReplyDataLoadTest extends AbstractTest
final int iterations = 500; final int iterations = 500;
final int count = 50; final int count = 50;
final Headers headers = new Headers(); final Fields headers = new Fields();
headers.put("method", "get"); headers.put("method", "get");
headers.put("url", "/"); headers.put("url", "/");
headers.put("version", "http/1.1"); headers.put("version", "http/1.1");
@ -142,7 +142,7 @@ public class SynDataReplyDataLoadTest extends AbstractTest
threadPool.shutdown(); threadPool.shutdown();
} }
private void synCompletedData(Session session, Headers headers, int iterations) throws Exception private void synCompletedData(Session session, Fields headers, int iterations) throws Exception
{ {
final Map<Integer, Integer> counter = new ConcurrentHashMap<>(iterations); final Map<Integer, Integer> counter = new ConcurrentHashMap<>(iterations);
final CountDownLatch latch = new CountDownLatch(2 * iterations); final CountDownLatch latch = new CountDownLatch(2 * iterations);
@ -185,7 +185,7 @@ public class SynDataReplyDataLoadTest extends AbstractTest
Assert.assertTrue(counter.toString(), counter.isEmpty()); Assert.assertTrue(counter.toString(), counter.isEmpty());
} }
private void synGetDataGet(Session session, Headers headers, int iterations) throws Exception private void synGetDataGet(Session session, Fields headers, int iterations) throws Exception
{ {
final Map<Integer, Integer> counter = new ConcurrentHashMap<>(iterations); final Map<Integer, Integer> counter = new ConcurrentHashMap<>(iterations);
final CountDownLatch latch = new CountDownLatch(2 * iterations); final CountDownLatch latch = new CountDownLatch(2 * iterations);

View File

@ -29,7 +29,6 @@ import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.spdy.api.BytesDataInfo; import org.eclipse.jetty.spdy.api.BytesDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo; import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.SessionFrameListener; import org.eclipse.jetty.spdy.api.SessionFrameListener;
@ -39,6 +38,7 @@ import org.eclipse.jetty.spdy.api.StringDataInfo;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -63,7 +63,7 @@ public class SynReplyTest extends AbstractTest
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{ {
Assert.assertTrue(stream.isHalfClosed()); Assert.assertTrue(stream.isHalfClosed());
stream.reply(new ReplyInfo(new Headers(), true)); stream.reply(new ReplyInfo(new Fields(), true));
synLatch.countDown(); synLatch.countDown();
return null; return null;
} }
@ -93,7 +93,7 @@ public class SynReplyTest extends AbstractTest
}); });
final CountDownLatch replyLatch = new CountDownLatch(1); final CountDownLatch replyLatch = new CountDownLatch(1);
Stream stream = session.syn(new SynInfo(new Headers(), true), new StreamFrameListener.Adapter() Stream stream = session.syn(new SynInfo(new Fields(), true), new StreamFrameListener.Adapter()
{ {
@Override @Override
public void onReply(Stream stream, ReplyInfo replyInfo) public void onReply(Stream stream, ReplyInfo replyInfo)

View File

@ -25,7 +25,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.StreamFrameListener;
@ -38,6 +37,7 @@ import org.eclipse.jetty.spdy.frames.RstStreamFrame;
import org.eclipse.jetty.spdy.frames.SynStreamFrame; import org.eclipse.jetty.spdy.frames.SynStreamFrame;
import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser; import org.eclipse.jetty.spdy.parser.Parser;
import org.eclipse.jetty.util.Fields;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -63,7 +63,7 @@ public class UnsupportedVersionTest extends AbstractTest
} }
}); });
SynStreamFrame frame = new SynStreamFrame(SPDY.V2, SynInfo.FLAG_CLOSE, 1, 0, (byte)0, (short)0, new Headers()); SynStreamFrame frame = new SynStreamFrame(SPDY.V2, SynInfo.FLAG_CLOSE, 1, 0, (byte)0, (short)0, new Fields());
Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor()); Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory.StandardCompressor());
ByteBuffer buffer = generator.control(frame); ByteBuffer buffer = generator.control(frame);
// Replace the version byte with an unsupported version // Replace the version byte with an unsupported version

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.spdy.api; package org.eclipse.jetty.util;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -27,36 +27,36 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
* <p>A container for name/value pairs, known as headers.</p> * <p>A container for name/value pairs, known as fields.</p>
* <p>A {@link Header} is composed of a case-insensitive name string and * <p>A {@link Field} is composed of a case-insensitive name string and
* of a case-sensitive set of value strings.</p> * of a case-sensitive set of value strings.</p>
* <p>The implementation of this class is not thread safe.</p> * <p>The implementation of this class is not thread safe.</p>
*/ */
public class Headers implements Iterable<Headers.Header> public class Fields implements Iterable<Fields.Field>
{ {
private final Map<String, Header> headers; private final Map<String, Field> fields;
/** /**
* <p>Creates an empty modifiable {@link Headers} instance.</p> * <p>Creates an empty modifiable {@link Fields} instance.</p>
* @see #Headers(Headers, boolean) * @see #Fields(Fields, boolean)
*/ */
public Headers() public Fields()
{ {
headers = new LinkedHashMap<>(); fields = new LinkedHashMap<>();
} }
/** /**
* <p>Creates a {@link Headers} instance by copying the headers from the given * <p>Creates a {@link Fields} instance by copying the fields from the given
* {@link Headers} and making it (im)mutable depending on the given {@code immutable} parameter</p> * {@link Fields} and making it (im)mutable depending on the given {@code immutable} parameter</p>
* *
* @param original the {@link Headers} to copy headers from * @param original the {@link Fields} to copy fields from
* @param immutable whether this instance is immutable * @param immutable whether this instance is immutable
*/ */
public Headers(Headers original, boolean immutable) public Fields(Fields original, boolean immutable)
{ {
Map<String, Header> copy = new LinkedHashMap<>(); Map<String, Field> copy = new LinkedHashMap<>();
copy.putAll(original.headers); copy.putAll(original.fields);
headers = immutable ? Collections.unmodifiableMap(copy) : copy; fields = immutable ? Collections.unmodifiableMap(copy) : copy;
} }
@Override @Override
@ -66,151 +66,156 @@ public class Headers implements Iterable<Headers.Header>
return true; return true;
if (obj == null || getClass() != obj.getClass()) if (obj == null || getClass() != obj.getClass())
return false; return false;
Headers that = (Headers)obj; Fields that = (Fields)obj;
return headers.equals(that.headers); return fields.equals(that.fields);
} }
@Override @Override
public int hashCode() public int hashCode()
{ {
return headers.hashCode(); return fields.hashCode();
} }
/** /**
* @return a set of header names * @return a set of field names
*/ */
public Set<String> names() public Set<String> names()
{ {
Set<String> result = new LinkedHashSet<>(); Set<String> result = new LinkedHashSet<>();
for (Header header : headers.values()) for (Field field : fields.values())
result.add(header.name); result.add(field.name());
return result; return result;
} }
/** /**
* @param name the header name * @param name the field name
* @return the {@link Header} with the given name, or null if no such header exists * @return the {@link Field} with the given name, or null if no such field exists
*/ */
public Header get(String name) public Field get(String name)
{ {
return headers.get(name.trim().toLowerCase()); return fields.get(name.trim().toLowerCase());
} }
/** /**
* <p>Inserts or replaces the given name/value pair as a single-valued {@link Header}.</p> * <p>Inserts or replaces the given name/value pair as a single-valued {@link Field}.</p>
* *
* @param name the header name * @param name the field name
* @param value the header value * @param value the field value
*/ */
public void put(String name, String value) public void put(String name, String value)
{ {
name = name.trim(); name = name.trim();
Header header = new Header(name, value.trim()); // Preserve the case for the field name
headers.put(name.toLowerCase(), header); Field field = new Field(name, value);
fields.put(name.toLowerCase(), field);
} }
/** /**
* <p>Inserts or replaces the given {@link Header}, mapped to the {@link Header#name() header's name}</p> * <p>Inserts or replaces the given {@link Field}, mapped to the {@link Field#name() field's name}</p>
* *
* @param header the header to add * @param field the field to put
*/ */
public void put(Header header) public void put(Field field)
{ {
if (header != null) if (field != null)
headers.put(header.name().toLowerCase(), header); fields.put(field.name().toLowerCase(), field);
} }
/** /**
* <p>Adds the given value to a header with the given name, creating a {@link Header} is none exists * <p>Adds the given value to a field with the given name,
* for the given name.</p> * creating a {@link Field} is none exists for the given name.</p>
* *
* @param name the header name * @param name the field name
* @param value the header value to add * @param value the field value to add
*/ */
public void add(String name, String value) public void add(String name, String value)
{ {
name = name.trim(); name = name.trim();
Header header = headers.get(name.toLowerCase()); Field field = fields.get(name.toLowerCase());
if (header == null) if (field == null)
{ {
header = new Header(name, value.trim()); field = new Field(name, value);
headers.put(name.toLowerCase(), header); fields.put(name.toLowerCase(), field);
} }
else else
{ {
header = new Header(header.name(), header.value() + "," + value.trim()); field = new Field(field.name(), field.values(), value);
headers.put(name.toLowerCase(), header); fields.put(name.toLowerCase(), field);
} }
} }
/** /**
* <p>Removes the {@link Header} with the given name</p> * <p>Removes the {@link Field} with the given name</p>
* *
* @param name the name of the header to remove * @param name the name of the field to remove
* @return the removed header, or null if no such header existed * @return the removed field, or null if no such field existed
*/ */
public Header remove(String name) public Field remove(String name)
{ {
name = name.trim(); name = name.trim();
return headers.remove(name.toLowerCase()); return fields.remove(name.toLowerCase());
} }
/** /**
* <p>Empties this {@link Headers} instance from all headers</p> * <p>Empties this {@link Fields} instance from all fields</p>
* @see #isEmpty() * @see #isEmpty()
*/ */
public void clear() public void clear()
{ {
headers.clear(); fields.clear();
} }
/** /**
* @return whether this {@link Headers} instance is empty * @return whether this {@link Fields} instance is empty
*/ */
public boolean isEmpty() public boolean isEmpty()
{ {
return headers.isEmpty(); return fields.isEmpty();
} }
/** /**
* @return the number of headers * @return the number of fields
*/ */
public int size() public int size()
{ {
return headers.size(); return fields.size();
} }
/** /**
* @return an iterator over the {@link Header} present in this instance * @return an iterator over the {@link Field}s present in this instance
*/ */
@Override @Override
public Iterator<Header> iterator() public Iterator<Field> iterator()
{ {
return headers.values().iterator(); return fields.values().iterator();
} }
@Override @Override
public String toString() public String toString()
{ {
return headers.toString(); return fields.toString();
} }
/** /**
* <p>A named list of string values.</p> * <p>A named list of string values.</p>
* <p>The name is case-sensitive and there must be at least one value.</p> * <p>The name is case-sensitive and there must be at least one value.</p>
*/ */
public static class Header public static class Field
{ {
private final String name; private final String name;
private final String[] values; private final String[] values;
private Header(String name, String value, String... values) private Field(String name, String value)
{
this(name, new String[]{value});
}
private Field(String name, String[] values, String... moreValues)
{ {
this.name = name; this.name = name;
this.values = new String[values.length + 1]; this.values = new String[values.length + moreValues.length];
this.values[0] = value; System.arraycopy(values, 0, this.values, 0, values.length);
if (values.length > 0) System.arraycopy(moreValues, 0, this.values, values.length, moreValues.length);
System.arraycopy(values, 0, this.values, 1, values.length);
} }
@Override @Override
@ -220,8 +225,8 @@ public class Headers implements Iterable<Headers.Header>
return true; return true;
if (obj == null || getClass() != obj.getClass()) if (obj == null || getClass() != obj.getClass())
return false; return false;
Header that = (Header)obj; Field that = (Field)obj;
// Header names must be lowercase, thus we lowercase them before transmission, but keep them as is // Field names must be lowercase, thus we lowercase them before transmission, but keep them as is
// internally. That's why we've to compare them case insensitive. // internally. That's why we've to compare them case insensitive.
return name.equalsIgnoreCase(that.name) && Arrays.equals(values, that.values); return name.equalsIgnoreCase(that.name) && Arrays.equals(values, that.values);
} }
@ -235,7 +240,7 @@ public class Headers implements Iterable<Headers.Header>
} }
/** /**
* @return the header's name * @return the field's name
*/ */
public String name() public String name()
{ {
@ -243,7 +248,7 @@ public class Headers implements Iterable<Headers.Header>
} }
/** /**
* @return the first header's value * @return the first field's value
*/ */
public String value() public String value()
{ {
@ -265,7 +270,7 @@ public class Headers implements Iterable<Headers.Header>
} }
/** /**
* @return the header's values * @return the field's values
*/ */
public String[] values() public String[] values()
{ {
@ -273,22 +278,7 @@ public class Headers implements Iterable<Headers.Header>
} }
/** /**
* @return the values as a comma separated list * @return whether the field has multiple values
*/
public String valuesAsString()
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < values.length; ++i)
{
if (i > 0)
result.append(", ");
result.append(values[i]);
}
return result.toString();
}
/**
* @return whether the header has multiple values
*/ */
public boolean hasMultipleValues() public boolean hasMultipleValues()
{ {