diff --git a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/HttpChannelOverFCGI.java b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/HttpChannelOverFCGI.java index df7afda8482..d99e709ffb7 100644 --- a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/HttpChannelOverFCGI.java +++ b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/HttpChannelOverFCGI.java @@ -23,13 +23,11 @@ import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jetty.fcgi.FCGI; -import org.eclipse.jetty.http.FinalMetaData; import org.eclipse.jetty.http.HostPortHttpField; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpScheme; -import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.MetaData; import org.eclipse.jetty.io.EndPoint; @@ -90,7 +88,7 @@ public class HttpChannelOverFCGI extends HttpChannel if (query != null && query.length() > 0) uri += "?" + query; // TODO https? - onRequest(new FinalMetaData.Request(HttpVersion.fromString(version), HttpScheme.HTTP.asString(), method, uri, fields, hostPort)); + onRequest(new MetaData.Request(method, HttpScheme.HTTP.asString(), hostPort, uri, HttpVersion.fromString(version), fields)); } private HttpField convertHeader(HttpField field) diff --git a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java index b10beec9d86..3b1bb864d51 100644 --- a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java +++ b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java @@ -22,6 +22,7 @@ import java.net.URI; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; + import javax.servlet.RequestDispatcher; import javax.servlet.ServletConfig; import javax.servlet.ServletException; diff --git a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/TryFilesFilter.java b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/TryFilesFilter.java index 2ce21643587..5e4e660c662 100644 --- a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/TryFilesFilter.java +++ b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/TryFilesFilter.java @@ -24,6 +24,7 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; + import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; diff --git a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/EmptyServerHandler.java b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/EmptyServerHandler.java index 7eaf4e2091e..9097da7ad66 100644 --- a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/EmptyServerHandler.java +++ b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/EmptyServerHandler.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.fcgi.server; import java.io.IOException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/HttpClientTest.java b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/HttpClientTest.java index e97750f8b50..d0522dd6d57 100644 --- a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/HttpClientTest.java +++ b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/HttpClientTest.java @@ -32,6 +32,7 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.zip.GZIPOutputStream; + import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; diff --git a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServletTest.java b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServletTest.java index a52a044e956..7fe651ec27e 100644 --- a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServletTest.java +++ b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServletTest.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Random; import java.util.concurrent.TimeUnit; + import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; diff --git a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/TryFilesFilterTest.java b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/TryFilesFilterTest.java index e1d78c79b44..9cd494dace8 100644 --- a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/TryFilesFilterTest.java +++ b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/TryFilesFilterTest.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.fcgi.server.proxy; import java.io.IOException; import java.util.EnumSet; + import javax.servlet.DispatcherType; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; diff --git a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/WordPressSPDYFastCGIProxyServer.java b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/WordPressSPDYFastCGIProxyServer.java index ea023a4b00a..7a52784e9d0 100644 --- a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/WordPressSPDYFastCGIProxyServer.java +++ b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/proxy/WordPressSPDYFastCGIProxyServer.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.fcgi.server.proxy; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; + import javax.servlet.DispatcherType; import org.eclipse.jetty.server.Server; diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractMetaData.java b/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractMetaData.java deleted file mode 100644 index 524e94b1113..00000000000 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractMetaData.java +++ /dev/null @@ -1,163 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.http; - -import java.util.Iterator; - -public abstract class AbstractMetaData implements MetaData -{ - @Override - public boolean isRequest() - { - return false; - } - - @Override - public boolean isResponse() - { - return false; - } - - @Override - public Iterator iterator() - { - return getFields().iterator(); - } - - @Override - public int hashCode() - { - return 31 * getHttpVersion().hashCode() + getFields().hashCode(); - } - - @Override - public boolean equals(Object o) - { - if (this == o) - return true; - if (!(o instanceof AbstractMetaData)) - return false; - AbstractMetaData that = (AbstractMetaData)o; - - if (getHttpVersion() != that.getHttpVersion()) - return false; - - return getFields().equals(that.getFields()); - } - - @Override - public String toString() - { - StringBuilder out = new StringBuilder(); - for (HttpField field: this) - out.append(field).append(System.lineSeparator()); - return out.toString(); - } - - /* -------------------------------------------------------- */ - /* -------------------------------------------------------- */ - /* -------------------------------------------------------- */ - public abstract static class Request extends AbstractMetaData implements MetaData.Request - { - @Override - public boolean isRequest() - { - return true; - } - - @Override - public boolean isResponse() - { - return false; - } - - @Override - public int hashCode() - { - int hash = getMethod().hashCode(); - hash = 31 * hash + getScheme().hashCode(); - hash = 31 * hash + getURI().hashCode(); - return 31 * hash + super.hashCode(); - } - - @Override - public boolean equals(Object o) - { - if (this == o) - return true; - if (!(o instanceof MetaData.Request)) - return false; - MetaData.Request that = (MetaData.Request)o; - if (!getMethod().equals(that.getMethod()) || - !getScheme().equals(that.getScheme()) || - !getURI().equals(that.getURI())) - return false; - return super.equals(o); - } - - @Override - public String toString() - { - return String.format("%s %s://%s:%d%s HTTP/2%s%s", - getMethod(), getScheme(), getHost(), getPort(), getURI(), System.lineSeparator(), super.toString()); - } - } - - /* -------------------------------------------------------- */ - /* -------------------------------------------------------- */ - /* -------------------------------------------------------- */ - public abstract static class Response extends AbstractMetaData implements MetaData.Response - { - @Override - public boolean isRequest() - { - return false; - } - - @Override - public boolean isResponse() - { - return true; - } - @Override - public int hashCode() - { - return 31 * getStatus() + super.hashCode(); - } - - @Override - public boolean equals(Object o) - { - if (this == o) - return true; - if (!(o instanceof MetaData.Response)) - return false; - MetaData.Response that = (MetaData.Response)o; - if (getStatus() != that.getStatus()) - return false; - return super.equals(o); - } - - @Override - public String toString() - { - return String.format("HTTP/2 %d%s%s", getStatus(), System.lineSeparator(), super.toString()); - } - } -} diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/FinalMetaData.java b/jetty-http/src/main/java/org/eclipse/jetty/http/FinalMetaData.java deleted file mode 100644 index e3a2bac20f2..00000000000 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/FinalMetaData.java +++ /dev/null @@ -1,160 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.http; - - -public class FinalMetaData extends AbstractMetaData -{ - private final HttpVersion _version; - private final HttpFields _fields; - - public FinalMetaData(HttpVersion version,HttpFields fields) - { - _fields=fields; - _version=version; - } - - @Override - public HttpVersion getHttpVersion() - { - return _version; - } - - @Override - public HttpFields getFields() - { - return _fields; - } - - - /* -------------------------------------------------------- */ - /* -------------------------------------------------------- */ - /* -------------------------------------------------------- */ - public static class Request extends AbstractMetaData.Request - { - private final HttpVersion _version; - private final HttpFields _fields; - private final String _method; - private final String _uri; - private final HostPortHttpField _hostPort; - private final HttpScheme _scheme; - - public Request(HttpVersion version, String scheme, String method, String uri, HttpFields fields, HostPortHttpField hostPort) - { - _fields=fields; - _version=version; - _method=method; - _uri=uri; - _hostPort = hostPort; - if (scheme == null) - _scheme = HttpScheme.HTTP; - else - { - HttpScheme s = HttpScheme.CACHE.get(scheme); - _scheme = s == null ? HttpScheme.HTTP : s; - } - } - - public Request(HttpVersion version, HttpScheme scheme, String method, HostPortHttpField authority, String path, HttpFields fields) - { - _fields=fields; - _version=version; - _method=method; - _uri=path; - _hostPort = authority; - _scheme=scheme; - } - - @Override - public HttpVersion getHttpVersion() - { - return _version; - } - - @Override - public HttpFields getFields() - { - return _fields; - } - - @Override - public String getMethod() - { - return _method; - } - - @Override - public HttpScheme getScheme() - { - return _scheme; - } - - @Override - public String getHost() - { - return _hostPort==null?null:_hostPort.getHost(); - } - - @Override - public int getPort() - { - return _hostPort==null?0:_hostPort.getPort(); - } - - @Override - public String getURI() - { - return _uri; - } - } - - /* -------------------------------------------------------- */ - /* -------------------------------------------------------- */ - /* -------------------------------------------------------- */ - public static class Response extends AbstractMetaData.Response - { - private final HttpVersion _version; - private final HttpFields _fields; - private final int _status; - - public Response(HttpVersion version, int status, HttpFields fields) - { - _fields=fields; - _version=version; - _status=status; - } - - @Override - public HttpVersion getHttpVersion() - { - return _version; - } - - @Override - public HttpFields getFields() - { - return _fields; - } - - public int getStatus() - { - return _status; - } - } -} diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java index 978593a9f02..bdc251bdc38 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java @@ -564,7 +564,10 @@ public class HttpFields implements Iterable @Override public int hashCode() { - return _fields.hashCode(); + int hash=0; + for (HttpField field:_fields) + hash+=field.hashCode(); + return hash; } @Override diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java index fc7cdb7d61d..f9c48a2f73f 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.http; import java.io.UnsupportedEncodingException; import java.net.URI; +import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -50,297 +51,244 @@ import org.eclipse.jetty.util.UrlEncoded; */ public class HttpURI { - private final static int - START=0, - AUTH_OR_PATH=1, - SCHEME_OR_PATH=2, - AUTH=4, - IPV6=5, - PORT=6, - PATH=7, - PARAM=8, - QUERY=9, - ASTERISK=10; + private enum State { + START, + HOST_OR_PATH, + SCHEME_OR_PATH, + HOST, + IPV6, + PORT, + PATH, + PARAM, + QUERY, + FRAGMENT, + ASTERISK}; - boolean _partial=false; + private String _scheme; + private String _host; + private int _port; + private String _path; + private String _param; + private String _query; + private String _fragment; + String _uri; - int _scheme; - int _authority; - int _host; - int _port; - int _portValue; - int _path; - int _param; - int _query; - int _fragment; - int _end; - boolean _encoded=false; + String _decodedPath; + /* ------------------------------------------------------------ */ public HttpURI() { } /* ------------------------------------------------------------ */ - /** - * @param parsePartialAuth If True, parse auth without prior scheme, else treat all URIs starting with / as paths - */ - public HttpURI(boolean parsePartialAuth) - { - _partial=parsePartialAuth; - } - public HttpURI(String uri) { - _uri=uri; parse(uri); + parse(State.START,uri,0,uri.length()); } + /* ------------------------------------------------------------ */ public HttpURI(URI uri) { - this(uri.toASCIIString()); + _uri=null; + + _scheme=uri.getScheme(); + _host=uri.getHost(); + _port=uri.getPort(); + _path=uri.getRawPath(); + _decodedPath=uri.getPath(); + int p=_path.lastIndexOf(';'); + if (p>=0) + _param=_path.substring(p+1); + _query=uri.getRawQuery(); + _fragment=uri.getFragment(); + + _decodedPath=null; } - - public void parseConnect(String authority) + /* ------------------------------------------------------------ */ + public HttpURI(String scheme, String host, int port, String pathQuery) { - parseConnect(authority,0,authority.length()); + _uri=null; + + _scheme=scheme; + _host=host; + _port=port; + + parse(State.PATH,pathQuery,0,pathQuery.length()); + } - - public void parseConnect(String authority,int offset,int length) - { - _uri=authority; - _encoded=false; - int i=offset; - int e=offset+length; - int state=AUTH; - _end=offset+length; - _scheme=offset; - _authority=offset; - _host=offset; - _port=_end; - _portValue=-1; - _path=_end; - _param=_end; - _query=_end; - _fragment=_end; - loop: while (i_query); + return _query!=null && _query.length()>0; } + /* ------------------------------------------------------------ */ public String getFragment() { - if (_fragment==_end) - return null; - - return _uri.substring(_fragment+1,_end); + return _fragment; } + /* ------------------------------------------------------------ */ public void decodeQueryTo(MultiMap parameters) { if (_query==_fragment) return; - UrlEncoded.decodeUtf8To(_uri,_query+1,_fragment-_query-1,parameters); + UrlEncoded.decodeUtf8To(_query,parameters); } + /* ------------------------------------------------------------ */ public void decodeQueryTo(MultiMap parameters, String encoding) throws UnsupportedEncodingException { - if (_query==_fragment) - return; decodeQueryTo(parameters,Charset.forName(encoding)); } + /* ------------------------------------------------------------ */ public void decodeQueryTo(MultiMap parameters, Charset encoding) throws UnsupportedEncodingException { if (_query==_fragment) return; if (encoding==null || StandardCharsets.UTF_8.equals(encoding)) - UrlEncoded.decodeUtf8To(_uri,_query+1,_fragment-_query-1,parameters); + UrlEncoded.decodeUtf8To(_query,parameters); else - UrlEncoded.decodeTo(_uri.substring(_query+1,_fragment-_query-1),parameters,encoding); + UrlEncoded.decodeTo(_query,parameters,encoding); } + /* ------------------------------------------------------------ */ public void clear() { - _scheme=_authority=_host=_port=_path=_param=_query=_fragment=_end=0; _uri=null; - _encoded=false; + + _scheme=null; + _host=null; + _port=-1; + _path=null; + _param=null; + _query=null; + _fragment=null; + + _decodedPath=null; } + /* ------------------------------------------------------------ */ + public boolean isAbsolute() + { + return _scheme!=null && _scheme.length()>0; + } + + /* ------------------------------------------------------------ */ @Override public String toString() { + if (_uri==null) + { + StringBuilder out = new StringBuilder(); + + if (_scheme!=null) + out.append(_scheme).append(':'); + + if (_host!=null) + out.append("//").append(_host); + + if (_port>0) + out.append(':').append(_port); + + if (_path!=null) + out.append(_path); + + if (_query!=null) + out.append('?').append(_query); + + if (_fragment!=null) + out.append('#').append(_fragment); + + if (out.length()>0) + _uri=out.toString(); + else + _uri=""; + } return _uri; } + /* ------------------------------------------------------------ */ public boolean equals(Object o) { if (o==this) @@ -590,4 +624,37 @@ public class HttpURI return toString().equals(o.toString()); } + /* ------------------------------------------------------------ */ + /** + * @param host + * @param port + */ + public void setAuth(String host, int port) + { + _host=host; + _port=port; + _uri=null; + } + + /* ------------------------------------------------------------ */ + public URI toURI() throws URISyntaxException + { + return new URI(_scheme,null,_host,_port,_path,_query==null?null:UrlEncoded.decodeString(_query),_fragment); + } + + /* ------------------------------------------------------------ */ + public String getPathQuery() + { + if (_query==null) + return _path; + return _path+"?"+_query; + } + + /* ------------------------------------------------------------ */ + public String getAuthority() + { + if (_port>0) + return _host+":"+_port; + return _host; + } } diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java b/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java index 4bf47ab3793..30405fe92b6 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java @@ -18,30 +18,299 @@ package org.eclipse.jetty.http; -public interface MetaData extends Iterable +import java.util.Iterator; + +public class MetaData implements Iterable { - public HttpVersion getHttpVersion(); - public boolean isRequest(); - public boolean isResponse(); - public HttpFields getFields(); + private HttpVersion _httpVersion; + private HttpFields _fields; + + /* ------------------------------------------------------------ */ + public MetaData() + { + } + + /* ------------------------------------------------------------ */ + public MetaData(HttpVersion version, HttpFields fields) + { + _httpVersion = version; + _fields = fields; + } + + /* ------------------------------------------------------------ */ + public boolean isRequest() + { + return false; + } + + /* ------------------------------------------------------------ */ + public boolean isResponse() + { + return false; + } + + /* ------------------------------------------------------------ */ + /** Get the httpVersion. + * @return the httpVersion + */ + public HttpVersion getVersion() + { + return _httpVersion; + } + + /* ------------------------------------------------------------ */ + /** Set the httpVersion. + * @param httpVersion the httpVersion to set + */ + public void setHttpVersion(HttpVersion httpVersion) + { + _httpVersion = httpVersion; + } + + /* ------------------------------------------------------------ */ + /** Get the fields. + * @return the fields + */ + public HttpFields getFields() + { + return _fields; + } + + /* ------------------------------------------------------------ */ + /** Set the fields. + * @param fields the fields to set + */ + public void setFields(HttpFields fields) + { + _fields = fields; + } + + /* ------------------------------------------------------------ */ + public Iterator iterator() + { + return getFields().iterator(); + } + + /* ------------------------------------------------------------ */ + @Override + public int hashCode() + { + return 31 * getVersion().hashCode() + getFields().hashCode(); + } + + /* ------------------------------------------------------------ */ + @Override + public boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof MetaData)) + return false; + MetaData that = (MetaData)o; + + if (getVersion() != that.getVersion()) + return false; + + return getFields().equals(that.getFields()); + } + + /* ------------------------------------------------------------ */ + @Override + public String toString() + { + StringBuilder out = new StringBuilder(); + for (HttpField field: this) + out.append(field).append(System.lineSeparator()); + return out.toString(); + } /* -------------------------------------------------------- */ /* -------------------------------------------------------- */ /* -------------------------------------------------------- */ - public interface Request extends MetaData + public static class Request extends MetaData { - public String getMethod(); - public HttpScheme getScheme(); - public String getHost(); - public int getPort(); - public String getURI(); + private String _method; + private HttpURI _uri; + + public Request() + { + } + + /* ------------------------------------------------------------ */ + /** + * @param method + * @param uri + * @param version + * @param fields + */ + public Request(String method, HttpURI uri, HttpVersion version, HttpFields fields) + { + super(version,fields); + _method = method; + _uri = uri; + } + + /* ------------------------------------------------------------ */ + public Request(String method, HttpScheme scheme, HostPortHttpField hostPort, String uri, HttpVersion version, HttpFields fields) + { + this(method,new HttpURI(scheme==null?null:scheme.asString(),hostPort.getHost(),hostPort.getPort(),uri),version,fields); + } + + /* ------------------------------------------------------------ */ + public Request(String method, String scheme, HostPortHttpField hostPort, String uri, HttpVersion version, HttpFields fields) + { + this(method,new HttpURI(scheme,hostPort.getHost(),hostPort.getPort(),uri),version,fields); + } + + /* ------------------------------------------------------------ */ + @Override + public boolean isRequest() + { + return true; + } + + /* ------------------------------------------------------------ */ + /** Get the method. + * @return the method + */ + public String getMethod() + { + return _method; + } + + /* ------------------------------------------------------------ */ + /** Set the method. + * @param method the method to set + */ + public void setMethod(String method) + { + _method = method; + } + + /* ------------------------------------------------------------ */ + /** Get the uri. + * @return the uri + */ + public HttpURI getURI() + { + return _uri; + } + + /* ------------------------------------------------------------ */ + /** Set the uri. + * @param uri the uri to set + */ + public void setURI(HttpURI uri) + { + _uri = uri; + } + + /* ------------------------------------------------------------ */ + @Override + public int hashCode() + { + return ((super.hashCode()*31)+_method.hashCode())*31+_uri.hashCode(); + } + + /* ------------------------------------------------------------ */ + @Override + public boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof MetaData.Request)) + return false; + MetaData.Request that = (MetaData.Request)o; + if (!getMethod().equals(that.getMethod()) || + !getURI().equals(that.getURI())) + return false; + return super.equals(o); + } + + /* ------------------------------------------------------------ */ + @Override + public String toString() + { + return String.format("%s %s %s%s%s", + getMethod(), getURI(), getVersion(), System.lineSeparator(), super.toString()); + } } /* -------------------------------------------------------- */ /* -------------------------------------------------------- */ /* -------------------------------------------------------- */ - public interface Response extends MetaData + public static class Response extends MetaData { - public int getStatus(); + private int _status; + + public Response() + { + } + + /* ------------------------------------------------------------ */ + /** + * @param version + * @param fields + * @param status + */ + public Response(HttpVersion version, int status, HttpFields fields) + { + super(version,fields); + _status=status; + } + + /* ------------------------------------------------------------ */ + @Override + public boolean isResponse() + { + return true; + } + + /* ------------------------------------------------------------ */ + /** Get the status. + * @return the status + */ + public int getStatus() + { + return _status; + } + + /* ------------------------------------------------------------ */ + /** Set the status. + * @param status the status to set + */ + public void setStatus(int status) + { + _status = status; + } + + /* ------------------------------------------------------------ */ + @Override + public int hashCode() + { + return 31 * getStatus() + super.hashCode(); + } + + /* ------------------------------------------------------------ */ + @Override + public boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof MetaData.Response)) + return false; + MetaData.Response that = (MetaData.Response)o; + if (getStatus() != that.getStatus()) + return false; + return super.equals(o); + } + + /* ------------------------------------------------------------ */ + @Override + public String toString() + { + return String.format("%s %d%s%s",getVersion(), getStatus(), System.lineSeparator(), super.toString()); + } + } } diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java index b5502fd9f96..1557a8425ff 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.http; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -75,7 +74,8 @@ public class HttpURITest { for (String[] test:tests) { - HttpURI uri = new HttpURI(new URI(test[INPUT])); + URI u=new URI(test[INPUT]); + HttpURI uri = new HttpURI(u); assertEquals(test[SCHEME], uri.getScheme()); assertEquals(test[HOST], uri.getHost()); @@ -84,67 +84,11 @@ public class HttpURITest assertEquals(test[PARAM], uri.getParam()); assertEquals(test[QUERY], uri.getQuery()); assertEquals(test[FRAGMENT], uri.getFragment()); + + assertEquals(u,uri.toURI()); } } - private final String[][] partial_tests= - { - /* 0*/ {"/path/info",null,null,null,null,"/path/info",null,null,null}, - /* 1*/ {"/path/info#fragment",null,null,null,null,"/path/info",null,null,"fragment"}, - /* 2*/ {"/path/info?query",null,null,null,null,"/path/info",null,"query",null}, - /* 3*/ {"/path/info?query#fragment",null,null,null,null,"/path/info",null,"query","fragment"}, - /* 4*/ {"/path/info;param",null,null,null,null,"/path/info;param","param",null,null}, - /* 5*/ {"/path/info;param#fragment",null,null,null,null,"/path/info;param","param",null,"fragment"}, - /* 6*/ {"/path/info;param?query",null,null,null,null,"/path/info;param","param","query",null}, - /* 7*/ {"/path/info;param?query#fragment",null,null,null,null,"/path/info;param","param","query","fragment"}, - /* 8*/ {"//host/path/info",null,"//host","host",null,"/path/info",null,null,null}, - /* 9*/ {"//user@host/path/info",null,"//user@host","host",null,"/path/info",null,null,null}, - /*10*/ {"//user@host:8080/path/info",null,"//user@host:8080","host","8080","/path/info",null,null,null}, - /*11*/ {"//host:8080/path/info",null,"//host:8080","host","8080","/path/info",null,null,null}, - /*12*/ {"http:/path/info","http",null,null,null,"/path/info",null,null,null}, - /*13*/ {"http:/path/info#fragment","http",null,null,null,"/path/info",null,null,"fragment"}, - /*14*/ {"http:/path/info?query","http",null,null,null,"/path/info",null,"query",null}, - /*15*/ {"http:/path/info?query#fragment","http",null,null,null,"/path/info",null,"query","fragment"}, - /*16*/ {"http:/path/info;param","http",null,null,null,"/path/info;param","param",null,null}, - /*17*/ {"http:/path/info;param#fragment","http",null,null,null,"/path/info;param","param",null,"fragment"}, - /*18*/ {"http:/path/info;param?query","http",null,null,null,"/path/info;param","param","query",null}, - /*19*/ {"http:/path/info;param?query#fragment","http",null,null,null,"/path/info;param","param","query","fragment"}, - /*20*/ {"http://user@host:8080/path/info;param?query#fragment","http","//user@host:8080","host","8080","/path/info;param","param","query","fragment"}, - /*21*/ {"xxxxx://user@host:8080/path/info;param?query#fragment","xxxxx","//user@host:8080","host","8080","/path/info;param","param","query","fragment"}, - /*22*/ {"http:///;?#","http","//",null,null,"/;","","",""}, - /*23*/ {"/path/info?a=?query",null,null,null,null,"/path/info",null,"a=?query",null}, - /*24*/ {"/path/info?a=;query",null,null,null,null,"/path/info",null,"a=;query",null}, - /*25*/ {"//host:8080//",null,"//host:8080","host","8080","//",null,null,null}, - /*26*/ {"file:///path/info","file","//",null,null,"/path/info",null,null,null}, - /*27*/ {"//",null,"//",null,null,null,null,null,null}, - /*28*/ {"/;param",null, null, null,null,"/;param", "param",null,null}, - /*29*/ {"/?x=y",null, null, null,null,"/", null,"x=y",null}, - /*30*/ {"/?abc=test",null, null, null,null,"/", null,"abc=test",null}, - /*31*/ {"/#fragment",null, null, null,null,"/", null,null,"fragment"}, - /*32*/ {"http://localhost:8080", "http", "//localhost:8080", "localhost", "8080", null, null, null, null}, - /*33*/ {"./?foo:bar=:1:1::::",null,null,null,null,"./",null,"foo:bar=:1:1::::",null} - }; - - @Test - public void testPartialURIs() throws Exception - { - HttpURI uri = new HttpURI(true); - - for (int t=0;t frames = new ArrayList<>(); Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() @@ -84,10 +83,7 @@ public class HeadersGenerateParseTest Assert.assertEquals(streamId, frame.getStreamId()); Assert.assertTrue(frame.isEndStream()); MetaData.Request request = (MetaData.Request)frame.getMetaData(); - Assert.assertSame(metaData.getScheme(), request.getScheme()); Assert.assertEquals(metaData.getMethod(), request.getMethod()); - Assert.assertEquals(metaData.getHost(), request.getHost()); - Assert.assertEquals(metaData.getPort(), request.getPort()); Assert.assertEquals(metaData.getURI(), request.getURI()); for (int j = 0; j < fields.size(); ++j) { @@ -117,7 +113,7 @@ public class HeadersGenerateParseTest HttpFields fields = new HttpFields(); fields.put("Accept", "text/html"); fields.put("User-Agent", "Jetty"); - MetaData.Request metaData = new FinalMetaData.Request(HttpVersion.HTTP_2, HttpScheme.HTTP, "GET", new HostPortHttpField("localhost:8080"), "/path", fields); + MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:8080"), "/path", HttpVersion.HTTP_2, fields); ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); generator.generateHeaders(lease, streamId, metaData, false); @@ -135,10 +131,7 @@ public class HeadersGenerateParseTest Assert.assertEquals(streamId, frame.getStreamId()); Assert.assertTrue(frame.isEndStream()); MetaData.Request request = (MetaData.Request)frame.getMetaData(); - Assert.assertSame(metaData.getScheme(), request.getScheme()); Assert.assertEquals(metaData.getMethod(), request.getMethod()); - Assert.assertEquals(metaData.getHost(), request.getHost()); - Assert.assertEquals(metaData.getPort(), request.getPort()); Assert.assertEquals(metaData.getURI(), request.getURI()); for (int j = 0; j < fields.size(); ++j) { diff --git a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PushPromiseGenerateParseTest.java b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PushPromiseGenerateParseTest.java index b8a7827a889..b636086ef8f 100644 --- a/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PushPromiseGenerateParseTest.java +++ b/jetty-http2/http2-common/src/test/java/org/eclipse/jetty/http2/frames/PushPromiseGenerateParseTest.java @@ -22,7 +22,6 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; -import org.eclipse.jetty.http.FinalMetaData; import org.eclipse.jetty.http.HostPortHttpField; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpFields; @@ -63,7 +62,7 @@ public class PushPromiseGenerateParseTest HttpFields fields = new HttpFields(); fields.put("Accept", "text/html"); fields.put("User-Agent", "Jetty"); - MetaData.Request metaData = new FinalMetaData.Request(HttpVersion.HTTP_2, HttpScheme.HTTP, "GET", new HostPortHttpField("localhost:8080"), "/path", fields); + MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:8080"), "/path", HttpVersion.HTTP_2, fields); // Iterate a few times to be sure generator and parser are properly reset. for (int i = 0; i < 2; ++i) @@ -85,10 +84,7 @@ public class PushPromiseGenerateParseTest Assert.assertEquals(streamId, frame.getStreamId()); Assert.assertEquals(promisedStreamId, frame.getPromisedStreamId()); MetaData.Request request = (MetaData.Request)frame.getMetaData(); - Assert.assertSame(metaData.getScheme(), request.getScheme()); Assert.assertEquals(metaData.getMethod(), request.getMethod()); - Assert.assertEquals(metaData.getHost(), request.getHost()); - Assert.assertEquals(metaData.getPort(), request.getPort()); Assert.assertEquals(metaData.getURI(), request.getURI()); for (int j = 0; j < fields.size(); ++j) { @@ -119,7 +115,7 @@ public class PushPromiseGenerateParseTest HttpFields fields = new HttpFields(); fields.put("Accept", "text/html"); fields.put("User-Agent", "Jetty"); - MetaData.Request metaData = new FinalMetaData.Request(HttpVersion.HTTP_2, HttpScheme.HTTP, "GET", new HostPortHttpField("localhost:8080"), "/path", fields); + MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:8080"), "/path", HttpVersion.HTTP_2, fields); ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); generator.generatePushPromise(lease, streamId, promisedStreamId, metaData); @@ -137,10 +133,7 @@ public class PushPromiseGenerateParseTest Assert.assertEquals(streamId, frame.getStreamId()); Assert.assertEquals(promisedStreamId, frame.getPromisedStreamId()); MetaData.Request request = (MetaData.Request)frame.getMetaData(); - Assert.assertSame(metaData.getScheme(), request.getScheme()); Assert.assertEquals(metaData.getMethod(), request.getMethod()); - Assert.assertEquals(metaData.getHost(), request.getHost()); - Assert.assertEquals(metaData.getPort(), request.getPort()); Assert.assertEquals(metaData.getURI(), request.getURI()); for (int j = 0; j < fields.size(); ++j) { diff --git a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/AuthorityHttpField.java b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/AuthorityHttpField.java index 99bdf14593d..a0672d122a4 100644 --- a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/AuthorityHttpField.java +++ b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/AuthorityHttpField.java @@ -20,8 +20,6 @@ package org.eclipse.jetty.http2.hpack; import org.eclipse.jetty.http.HostPortHttpField; -import org.eclipse.jetty.http2.hpack.HpackContext; -import org.eclipse.jetty.util.StringUtil; /* ------------------------------------------------------------ */ diff --git a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackDecoder.java b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackDecoder.java index ff376a57678..4e960289dfa 100644 --- a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackDecoder.java +++ b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackDecoder.java @@ -27,7 +27,6 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpStatus; -import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.MetaData; import org.eclipse.jetty.http2.hpack.HpackContext.Entry; import org.eclipse.jetty.util.TypeUtil; diff --git a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackEncoder.java b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackEncoder.java index 78ac879f74f..e30566ea3cf 100644 --- a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackEncoder.java +++ b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackEncoder.java @@ -24,6 +24,7 @@ import java.util.EnumSet; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.MetaData; import org.eclipse.jetty.http2.hpack.HpackContext.Entry; @@ -139,10 +140,11 @@ public class HpackEncoder MetaData.Request request = (MetaData.Request)metadata; // TODO optimise these to avoid HttpField creation - encode(buffer,new HttpField(":scheme",request.getScheme().asString())); + String scheme=request.getURI().getScheme(); + encode(buffer,new HttpField(":scheme",scheme==null?HttpScheme.HTTP.asString():scheme)); encode(buffer,new HttpField(":method",request.getMethod())); - encode(buffer,new HttpField(":authority",request.getPort()>0?(request.getHost()+':'+request.getPort()):request.getHost())); - encode(buffer,new HttpField(":path",request.getURI())); + encode(buffer,new HttpField(":authority",request.getURI().getAuthority())); + encode(buffer,new HttpField(":path",request.getURI().getPathQuery())); } else if (metadata.isResponse()) diff --git a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/MetaDataBuilder.java b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/MetaDataBuilder.java index aa09a31f80f..b7793bc1e92 100644 --- a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/MetaDataBuilder.java +++ b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/MetaDataBuilder.java @@ -21,13 +21,11 @@ package org.eclipse.jetty.http2.hpack; import org.eclipse.jetty.http.BadMessageException; -import org.eclipse.jetty.http.FinalMetaData; import org.eclipse.jetty.http.HostPortHttpField; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpStatus; -import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.MetaData; @@ -133,10 +131,10 @@ public class MetaDataBuilder HttpFields fields = _fields; _fields = new HttpFields(Math.max(10,fields.size()+5)); if (_method!=null) - return new FinalMetaData.Request(HttpVersion.HTTP_2,_scheme,_method,_authority,_path,fields); + return new MetaData.Request(_method,_scheme,_authority,_path,HttpVersion.HTTP_2,fields); if (_status!=0) - return new FinalMetaData.Response(HttpVersion.HTTP_2,_status,fields); - return new FinalMetaData(HttpVersion.HTTP_2,fields); + return new MetaData.Response(HttpVersion.HTTP_2,_status,fields); + return new MetaData(HttpVersion.HTTP_2,fields); } finally { diff --git a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackContextTest.java b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackContextTest.java index 46a5cdc7803..9809b81c2d2 100644 --- a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackContextTest.java +++ b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackContextTest.java @@ -20,6 +20,12 @@ package org.eclipse.jetty.http2.hpack; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.nio.ByteBuffer; import java.util.HashSet; import java.util.Iterator; @@ -31,12 +37,6 @@ import org.hamcrest.Matchers; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - /* ------------------------------------------------------------ */ /** diff --git a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackDecoderTest.java b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackDecoderTest.java index d3966d79012..14501a81248 100644 --- a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackDecoderTest.java +++ b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackDecoderTest.java @@ -19,20 +19,19 @@ package org.eclipse.jetty.http2.hpack; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.nio.ByteBuffer; import java.util.Iterator; import org.eclipse.jetty.http.HttpField; -import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.MetaData; import org.eclipse.jetty.util.TypeUtil; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - /* ------------------------------------------------------------ */ /** @@ -52,9 +51,9 @@ public class HpackDecoderTest MetaData.Request request = (MetaData.Request)decoder.decode(buffer); assertEquals("GET", request.getMethod()); - assertEquals(HttpScheme.HTTP,request.getScheme()); - assertEquals("/",request.getURI()); - assertEquals("www.example.com",request.getHost()); + assertEquals(HttpScheme.HTTP.asString(),request.getURI().getScheme()); + assertEquals("/",request.getURI().getPath()); + assertEquals("www.example.com",request.getURI().getHost()); assertFalse(request.iterator().hasNext()); @@ -65,9 +64,9 @@ public class HpackDecoderTest request = (MetaData.Request)decoder.decode(buffer); assertEquals("GET", request.getMethod()); - assertEquals(HttpScheme.HTTP,request.getScheme()); - assertEquals("/",request.getURI()); - assertEquals("www.example.com",request.getHost()); + assertEquals(HttpScheme.HTTP.asString(),request.getURI().getScheme()); + assertEquals("/",request.getURI().getPath()); + assertEquals("www.example.com",request.getURI().getHost()); Iterator iterator=request.iterator(); assertTrue(iterator.hasNext()); assertEquals(new HttpField("cache-control","no-cache"),iterator.next()); @@ -81,9 +80,9 @@ public class HpackDecoderTest request = (MetaData.Request)decoder.decode(buffer); assertEquals("GET",request.getMethod()); - assertEquals(HttpScheme.HTTPS,request.getScheme()); - assertEquals("/index.html",request.getURI()); - assertEquals("www.example.com",request.getHost()); + assertEquals(HttpScheme.HTTPS.asString(),request.getURI().getScheme()); + assertEquals("/index.html",request.getURI().getPath()); + assertEquals("www.example.com",request.getURI().getHost()); iterator=request.iterator(); assertTrue(iterator.hasNext()); assertEquals(new HttpField("custom-key","custom-value"),iterator.next()); @@ -102,9 +101,9 @@ public class HpackDecoderTest MetaData.Request request = (MetaData.Request)decoder.decode(buffer); assertEquals("GET", request.getMethod()); - assertEquals(HttpScheme.HTTP,request.getScheme()); - assertEquals("/",request.getURI()); - assertEquals("www.example.com",request.getHost()); + assertEquals(HttpScheme.HTTP.asString(),request.getURI().getScheme()); + assertEquals("/",request.getURI().getPath()); + assertEquals("www.example.com",request.getURI().getHost()); assertFalse(request.iterator().hasNext()); @@ -115,9 +114,9 @@ public class HpackDecoderTest request = (MetaData.Request)decoder.decode(buffer); assertEquals("GET", request.getMethod()); - assertEquals(HttpScheme.HTTP,request.getScheme()); - assertEquals("/",request.getURI()); - assertEquals("www.example.com",request.getHost()); + assertEquals(HttpScheme.HTTP.asString(),request.getURI().getScheme()); + assertEquals("/",request.getURI().getPath()); + assertEquals("www.example.com",request.getURI().getHost()); Iterator iterator=request.iterator(); assertTrue(iterator.hasNext()); assertEquals(new HttpField("cache-control","no-cache"),iterator.next()); @@ -130,9 +129,9 @@ public class HpackDecoderTest request = (MetaData.Request)decoder.decode(buffer); assertEquals("GET",request.getMethod()); - assertEquals(HttpScheme.HTTPS,request.getScheme()); - assertEquals("/index.html",request.getURI()); - assertEquals("www.example.com",request.getHost()); + assertEquals(HttpScheme.HTTPS.asString(),request.getURI().getScheme()); + assertEquals("/index.html",request.getURI().getPath()); + assertEquals("www.example.com",request.getURI().getHost()); iterator=request.iterator(); assertTrue(iterator.hasNext()); assertEquals(new HttpField("custom-key","custom-value"),iterator.next()); diff --git a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackEncoderTest.java b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackEncoderTest.java index 8286ab345c3..61b52a947f4 100644 --- a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackEncoderTest.java +++ b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackEncoderTest.java @@ -20,10 +20,11 @@ package org.eclipse.jetty.http2.hpack; +import static org.junit.Assert.assertThat; + import java.nio.ByteBuffer; import java.util.HashSet; -import org.eclipse.jetty.http.FinalMetaData; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpVersion; @@ -34,8 +35,6 @@ import org.hamcrest.Matchers; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertThat; - /* ------------------------------------------------------------ */ /** @@ -71,7 +70,7 @@ public class HpackEncoderTest // encode them ByteBuffer buffer = BufferUtil.allocate(4096); int pos = BufferUtil.flipToFill(buffer); - encoder.encode(buffer,new FinalMetaData(HttpVersion.HTTP_2,fields)); + encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields)); BufferUtil.flipToFlush(buffer,pos); // something was encoded! @@ -90,7 +89,7 @@ public class HpackEncoderTest // encode exact same fields again! BufferUtil.clearToFill(buffer); - encoder.encode(buffer,new FinalMetaData(HttpVersion.HTTP_2,fields)); + encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields)); BufferUtil.flipToFlush(buffer,0); // nothing should be encoded! @@ -113,7 +112,7 @@ public class HpackEncoderTest // encode BufferUtil.clearToFill(buffer); - encoder.encode(buffer,new FinalMetaData(HttpVersion.HTTP_2,fields)); + encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields)); BufferUtil.flipToFlush(buffer,0); // something was encoded! @@ -137,7 +136,7 @@ public class HpackEncoderTest // encode BufferUtil.clearToFill(buffer); - encoder.encode(buffer,new FinalMetaData(HttpVersion.HTTP_2,fields)); + encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields)); BufferUtil.flipToFlush(buffer,0); // something was encoded! @@ -164,7 +163,7 @@ public class HpackEncoderTest // encode BufferUtil.clearToFill(buffer); - encoder.encode(buffer,new FinalMetaData(HttpVersion.HTTP_2,fields)); + encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields)); BufferUtil.flipToFlush(buffer,0); // something was encoded! @@ -192,7 +191,7 @@ public class HpackEncoderTest // encode BufferUtil.clearToFill(buffer); - encoder.encode(buffer,new FinalMetaData(HttpVersion.HTTP_2,fields)); + encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields)); BufferUtil.flipToFlush(buffer,0); // something was encoded! @@ -226,7 +225,7 @@ public class HpackEncoderTest // encode BufferUtil.clearToFill(buffer); - encoder.encode(buffer,new FinalMetaData(HttpVersion.HTTP_2,fields)); + encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields)); BufferUtil.flipToFlush(buffer,0); // something was encoded! @@ -247,7 +246,7 @@ public class HpackEncoderTest // encode BufferUtil.clearToFill(buffer); - encoder.encode(buffer,new FinalMetaData(HttpVersion.HTTP_2,fields)); + encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields)); BufferUtil.flipToFlush(buffer,0); // something was encoded! @@ -259,7 +258,7 @@ public class HpackEncoderTest // encode again BufferUtil.clearToFill(buffer); - encoder.encode(buffer,new FinalMetaData(HttpVersion.HTTP_2,fields)); + encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields)); BufferUtil.flipToFlush(buffer,0); // something was encoded! diff --git a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java index 4323ca8d7c8..ac6a9ac7568 100644 --- a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java +++ b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertEquals; import java.nio.ByteBuffer; import org.eclipse.jetty.http.BadMessageException; -import org.eclipse.jetty.http.FinalMetaData; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpStatus; @@ -51,7 +50,7 @@ public class HpackTest fields0.add(HttpHeader.SERVER,"jetty"); fields0.add(HttpHeader.SET_COOKIE,"abcdefghijklmnopqrstuvwxyz"); fields0.add("custom-key","custom-value"); - Response original0 = new FinalMetaData.Response(HttpVersion.HTTP_2,200,fields0); + Response original0 = new MetaData.Response(HttpVersion.HTTP_2,200,fields0); BufferUtil.clearToFill(buffer); encoder.encode(buffer,original0); @@ -73,7 +72,7 @@ public class HpackTest fields1.add(HttpHeader.CONTENT_LENGTH,"1234"); fields1.add(HttpHeader.SERVER,"jetty"); fields1.add("Custom-Key","Other-Value"); - Response original1 = new FinalMetaData.Response(HttpVersion.HTTP_2,200,fields1); + Response original1 = new MetaData.Response(HttpVersion.HTTP_2,200,fields1); // Same again? BufferUtil.clearToFill(buffer); @@ -97,7 +96,7 @@ public class HpackTest HttpFields fields0 = new HttpFields(); fields0.add("1234567890","1234567890123456789012345678901234567890"); fields0.add("Cookie","abcdeffhijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR"); - MetaData original0= new FinalMetaData(HttpVersion.HTTP_2,fields0); + MetaData original0= new MetaData(HttpVersion.HTTP_2,fields0); BufferUtil.clearToFill(buffer); encoder.encode(buffer,original0); @@ -110,7 +109,7 @@ public class HpackTest fields1.add("1234567890","1234567890123456789012345678901234567890"); fields1.add("Cookie","abcdeffhijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR"); fields1.add("x","y"); - MetaData original1 = new FinalMetaData(HttpVersion.HTTP_2,fields1); + MetaData original1 = new MetaData(HttpVersion.HTTP_2,fields1); BufferUtil.clearToFill(buffer); encoder.encode(buffer,original1); diff --git a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/NBitIntegerTest.java b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/NBitIntegerTest.java index 8de3a29fc76..7b395fbb7f8 100644 --- a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/NBitIntegerTest.java +++ b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/NBitIntegerTest.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.http2.hpack; +import static org.junit.Assert.assertEquals; + import java.nio.ByteBuffer; import org.eclipse.jetty.util.BufferUtil; @@ -25,8 +27,6 @@ import org.eclipse.jetty.util.TypeUtil; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class NBitIntegerTest { diff --git a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java index b6cd36a0cde..900736f7f38 100644 --- a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java +++ b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java @@ -87,7 +87,7 @@ public class HttpChannelOverHTTP2 extends HttpChannel if (LOG.isDebugEnabled()) { LOG.debug("HTTP2 Request #{}:{}{} {} {}{}{}", - stream.getId(), System.lineSeparator(), request.getMethod(), request.getURI(), request.getHttpVersion(), System.lineSeparator(), fields); + stream.getId(), System.lineSeparator(), request.getMethod(), request.getURI(), request.getVersion(), System.lineSeparator(), fields); } execute(this); diff --git a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java index c6b2744d61f..e9e8ad69b1e 100644 --- a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java +++ b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java @@ -21,7 +21,6 @@ package org.eclipse.jetty.http2.server; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; -import org.eclipse.jetty.http.FinalMetaData; import org.eclipse.jetty.http.HttpGenerator; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpVersion; @@ -82,7 +81,7 @@ public class HttpTransportOverHTTP2 implements HttpTransport System.lineSeparator(), info.getHttpFields()); } - MetaData metaData = new FinalMetaData.Response(HttpVersion.HTTP_2, info.getStatus(), info.getHttpFields()); + MetaData metaData = new MetaData.Response(HttpVersion.HTTP_2, info.getStatus(), info.getHttpFields()); HeadersFrame frame = new HeadersFrame(stream.getId(), metaData, null, endStream); stream.headers(frame, callback); } diff --git a/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java b/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java index e9700374f38..15c0b7996ff 100644 --- a/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java +++ b/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java @@ -34,7 +34,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.http.FinalMetaData; import org.eclipse.jetty.http.HostPortHttpField; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpMethod; @@ -100,8 +99,8 @@ public class HTTP2ServerTest String host = "localhost"; int port = connector.getLocalPort(); HttpFields fields = new HttpFields(); - MetaData.Request metaData = new FinalMetaData.Request(HttpVersion.HTTP_2, HttpScheme.HTTP, HttpMethod.GET.asString(), - new HostPortHttpField(host + ":" + port), path, fields); + MetaData.Request metaData = new MetaData.Request(HttpMethod.GET.asString(), HttpScheme.HTTP, new HostPortHttpField(host + ":" + port), + path, HttpVersion.HTTP_2, fields); HeadersFrame request = new HeadersFrame(1, metaData, null, true); ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); generator.control(lease, request); @@ -149,8 +148,8 @@ public class HTTP2ServerTest String host = "localhost"; int port = connector.getLocalPort(); HttpFields fields = new HttpFields(); - MetaData.Request metaData = new FinalMetaData.Request(HttpVersion.HTTP_2, HttpScheme.HTTP, HttpMethod.GET.asString(), - new HostPortHttpField(host + ":" + port), path, fields); + MetaData.Request metaData = new MetaData.Request(HttpMethod.GET.asString(), HttpScheme.HTTP, new HostPortHttpField(host + ":" + port), + path, HttpVersion.HTTP_2, fields); HeadersFrame request = new HeadersFrame(1, metaData, null, true); ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); generator.control(lease, request); @@ -212,8 +211,8 @@ public class HTTP2ServerTest String host = "localhost"; int port = connector.getLocalPort(); HttpFields fields = new HttpFields(); - MetaData.Request metaData = new FinalMetaData.Request(HttpVersion.HTTP_2,HttpScheme.HTTP, HttpMethod.GET.asString(), - new HostPortHttpField(host + ":" + port), path, fields); + MetaData.Request metaData = new MetaData.Request(HttpMethod.GET.asString(),HttpScheme.HTTP, new HostPortHttpField(host + ":" + port), + path, HttpVersion.HTTP_2, fields); HeadersFrame request = new HeadersFrame(1, metaData, null, true); ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool); generator.control(lease, request); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java index ff8f14763dc..883eda6d0ac 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server; import java.net.InetSocketAddress; +import org.eclipse.jetty.http.HostPortHttpField; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpScheme; @@ -46,7 +47,7 @@ import org.eclipse.jetty.server.HttpConfiguration.Customizer; */ public class ForwardedRequestCustomizer implements Customizer { - private String _hostHeader; + private HostPortHttpField _hostHeader; private String _forwardedHostHeader = HttpHeader.X_FORWARDED_HOST.toString(); private String _forwardedServerHeader = HttpHeader.X_FORWARDED_SERVER.toString(); private String _forwardedForHeader = HttpHeader.X_FORWARDED_FOR.toString(); @@ -58,7 +59,7 @@ public class ForwardedRequestCustomizer implements Customizer /* ------------------------------------------------------------ */ public String getHostHeader() { - return _hostHeader; + return _hostHeader.getValue(); } /* ------------------------------------------------------------ */ @@ -70,7 +71,7 @@ public class ForwardedRequestCustomizer implements Customizer */ public void setHostHeader(String hostHeader) { - _hostHeader = hostHeader; + _hostHeader = new HostPortHttpField(hostHeader); } /* ------------------------------------------------------------ */ @@ -224,18 +225,17 @@ public class ForwardedRequestCustomizer implements Customizer if (_hostHeader != null) { // Update host header - httpFields.put(HttpHeader.HOST.toString(),_hostHeader); - request.setServerName(null); - request.setServerPort(-1); - request.getServerName(); + httpFields.put(_hostHeader); + request.setServerName(_hostHeader.getHost()); + request.setServerPort(_hostHeader.getPort()); } else if (forwardedHost != null) { // Update host header - httpFields.put(HttpHeader.HOST.toString(),forwardedHost); - request.setServerName(null); - request.setServerPort(-1); - request.getServerName(); + HostPortHttpField auth = new HostPortHttpField(forwardedHost); + httpFields.put(auth); + request.setServerName(auth.getHost()); + request.setServerPort(auth.getPort()); } else if (forwardedServer != null) { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java index fd60d3ebf67..266ed8fbb54 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; -import org.eclipse.jetty.http.AbstractMetaData; import org.eclipse.jetty.http.HostPortHttpField; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpFields; @@ -34,9 +33,11 @@ import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpParser; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpStatus; +import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.MetaData; import org.eclipse.jetty.io.EndPoint; +import org.omg.stub.java.rmi._Remote_Stub; /** * A HttpChannel customized to be transported over the HTTP/1 protocol @@ -44,64 +45,22 @@ import org.eclipse.jetty.io.EndPoint; class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandler, HttpParser.ProxyHandler { private final HttpConnection _httpConnection; - private String _method; - private String _uri; - private HttpVersion _version; private final HttpFields _fields = new HttpFields(); - private HostPortHttpField _hostPort; private HttpField _connection; private boolean _expect = false; private boolean _expect100Continue = false; private boolean _expect102Processing = false; - private final MetaData.Request _metadata = new AbstractMetaData.Request() - { - @Override - public String getMethod() - { - return _method; - } - - @Override - public HttpScheme getScheme() - { - return HttpScheme.HTTP; - } - - @Override - public String getHost() - { - return _hostPort==null?null:_hostPort.getHost(); - } - - @Override - public int getPort() - { - return _hostPort==null?0:_hostPort.getPort(); - } - - @Override - public String getURI() - { - return _uri; - } - - @Override - public HttpVersion getHttpVersion() - { - return _version; - } - - @Override - public HttpFields getFields() - { - return _fields; - } - }; + + private final HttpURI _uri = new HttpURI(); + private final MetaData.Request _metadata = new MetaData.Request(); + public HttpChannelOverHttp(HttpConnection httpConnection, Connector connector, HttpConfiguration config, EndPoint endPoint, HttpTransport transport, HttpInput input) { super(connector,config,endPoint,transport,input); _httpConnection = httpConnection; + _metadata.setFields(_fields); + _metadata.setURI(_uri); } @Override @@ -111,10 +70,7 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl _expect = false; _expect100Continue = false; _expect102Processing = false; - _method=null; - _uri=null; - _version=null; - _hostPort=null; + _uri.clear(); _connection=null; _fields.clear(); } @@ -134,9 +90,9 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl @Override public boolean startRequest(String method, String uri, HttpVersion version) { - _method=method; - _uri=uri; - _version=version; + _metadata.setMethod(method); + _uri.parse(uri); + _metadata.setHttpVersion(version); _expect = false; _expect100Continue = false; _expect102Processing = false; @@ -146,7 +102,7 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl @Override public void proxied(String protocol, String sAddr, String dAddr, int sPort, int dPort) { - _method=HttpMethod.CONNECT.asString(); + _metadata.setMethod(HttpMethod.CONNECT.asString()); Request request = getRequest(); request.setAttribute("PROXY", protocol); request.setServerName(sAddr); @@ -168,12 +124,16 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl break; case HOST: - _hostPort=(HostPortHttpField)field; + if (!_uri.isAbsolute() && field instanceof HostPortHttpField) + { + HostPortHttpField hp = (HostPortHttpField)field; + _uri.setAuth(hp.getHost(),hp.getPort()); + } break; case EXPECT: { - if (_version==HttpVersion.HTTP_1_1) + if (_metadata.getVersion()==HttpVersion.HTTP_1_1) { HttpHeaderValue expect = HttpHeaderValue.CACHE.get(value); switch (expect == null ? HttpHeaderValue.UNKNOWN : expect) @@ -253,7 +213,7 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl public void earlyEOF() { // If we have no request yet, just close - if (_method==null) + if (_metadata.getMethod()==null) _httpConnection.close(); else onEarlyEOF(); @@ -279,7 +239,7 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl { boolean persistent; - switch (_version) + switch (_metadata.getVersion()) { case HTTP_1_0: { @@ -294,7 +254,7 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl persistent=false; if (!persistent) - persistent = HttpMethod.CONNECT.is(_method); + persistent = HttpMethod.CONNECT.is(_metadata.getMethod()); if (persistent) getResponse().getHttpFields().add(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE); @@ -320,7 +280,7 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl persistent=true; if (!persistent) - persistent = HttpMethod.CONNECT.is(_method); + persistent = HttpMethod.CONNECT.is(_metadata.getMethod()); if (!persistent) getResponse().getHttpFields().add(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE); break; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 7ca5312d280..a0b12aaced2 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -922,7 +922,7 @@ public class Request implements HttpServletRequest @Override public String getProtocol() { - return _metadata==null?null:_metadata.getHttpVersion().toString(); + return _metadata==null?null:_metadata.getVersion().toString(); } /* ------------------------------------------------------------ */ @@ -931,7 +931,7 @@ public class Request implements HttpServletRequest */ public HttpVersion getHttpVersion() { - return _metadata==null?null:_metadata.getHttpVersion(); + return _metadata==null?null:_metadata.getVersion(); } /* ------------------------------------------------------------ */ @@ -1117,7 +1117,7 @@ public class Request implements HttpServletRequest public String getRequestURI() { if (_requestURI == null && _uri != null) - _requestURI = _uri.getPathAndParam(); + _requestURI = _uri.getPath(); return _requestURI; } @@ -1537,9 +1537,11 @@ public class Request implements HttpServletRequest { _metadata=request; setMethod(request.getMethod()); - setScheme(request.getScheme().asString()); - - HttpURI uri = new HttpURI(request.getURI()); + HttpURI uri = request.getURI(); + + String scheme=uri.getScheme(); + if (scheme!=null) + setScheme(scheme); String uriHost=uri.getHost(); if (uriHost!=null) @@ -1548,29 +1550,32 @@ public class Request implements HttpServletRequest setServerName(uriHost); setServerPort(uri.getPort()); } - else - { - setServerName(request.getHost()); - setServerPort(request.getPort()); - } setUri(uri); String path = uri.getDecodedPath(); - - String info = URIUtil.canonicalPath(path); // TODO should this be done prior to decoding??? - - if (info == null) + String info; + if (path==null || path.length()==0) { - if( path==null && uri.getScheme()!=null && uri.getHost()!=null) - { - info = "/"; - setRequestURI(""); - } + if (uri.isAbsolute()) + path="/"; else throw new BadMessageException(400,"Bad URI"); + info=path; } + else if (!path.startsWith("/")) + { + if (!"*".equals(path) && !HttpMethod.CONNECT.is(getMethod())) + throw new BadMessageException(400,"Bad URI"); + info=path; + } + else + info = URIUtil.canonicalPath(path);// TODO should this be done prior to decoding??? + + if (info == null) + throw new BadMessageException(400,"Bad URI"); + setPathInfo(info); } @@ -2010,7 +2015,6 @@ public class Request implements HttpServletRequest * @param uri * The uri to set. */ - @Deprecated // is this still needed or can we use meta data? public void setUri(HttpURI uri) { _uri = uri; diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpChannelOverSPDY.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpChannelOverSPDY.java index ca1353d2104..a82dcfc5a27 100644 --- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpChannelOverSPDY.java +++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpChannelOverSPDY.java @@ -20,13 +20,11 @@ package org.eclipse.jetty.spdy.server.http; import java.nio.ByteBuffer; -import org.eclipse.jetty.http.FinalMetaData; import org.eclipse.jetty.http.HostPortHttpField; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpScheme; -import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.MetaData; import org.eclipse.jetty.io.EndPoint; @@ -164,7 +162,7 @@ public class HttpChannelOverSPDY extends HttpChannel // At last, add the Host header. fields.add(hostPort); - MetaData.Request request = new FinalMetaData.Request(httpVersion, HttpScheme.HTTP.asString(), httpMethod==null?methodHeader.getValue():httpMethod.asString(), uriHeader.getValue(), fields, hostPort); + MetaData.Request request = new MetaData.Request(httpMethod==null?methodHeader.getValue():httpMethod.asString(), HttpScheme.HTTP.asString(), hostPort, uriHeader.getValue(), httpVersion, fields); onRequest(request); return true; } diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ReferrerPushStrategyTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ReferrerPushStrategyTest.java index eec770d7504..6ec67bcc832 100644 --- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ReferrerPushStrategyTest.java +++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ReferrerPushStrategyTest.java @@ -18,6 +18,10 @@ package org.eclipse.jetty.spdy.server.http; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + import java.io.IOException; import java.io.PrintWriter; import java.net.InetSocketAddress; @@ -27,6 +31,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; + import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; @@ -63,10 +68,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest { private static final Logger LOG = Log.getLogger(ReferrerPushStrategyTest.class); diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPToSPDYTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPToSPDYTest.java index 0f450e2ce63..4a7ea452793 100644 --- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPToSPDYTest.java +++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPToSPDYTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.spdy.server.proxy; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -62,9 +65,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - @RunWith(Parameterized.class) public class ProxyHTTPToSPDYTest { diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPLoadTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPLoadTest.java index 9e723036f32..2c318efdbf0 100644 --- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPLoadTest.java +++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPLoadTest.java @@ -18,6 +18,11 @@ package org.eclipse.jetty.spdy.server.proxy; +import static junit.framework.Assert.fail; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.InetSocketAddress; @@ -33,6 +38,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -71,11 +77,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static junit.framework.Assert.fail; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; - @Ignore @RunWith(value = Parameterized.class) public abstract class ProxySPDYToHTTPLoadTest diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPTest.java index 219ebde0706..cee18e154c9 100644 --- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPTest.java +++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPTest.java @@ -18,6 +18,11 @@ package org.eclipse.jetty.spdy.server.proxy; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -27,6 +32,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -69,11 +75,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - @RunWith(value = Parameterized.class) public abstract class ProxySPDYToHTTPTest { diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYLoadTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYLoadTest.java index 89f0eced800..195cd64e735 100644 --- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYLoadTest.java +++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYLoadTest.java @@ -18,6 +18,10 @@ package org.eclipse.jetty.spdy.server.proxy; +import static junit.framework.Assert.fail; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + import java.io.ByteArrayOutputStream; import java.net.InetSocketAddress; import java.util.ArrayList; @@ -60,10 +64,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static junit.framework.Assert.fail; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - @RunWith(value = Parameterized.class) public abstract class ProxySPDYToSPDYLoadTest { diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYTest.java index 04e9551cd55..0a0b1930b88 100644 --- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYTest.java +++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.spdy.server.proxy; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + import java.io.ByteArrayOutputStream; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; @@ -62,9 +65,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - @RunWith(value = Parameterized.class) public abstract class ProxySPDYToSPDYTest { diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java index adf1b770d33..f8865e0441d 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java @@ -780,6 +780,16 @@ public class UrlEncoded extends MultiMap implements Cloneable } } } + + /* -------------------------------------------------------------- */ + /** Decode String with % encoding. + * This method makes the assumption that the majority of calls + * will need no decoding. + */ + public static String decodeString(String encoded) + { + return decodeString(encoded,0,encoded.length(),ENCODING); + } /* -------------------------------------------------------------- */ /** Decode String with % encoding.