Merged branch 'master' into 'jetty-9.1'.

This commit is contained in:
Simone Bordet 2013-07-24 11:21:36 +02:00
commit f4a41efaad
9 changed files with 43 additions and 28 deletions

View File

@ -91,7 +91,7 @@ public abstract class HttpConnection implements Connection
if (request.getIdleTimeout() <= 0) if (request.getIdleTimeout() <= 0)
request.idleTimeout(client.getIdleTimeout(), TimeUnit.MILLISECONDS); request.idleTimeout(client.getIdleTimeout(), TimeUnit.MILLISECONDS);
HttpMethod method = request.getMethod(); String method = request.getMethod();
HttpVersion version = request.getVersion(); HttpVersion version = request.getVersion();
HttpFields headers = request.getHeaders(); HttpFields headers = request.getHeaders();
ContentProvider content = request.getContent(); ContentProvider content = request.getContent();
@ -106,7 +106,7 @@ public abstract class HttpConnection implements Connection
path = "/"; path = "/";
request.path(path); request.path(path);
} }
if (destination.isProxied() && HttpMethod.CONNECT != method) if (destination.isProxied() && !HttpMethod.CONNECT.is(method))
{ {
path = request.getURI().toString(); path = request.getURI().toString();
request.path(path); request.path(path);

View File

@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -65,7 +66,7 @@ public class HttpRequest implements Request
private String scheme; private String scheme;
private String path; private String path;
private String query; private String query;
private HttpMethod method; private String method;
private HttpVersion version; private HttpVersion version;
private long idleTimeout; private long idleTimeout;
private long timeout; private long timeout;
@ -125,7 +126,7 @@ public class HttpRequest implements Request
} }
@Override @Override
public HttpMethod getMethod() public String getMethod()
{ {
return method; return method;
} }
@ -133,7 +134,14 @@ public class HttpRequest implements Request
@Override @Override
public Request method(HttpMethod method) public Request method(HttpMethod method)
{ {
this.method = method; this.method = method.asString();
return this;
}
@Override
public Request method(String method)
{
this.method = Objects.requireNonNull(method).toUpperCase(Locale.ENGLISH);
return this; return this;
} }

View File

