Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimone Bordet2013-07-24 09:21:36 +0000
committerSimone Bordet2013-07-24 09:21:36 +0000
commitf4a41efaadeaca417f259475557d1f071864cf4c (patch)
treeb734232cc0a4fcbb5023a8bddd3dad0353ef643c
parent1ab5de8ecdde942078e3961398964e55b2228b12 (diff)
parent0f702624a3011e3e1a953a4f0df468537caccd0d (diff)
downloadorg.eclipse.jetty.project-f4a41efaadeaca417f259475557d1f071864cf4c.tar.gz
org.eclipse.jetty.project-f4a41efaadeaca417f259475557d1f071864cf4c.tar.xz
org.eclipse.jetty.project-f4a41efaadeaca417f259475557d1f071864cf4c.zip
Merged branch 'master' into 'jetty-9.1'.
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java4
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java14
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/RedirectProtocolHandler.java9
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java10
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java2
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpSenderOverHTTP.java2
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java2
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java26
-rw-r--r--jetty-spdy/spdy-http-client-transport/src/main/java/org/eclipse/jetty/spdy/client/http/HttpSenderOverSPDY.java2
9 files changed, 43 insertions, 28 deletions
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java
index 2b3b138f2e..71ecf9ad40 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java
@@ -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);
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java
index 73357bf9e0..b9d1b3533c 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java
@@ -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;
}
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/RedirectProtocolHandler.java b/jetty-client/src/main/java/org/eclipse/jetty/client/RedirectProtocolHandler.java
index ee177dca11..125ef8c087 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/RedirectProtocolHandler.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/RedirectProtocolHandler.java
@@ -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);
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java b/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java
index d582028272..ebe117657c 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java
@@ -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
@@ -87,6 +87,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()
*/
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java
index d1ada96ea9..f398f375e1 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java
@@ -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);
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpSenderOverHTTP.java b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpSenderOverHTTP.java
index 69a64880e2..c18a92a41a 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpSenderOverHTTP.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpSenderOverHTTP.java
@@ -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
{
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java b/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java
index b6a54cb870..f45e4d29b3 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java
@@ -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)));
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java
index 6b27173c7a..15b2011874 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java
@@ -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()
{
diff --git a/jetty-spdy/spdy-http-client-transport/src/main/java/org/eclipse/jetty/spdy/client/http/HttpSenderOverSPDY.java b/jetty-spdy/spdy-http-client-transport/src/main/java/org/eclipse/jetty/spdy/client/http/HttpSenderOverSPDY.java
index 34ac5a5da0..3a48371c2b 100644
--- a/jetty-spdy/spdy-http-client-transport/src/main/java/org/eclipse/jetty/spdy/client/http/HttpSenderOverSPDY.java
+++ b/jetty-spdy/spdy-http-client-transport/src/main/java/org/eclipse/jetty/spdy/client/http/HttpSenderOverSPDY.java
@@ -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)

Back to the top