jetty-9 Use public HttpField

This commit is contained in:
Greg Wilkins 2012-12-07 14:01:18 +11:00
parent a20d984d30
commit 3e151901bf
10 changed files with 52 additions and 40 deletions

View File

@ -33,6 +33,7 @@ import org.eclipse.jetty.client.api.CookieStore;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpParser;
import org.eclipse.jetty.http.HttpVersion;
@ -183,7 +184,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
}
@Override
public boolean parsedHeader(HttpHeader header, String name, String value)
public boolean parsedHeader(HttpField field)
{
if (updateState(State.RECEIVE, State.RECEIVE))
{
@ -191,15 +192,16 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
// The exchange may be null if it failed concurrently
if (exchange != null)
{
exchange.getResponse().getHeaders().add(name, value);
switch (name.toLowerCase(Locale.ENGLISH))
exchange.getResponse().getHeaders().add(field);
if (field.getHeader()!=null)
switch (field.getHeader())
{
case "set-cookie":
case "set-cookie2":
case SET_COOKIE:
case SET_COOKIE2:
{
CookieStore cookieStore = connection.getHttpClient().getCookieStore();
HttpDestination destination = connection.getDestination();
List<HttpCookie> cookies = HttpCookieParser.parseCookies(value);
List<HttpCookie> cookies = HttpCookieParser.parseCookies(field.getValue());
for (HttpCookie cookie : cookies)
cookieStore.addCookie(destination, cookie);
break;

View File

@ -928,6 +928,11 @@ public class HttpFields implements Iterable<HttpField>
_fields.clear();
}
public void add(HttpField field)
{
_fields.add(field);
}
/**
* Add fields from another HttpFields instance. Single valued fields are replaced, while all
* others are added.

View File

@ -63,6 +63,7 @@ public class HttpParser
private final RequestHandler<ByteBuffer> _requestHandler;
private final ResponseHandler<ByteBuffer> _responseHandler;
private final int _maxHeaderBytes;
private HttpField _field;
private HttpHeader _header;
private String _headerString;
private HttpHeaderValue _value;
@ -646,7 +647,8 @@ public class HttpParser
if (_header!=null && handleKnownHeaders(buffer))
return true;
return_from_parse|=_handler.parsedHeader(_header, _headerString, _valueString);
return_from_parse|=_handler.parsedHeader(_field!=null?_field:new HttpField(_header,_headerString,_valueString));
_field=null;
}
_headerString=_valueString=null;
_header=null;
@ -717,18 +719,19 @@ public class HttpParser
if (buffer.remaining()>6 && buffer.hasArray())
{
// Try a look ahead for the known header name and value.
HttpField field=HttpField.CACHE.getBest(buffer.array(),buffer.arrayOffset()+buffer.position()-1,buffer.remaining()+1);
if (field!=null)
_field=HttpField.CACHE.getBest(buffer.array(),buffer.arrayOffset()+buffer.position()-1,buffer.remaining()+1);
if (_field!=null)
{
_header=field.getHeader();
_headerString=field.getName();
_valueString=field.getValue();
_header=_field.getHeader();
_headerString=_field.getName();
_valueString=_field.getValue();
if (_valueString==null)
{
setState(State.HEADER_VALUE);
buffer.position(buffer.position()+_headerString.length()+1);
_string.setLength(0);
_length=0;
_field=null;
}
else
{
@ -915,6 +918,7 @@ public class HttpParser
_string.append(_valueString);
_length=_valueString.length();
_valueString=null;
_field=null;
}
_string.append((char)ch);
setState(State.HEADER_VALUE);
@ -926,6 +930,7 @@ public class HttpParser
_string.append(_valueString);
_length=_valueString.length();
_valueString=null;
_field=null;
}
_string.append((char)ch);
_length++;
@ -1312,12 +1317,10 @@ public class HttpParser
/**
* This is the method called by parser when a HTTP Header name and value is found
* @param header The HttpHeader value if there is a match
* @param name The String value of the header name
* @param value The String value of the header
* @param field TODO
* @return
*/
public boolean parsedHeader(HttpHeader header, String name, String value);
public boolean parsedHeader(HttpField field);
public boolean earlyEOF();
@ -1333,7 +1336,7 @@ public class HttpParser
/**
* This is the method called by the parser after it has parsed the host header (and checked it's format). This is
* called after the {@link HttpHandler#parsedHeader(HttpHeader, String, String) methods and before
* called after the {@link HttpHandler#parsedHeader(HttpField) methods and before
* HttpHandler#headerComplete();
*/
public abstract boolean parsedHostHeader(String host,int port);

View File

@ -118,9 +118,9 @@ public class HttpTester
}
}
@Override
public boolean parsedHeader(HttpHeader header, String name, String value)
public boolean parsedHeader(HttpField field)
{
put(name,value);
put(field.getName(),field.getValue());
return false;
}

View File

@ -70,10 +70,10 @@ public class HttpGeneratorServerTest
}
@Override
public boolean parsedHeader(HttpHeader header, String name, String value)
public boolean parsedHeader(HttpField field)
{
_hdr.add(name);
_val.add(value);
_hdr.add(field.getName());
_val.add(field.getValue());
return false;
}

View File

@ -759,11 +759,11 @@ public class HttpParserTest
}
@Override
public boolean parsedHeader(HttpHeader header, String name, String value)
public boolean parsedHeader(HttpField field)
{
//System.err.println("header "+name+": "+value);
_hdr[++_h]= name;
_val[_h]= value;
_hdr[++_h]= field.getName();
_val[_h]= field.getValue();
return false;
}

View File

@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpGenerator;
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
@ -411,8 +412,10 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
}
@Override
public boolean parsedHeader(HttpHeader header, String name, String value)
public boolean parsedHeader(HttpField field)
{
HttpHeader header=field.getHeader();
String value=field.getValue();
if (value == null)
value = "";
if (header != null)
@ -467,8 +470,9 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
break;
}
}
if (name != null)
_request.getHttpFields().add(name, value);
if (field.getName()!=null)
_request.getHttpFields().add(field);
return false;
}

View File

@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.Queue;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpVersion;
@ -213,7 +214,7 @@ public class HttpChannelOverSPDY extends HttpChannel<DataInfo>
// Spec says headers must be single valued
String value = header.value();
LOG.debug("HTTP > {}: {}", name, value);
parsedHeader(httpHeader, name, value);
parsedHeader(new HttpField(name,value));
break;
}
}

View File

@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpGenerator;
import org.eclipse.jetty.http.HttpHeader;
@ -92,17 +93,12 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
}
@Override
public boolean parsedHeader(HttpHeader header, String headerName, String headerValue)
public boolean parsedHeader(HttpField field)
{
switch (headerName.toLowerCase(Locale.ENGLISH))
{
case "host":
headers.put(HTTPSPDYHeader.HOST.name(version), headerValue);
break;
default:
headers.put(headerName, headerValue);
break;
}
if (field.getHeader()==HttpHeader.HOST)
headers.put(HTTPSPDYHeader.HOST.name(version), field.getValue());
else
headers.put(field.getName(), field.getValue());
return false;
}

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.server.mux;
import java.io.IOException;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpVersion;
@ -95,7 +96,7 @@ public class MuxAddHandler implements MuxAddServer
HttpHeader header = HttpHeader.CACHE.getBest(headerName.getBytes(),0,headerName.length());
for (String value : request.getHeaders().get(headerName))
{
httpChannel.parsedHeader(header,headerName,value);
httpChannel.parsedHeader(new HttpField(header,value));
}
}