@ -95,8 +95,9 @@ public class RedirectProtocolHandler extends Response.Listener.Empty implements
{ {
case 301: case 301:
{ {
if (request.getMethod() == HttpMethod.GET || request.getMethod() == HttpMethod.HEAD) String method = request.getMethod();
redirect(result, request.getMethod(), newURI); if (HttpMethod.GET.is(method) || HttpMethod.HEAD.is(method))
redirect(result, method, newURI);
else else
fail(result, new HttpResponseException("HTTP protocol violation: received 301 for non GET or HEAD request", response)); fail(result, new HttpResponseException("HTTP protocol violation: received 301 for non GET or HEAD request", response));
break; break;
@ -105,7 +106,7 @@ public class RedirectProtocolHandler extends Response.Listener.Empty implements
case 303: case 303:
{ {
// Redirect must be done using GET // Redirect must be done using GET
redirect(result, HttpMethod.GET, newURI); redirect(result, HttpMethod.GET.asString(), newURI);
break; break;
} }
case 307: case 307:
@ -174,7 +175,7 @@ public class RedirectProtocolHandler extends Response.Listener.Empty implements
} }
} }
private void redirect(Result result, HttpMethod method, URI location) private void redirect(Result result, String method, URI location)
{ {
final Request request = result.getRequest(); final Request request = result.getRequest();
HttpConversation conversation = client.getConversation(request.getConversationID(), false); HttpConversation conversation = client.getConversation(request.getConversationID(), false);

View File

@ -76,9 +76,9 @@ public interface Request
int getPort(); int getPort();
/** /**
* @return the method of this request, such as GET or POST * @return the method of this request, such as GET or POST, as a String
*/ */
HttpMethod getMethod(); String getMethod();
/** /**
* @param method the method of this request, such as GET or POST * @param method the method of this request, such as GET or POST
@ -86,6 +86,12 @@ public interface Request
*/ */
Request method(HttpMethod method); Request method(HttpMethod method);
/**
* @param method the method of this request, such as GET or POST
* @return this request object
*/
Request method(String method);
/** /**
* @return the path of this request, such as "/" or "/path" - without the query * @return the path of this request, such as "/" or "/path" - without the query
* @see #getQuery() * @see #getQuery()

View File

@ -132,7 +132,7 @@ public class HttpReceiverOverHTTP extends HttpReceiver implements HttpParser.Res
if (exchange == null) if (exchange == null)
return false; return false;
parser.setHeadResponse(exchange.getRequest().getMethod() == HttpMethod.HEAD); parser.setHeadResponse(HttpMethod.HEAD.is(exchange.getRequest().getMethod()));
exchange.getResponse().version(version).status(status).reason(reason); exchange.getResponse().version(version).status(status).reason(reason);
responseBegin(exchange); responseBegin(exchange);

View File

@ -56,7 +56,7 @@ public class HttpSenderOverHTTP extends HttpSender
String query = request.getQuery(); String query = request.getQuery();
if (query != null) if (query != null)
path += "?" + query; path += "?" + query;
HttpGenerator.RequestInfo requestInfo = new HttpGenerator.RequestInfo(request.getVersion(), request.getHeaders(), contentLength, request.getMethod().asString(), path); HttpGenerator.RequestInfo requestInfo = new HttpGenerator.RequestInfo(request.getVersion(), request.getHeaders(), contentLength, request.getMethod(), path);
try try
{ {

View File

@ -221,7 +221,7 @@ public class DigestAuthentication implements Authentication
String A1 = user + ":" + realm + ":" + password; String A1 = user + ":" + realm + ":" + password;
String hashA1 = toHexString(digester.digest(A1.getBytes(charset))); String hashA1 = toHexString(digester.digest(A1.getBytes(charset)));
String A2 = request.getMethod().asString() + ":" + request.getURI(); String A2 = request.getMethod() + ":" + request.getURI();
if ("auth-int".equals(qop)) if ("auth-int".equals(qop))
A2 += ":" + toHexString(digester.digest(content)); A2 += ":" + toHexString(digester.digest(content));
String hashA2 = toHexString(digester.digest(A2.getBytes(charset))); String hashA2 = toHexString(digester.digest(A2.getBytes(charset)));

View File

@ -41,7 +41,7 @@ public enum HttpMethod
MOVE; MOVE;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* Optimised lookup to find a method name and trailing space in a byte array. * Optimised lookup to find a method name and trailing space in a byte array.
* @param bytes Array containing ISO-8859-1 characters * @param bytes Array containing ISO-8859-1 characters
* @param position The first valid index * @param position The first valid index
@ -70,22 +70,22 @@ public enum HttpMethod
return HEAD; return HEAD;
break; break;
case 'O': case 'O':
if (bytes[position+1]=='O' && bytes[position+2]=='T' && bytes[position+3]=='I' && length>=8 && if (bytes[position+1]=='O' && bytes[position+2]=='T' && bytes[position+3]=='I' && length>=8 &&
bytes[position+4]=='O' && bytes[position+5]=='N' && bytes[position+6]=='S' && bytes[position+7]==' ' ) bytes[position+4]=='O' && bytes[position+5]=='N' && bytes[position+6]=='S' && bytes[position+7]==' ' )
return OPTIONS; return OPTIONS;
break; break;
case 'D': case 'D':
if (bytes[position+1]=='E' && bytes[position+2]=='L' && bytes[position+3]=='E' && length>=7 && if (bytes[position+1]=='E' && bytes[position+2]=='L' && bytes[position+3]=='E' && length>=7 &&
bytes[position+4]=='T' && bytes[position+5]=='E' && bytes[position+6]==' ' ) bytes[position+4]=='T' && bytes[position+5]=='E' && bytes[position+6]==' ' )
return DELETE; return DELETE;
break; break;
case 'T': case 'T':
if (bytes[position+1]=='R' && bytes[position+2]=='A' && bytes[position+3]=='C' && length>=6 && if (bytes[position+1]=='R' && bytes[position+2]=='A' && bytes[position+3]=='C' && length>=6 &&
bytes[position+4]=='E' && bytes[position+5]==' ' ) bytes[position+4]=='E' && bytes[position+5]==' ' )
return TRACE; return TRACE;
break; break;
case 'C': case 'C':
if (bytes[position+1]=='O' && bytes[position+2]=='N' && bytes[position+3]=='N' && length>=8 && if (bytes[position+1]=='O' && bytes[position+2]=='N' && bytes[position+3]=='N' && length>=8 &&
bytes[position+4]=='E' && bytes[position+5]=='C' && bytes[position+6]=='T' && bytes[position+7]==' ' ) bytes[position+4]=='E' && bytes[position+5]=='C' && bytes[position+6]=='T' && bytes[position+7]==' ' )
return CONNECT; return CONNECT;
break; break;
@ -93,7 +93,7 @@ public enum HttpMethod
if (bytes[position+1]=='O' && bytes[position+2]=='V' && bytes[position+3]=='E' && bytes[position+4]==' ') if (bytes[position+1]=='O' && bytes[position+2]=='V' && bytes[position+3]=='E' && bytes[position+4]==' ')
return MOVE; return MOVE;
break; break;
default: default:
break; break;
} }
@ -101,7 +101,7 @@ public enum HttpMethod
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* Optimised lookup to find a method name and trailing space in a byte array. * Optimised lookup to find a method name and trailing space in a byte array.
* @param buffer buffer containing ISO-8859-1 characters * @param buffer buffer containing ISO-8859-1 characters
* @return A HttpMethod if a match or null if no easy match. * @return A HttpMethod if a match or null if no easy match.
@ -110,14 +110,14 @@ public enum HttpMethod
{ {
if (buffer.hasArray()) if (buffer.hasArray())
return lookAheadGet(buffer.array(),buffer.arrayOffset()+buffer.position(),buffer.arrayOffset()+buffer.limit()); return lookAheadGet(buffer.array(),buffer.arrayOffset()+buffer.position(),buffer.arrayOffset()+buffer.limit());
// TODO use cache and check for space // TODO use cache and check for space
// return CACHE.getBest(buffer,0,buffer.remaining()); // return CACHE.getBest(buffer,0,buffer.remaining());
return null; return null;
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public final static Trie<HttpMethod> CACHE= new ArrayTrie<HttpMethod>(); public final static Trie<HttpMethod> CACHE= new ArrayTrie<>();
static static
{ {
for (HttpMethod method : HttpMethod.values()) for (HttpMethod method : HttpMethod.values())
@ -144,15 +144,15 @@ public enum HttpMethod
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public boolean is(String s) public boolean is(String s)
{ {
return toString().equalsIgnoreCase(s); return toString().equalsIgnoreCase(s);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public ByteBuffer asBuffer() public ByteBuffer asBuffer()
{ {
return _buffer.asReadOnlyBuffer(); return _buffer.asReadOnlyBuffer();
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public String asString() public String asString()
{ {

View File

@ -65,7 +65,7 @@ public class HttpSenderOverSPDY extends HttpSender
} }
// Add special SPDY headers // Add special SPDY headers
fields.put(HTTPSPDYHeader.METHOD.name(spdyVersion), request.getMethod().asString()); fields.put(HTTPSPDYHeader.METHOD.name(spdyVersion), request.getMethod());
String path = request.getPath(); String path = request.getPath();
String query = request.getQuery(); String query = request.getQuery();
if (query != null) if (query != null)