aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2013-03-13 13:17:22 (EDT)
committerThomas Becker2013-03-13 13:17:34 (EDT)
commita90a505316d055fcea1ab58d62be972ed07c2cc5 (patch)
treef413e60cb3bccde17a606b48b9043683b644ccc1
parent1112c268ee6c3511ee2b850fefa78ce203c54f39 (diff)
downloadorg.eclipse.jetty.project-a90a505316d055fcea1ab58d62be972ed07c2cc5.zip
org.eclipse.jetty.project-a90a505316d055fcea1ab58d62be972ed07c2cc5.tar.gz
org.eclipse.jetty.project-a90a505316d055fcea1ab58d62be972ed07c2cc5.tar.bz2
401806 spdy push properly pass through request and response headers for pushed resources
-rw-r--r--jetty-spdy/spdy-http-server/pom.xml6
-rw-r--r--jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java25
-rw-r--r--jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ReferrerPushStrategyTest.java25
3 files changed, 37 insertions, 19 deletions
diff --git a/jetty-spdy/spdy-http-server/pom.xml b/jetty-spdy/spdy-http-server/pom.xml
index a155403..a130ca4 100644
--- a/jetty-spdy/spdy-http-server/pom.xml
+++ b/jetty-spdy/spdy-http-server/pom.xml
@@ -97,6 +97,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlets</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.eclipse.jetty.npn</groupId>
<artifactId>npn-api</artifactId>
<version>${npn.api.version}</version>
diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java
index a63eb1d..1a9d686 100644
--- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java
+++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java
@@ -37,6 +37,7 @@ import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpTransport;
import org.eclipse.jetty.spdy.StreamException;
import org.eclipse.jetty.spdy.api.ByteBufferDataInfo;
+import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.PushInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY;
@@ -198,6 +199,8 @@ public class HttpTransportOverSPDY implements HttpTransport
{
if (!stream.isUnidirectional())
stream.reply(replyInfo, new Callback.Adapter());
+ else
+ stream.headers(new HeadersInfo(replyInfo.getHeaders(), replyInfo.isClose()), new Callback.Adapter());
Fields responseHeaders = replyInfo.getHeaders();
short version = stream.getSession().getVersion();
@@ -230,19 +233,17 @@ public class HttpTransportOverSPDY implements HttpTransport
private Fields createRequestHeaders(Fields.Field scheme, Fields.Field host, Fields.Field uri, String pushResourcePath)
{
- final Fields requestHeaders = new Fields();
+ final Fields newRequestHeaders = new Fields(requestHeaders, false);
short version = stream.getSession().getVersion();
- requestHeaders.put(HTTPSPDYHeader.METHOD.name(version), "GET");
- requestHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
- requestHeaders.put(scheme);
- requestHeaders.put(host);
- requestHeaders.put(HTTPSPDYHeader.URI.name(version), pushResourcePath);
+ newRequestHeaders.put(HTTPSPDYHeader.METHOD.name(version), "GET");
+ newRequestHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
+ newRequestHeaders.put(scheme);
+ newRequestHeaders.put(host);
+ newRequestHeaders.put(HTTPSPDYHeader.URI.name(version), pushResourcePath);
String referrer = scheme.value() + "://" + host.value() + uri.value();
- requestHeaders.put("referer", referrer);
- // Remember support for gzip encoding
- requestHeaders.put(requestHeaders.get("accept-encoding"));
- requestHeaders.put("x-spdy-push", "true");
- return requestHeaders;
+ newRequestHeaders.put("referer", referrer);
+ newRequestHeaders.put("x-spdy-push", "true");
+ return newRequestHeaders;
}
private Fields createPushHeaders(Fields.Field scheme, Fields.Field host, String pushResourcePath)
@@ -257,8 +258,6 @@ public class HttpTransportOverSPDY implements HttpTransport
pushHeaders.put(scheme);
pushHeaders.put(host);
}
- pushHeaders.put(HTTPSPDYHeader.STATUS.name(version), "200");
- pushHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");
return pushHeaders;
}
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 1bf46ac..f52c875 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
@@ -32,7 +32,9 @@ import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.servlets.gzip.GzipHandler;
import org.eclipse.jetty.spdy.api.DataInfo;
+import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.PushInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.RstInfo;
@@ -155,7 +157,8 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
private InetSocketAddress createServer() throws Exception
{
- return startHTTPServer(version, new AbstractHandler()
+ GzipHandler gzipHandler = new GzipHandler();
+ gzipHandler.setHandler(new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
@@ -171,6 +174,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
baseRequest.setHandled(true);
}
});
+ return startHTTPServer(version, gzipHandler);
}
private Session sendMainRequestAndCSSRequest() throws Exception
@@ -240,6 +244,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
final CountDownLatch mainStreamLatch = new CountDownLatch(2);
final CountDownLatch pushDataLatch = new CountDownLatch(1);
final CountDownLatch pushSynHeadersValid = new CountDownLatch(1);
+ final CountDownLatch pushResponseHeaders = new CountDownLatch(1);
Session session2 = startClient(version, serverAddress, null);
session2.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter()
{
@@ -258,9 +263,18 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
return new StreamFrameListener.Adapter()
{
@Override
- public void onData(Stream stream, DataInfo dataInfo)
+ public void onHeaders(Stream stream, HeadersInfo headersInfo)
{
+ Fields headers = headersInfo.getHeaders();
+ if (validateHeader(headers, HTTPSPDYHeader.STATUS.name(version), "200 OK")
+ && validateHeader(headers, HTTPSPDYHeader.VERSION.name(version),
+ "HTTP/1.1") && validateHeader(headers, "content-encoding", "gzip"))
+ pushResponseHeaders.countDown();
+ }
+ @Override
+ public void onData(Stream stream, DataInfo dataInfo)
+ {
dataInfo.consume(dataInfo.length());
if (dataInfo.isClose())
pushDataLatch.countDown();
@@ -797,9 +811,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
private void validateHeaders(Fields headers, CountDownLatch pushSynHeadersValid)
{
- if (validateHeader(headers, HTTPSPDYHeader.STATUS.name(version), "200")
- && validateHeader(headers, HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1")
- && validateUriHeader(headers))
+ if (validateUriHeader(headers))
pushSynHeadersValid.countDown();
}
@@ -808,7 +820,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Fields.Field header = headers.get(name);
if (header != null && expectedValue.equals(header.value()))
return true;
- System.out.println(name + " not valid! " + headers);
+ System.out.println(name + " not valid! Expected: " + expectedValue + " headers received:" + headers);
return false;
}
@@ -842,6 +854,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Fields requestHeaders = new Fields();
requestHeaders.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) " +
"Gecko/20100101 Firefox/16.0");
+ requestHeaders.put("accept-encoding", "gzip");
requestHeaders.put(HTTPSPDYHeader.METHOD.name(version), "GET");
requestHeaders.put(HTTPSPDYHeader.URI.name(version), resource);
requestHeaders.put(HTTPSPDYHeader.VERSION.name(version), "HTTP/1.1");