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

View File

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

View File

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

View File

@ -76,9 +76,9 @@ public interface Request
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
@ -86,6 +86,12 @@ public interface Request
*/
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
* @see #getQuery()

View File

@ -132,7 +132,7 @@ public class HttpReceiverOverHTTP extends HttpReceiver implements HttpParser.Res
if (exchange == null)
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);
responseBegin(exchange);

View File

@ -56,7 +56,7 @@ public class HttpSenderOverHTTP extends HttpSender
String query = request.getQuery();
if (query != null)
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
{

View File

@ -221,7 +221,7 @@ public class DigestAuthentication implements Authentication
String A1 = user + ":" + realm + ":" + password;
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))
A2 += ":" + toHexString(digester.digest(content));
String hashA2 = toHexString(digester.digest(A2.getBytes(charset)));

View File

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

View File

@ -65,7 +65,7 @@ public class HttpSenderOverSPDY extends HttpSender
}
// 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 query = request.getQuery();
if (query != null)