Merged branch 'jetty-9.3.x' into 'master'.
This commit is contained in:
commit
5062756135
|
@ -695,6 +695,10 @@ public class PushCacheFilterTest extends AbstractTest
|
|||
@Override
|
||||
public Stream.Listener onPush(Stream stream, PushPromiseFrame frame)
|
||||
{
|
||||
MetaData metaData = frame.getMetaData();
|
||||
Assert.assertTrue(metaData instanceof MetaData.Request);
|
||||
MetaData.Request pushedRequest = (MetaData.Request)metaData;
|
||||
Assert.assertEquals(servletPath + secondaryResource, pushedRequest.getURI().getPathQuery());
|
||||
return new Adapter()
|
||||
{
|
||||
@Override
|
||||
|
|
|
@ -32,14 +32,14 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
/**
|
||||
*/
|
||||
public class PushBuilderImpl implements PushBuilder
|
||||
{
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(PushBuilderImpl.class);
|
||||
|
||||
private final static HttpField JettyPush = new HttpField("x-http2-push","PushBuilder");
|
||||
|
||||
|
||||
private final Request _request;
|
||||
private final HttpFields _fields;
|
||||
private String _method;
|
||||
|
@ -49,7 +49,7 @@ public class PushBuilderImpl implements PushBuilder
|
|||
private String _path;
|
||||
private String _etag;
|
||||
private String _lastModified;
|
||||
|
||||
|
||||
public PushBuilderImpl(Request request, HttpFields fields, String method, String queryString, String sessionId, boolean conditional)
|
||||
{
|
||||
super();
|
||||
|
@ -70,7 +70,7 @@ public class PushBuilderImpl implements PushBuilder
|
|||
{
|
||||
return _method;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public PushBuilder method(String method)
|
||||
|
@ -78,14 +78,14 @@ public class PushBuilderImpl implements PushBuilder
|
|||
_method = method;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public String getQueryString()
|
||||
{
|
||||
return _queryString;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public PushBuilder queryString(String queryString)
|
||||
|
@ -93,14 +93,14 @@ public class PushBuilderImpl implements PushBuilder
|
|||
_queryString = queryString;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public String getSessionId()
|
||||
{
|
||||
return _sessionId;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public PushBuilder sessionId(String sessionId)
|
||||
|
@ -108,14 +108,14 @@ public class PushBuilderImpl implements PushBuilder
|
|||
_sessionId = sessionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public boolean isConditional()
|
||||
{
|
||||
return _conditional;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public PushBuilder conditional(boolean conditional)
|
||||
|
@ -123,21 +123,21 @@ public class PushBuilderImpl implements PushBuilder
|
|||
_conditional = conditional;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public Set<String> getHeaderNames()
|
||||
{
|
||||
return _fields.getFieldNamesCollection();
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public String getHeader(String name)
|
||||
{
|
||||
return _fields.get(name);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public PushBuilder setHeader(String name,String value)
|
||||
|
@ -145,7 +145,7 @@ public class PushBuilderImpl implements PushBuilder
|
|||
_fields.put(name,value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public PushBuilder addHeader(String name,String value)
|
||||
|
@ -161,7 +161,7 @@ public class PushBuilderImpl implements PushBuilder
|
|||
_fields.remove(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public String getPath()
|
||||
|
@ -213,31 +213,31 @@ public class PushBuilderImpl implements PushBuilder
|
|||
{
|
||||
if (HttpMethod.POST.is(_method) || HttpMethod.PUT.is(_method))
|
||||
throw new IllegalStateException("Bad Method "+_method);
|
||||
|
||||
|
||||
if (_path==null || _path.length()==0)
|
||||
throw new IllegalStateException("Bad Path "+_path);
|
||||
|
||||
|
||||
String path=_path;
|
||||
String query=_queryString;
|
||||
int q=path.indexOf('?');
|
||||
if (q>=0)
|
||||
{
|
||||
query=(query!=null && query.length()>0)?(_path.substring(q+1)+'&'+query):_path.substring(q+1);
|
||||
path=_path.substring(0,q);
|
||||
query=(query!=null && query.length()>0)?(path.substring(q+1)+'&'+query):path.substring(q+1);
|
||||
path=path.substring(0,q);
|
||||
}
|
||||
|
||||
|
||||
if (!path.startsWith("/"))
|
||||
path=URIUtil.addPaths(_request.getContextPath(),path);
|
||||
|
||||
|
||||
String param=null;
|
||||
if (_sessionId!=null)
|
||||
{
|
||||
if (_request.isRequestedSessionIdFromURL())
|
||||
param="jsessionid="+_sessionId;
|
||||
// TODO else
|
||||
// TODO else
|
||||
// _fields.add("Cookie","JSESSIONID="+_sessionId);
|
||||
}
|
||||
|
||||
|
||||
if (_conditional)
|
||||
{
|
||||
if (_etag!=null)
|
||||
|
@ -245,13 +245,13 @@ public class PushBuilderImpl implements PushBuilder
|
|||
else if (_lastModified!=null)
|
||||
_fields.add(HttpHeader.IF_MODIFIED_SINCE,_lastModified);
|
||||
}
|
||||
|
||||
HttpURI uri = HttpURI.createHttpURI(_request.getScheme(),_request.getServerName(),_request.getServerPort(),_path,param,query,null);
|
||||
|
||||
HttpURI uri = HttpURI.createHttpURI(_request.getScheme(),_request.getServerName(),_request.getServerPort(),path,param,query,null);
|
||||
MetaData.Request push = new MetaData.Request(_method,uri,_request.getHttpVersion(),_fields);
|
||||
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Push {} {} inm={} ims={}",_method,uri,_fields.get(HttpHeader.IF_NONE_MATCH),_fields.get(HttpHeader.IF_MODIFIED_SINCE));
|
||||
|
||||
|
||||
_request.getHttpChannel().getHttpTransport().push(push);
|
||||
_path=null;
|
||||
_etag=null;
|
||||
|
|
|
@ -34,7 +34,6 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
@ -45,7 +44,6 @@ import org.eclipse.jetty.http.HttpFields;
|
|||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.server.Dispatcher;
|
||||
import org.eclipse.jetty.server.PushBuilder;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
@ -158,6 +156,9 @@ public class PushCacheFilter implements Filter
|
|||
LOG.debug("{} {} referrer={} conditional={}", request.getMethod(), request.getRequestURI(), referrer, conditional);
|
||||
|
||||
String path = URIUtil.addPaths(request.getServletPath(), request.getPathInfo());
|
||||
String query = request.getQueryString();
|
||||
if (query != null)
|
||||
path += "?" + query;
|
||||
if (referrer != null)
|
||||
{
|
||||
HttpURI referrerURI = new HttpURI(referrer);
|
||||
|
@ -254,12 +255,12 @@ public class PushCacheFilter implements Filter
|
|||
if (!conditional && !primaryResource._associated.isEmpty())
|
||||
{
|
||||
PushBuilder builder = Request.getBaseRequest(request).getPushBuilder();
|
||||
|
||||
|
||||
for (String associated : primaryResource._associated.values())
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Pushing {} for {}", associated, path);
|
||||
|
||||
|
||||
builder.path(associated).push();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue