diff options
author | lzheng@chromium.org <lzheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-26 04:48:13 +0000 |
---|---|---|
committer | lzheng@chromium.org <lzheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-26 04:48:13 +0000 |
commit | d2360a5e34b37a76545d083dd977368035b930c6 (patch) | |
tree | c6dc4585305d2c6744291cfcfd03d97c1e180da6 /net/spdy | |
parent | d54b07954695d5f8b39228693ab7ddedc11c6f6f (diff) | |
download | chromium_src-d2360a5e34b37a76545d083dd977368035b930c6.zip chromium_src-d2360a5e34b37a76545d083dd977368035b930c6.tar.gz chromium_src-d2360a5e34b37a76545d083dd977368035b930c6.tar.bz2 |
Use SpecForRequest to get rid of anchor in url for spdy.
TEST=spdy_http_stream_unittest.cc
BUG=50058
Review URL: http://codereview.chromium.org/3061011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53610 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r-- | net/spdy/spdy_http_stream.cc | 3 | ||||
-rw-r--r-- | net/spdy/spdy_http_stream_unittest.cc | 86 |
2 files changed, 68 insertions, 21 deletions
diff --git a/net/spdy/spdy_http_stream.cc b/net/spdy/spdy_http_stream.cc index 581cb27..c813e96 100644 --- a/net/spdy/spdy_http_stream.cc +++ b/net/spdy/spdy_http_stream.cc @@ -14,6 +14,7 @@ #include "net/base/load_flags.h" #include "net/http/http_request_info.h" #include "net/http/http_response_info.h" +#include "net/http/http_util.h" #include "net/spdy/spdy_session.h" namespace { @@ -110,7 +111,7 @@ void CreateSpdyHeadersFromHttpRequest( // TODO(mbelshe): Add authentication headers here. (*headers)["method"] = info.method; - (*headers)["url"] = info.url.spec(); + (*headers)["url"] = net::HttpUtil::SpecForRequest(info.url); (*headers)["version"] = kHttpProtocolVersion; if (!info.referrer.is_empty()) (*headers)["referer"] = info.referrer.spec(); diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc index 25c9d24..9c23b54 100644 --- a/net/spdy/spdy_http_stream_unittest.cc +++ b/net/spdy/spdy_http_stream_unittest.cc @@ -20,6 +20,24 @@ class SpdyHttpStreamTest : public testing::Test { virtual void TearDown() { MessageLoop::current()->RunAllPending(); } + int InitSession(MockRead* reads, size_t reads_count, + MockWrite* writes, size_t writes_count, + HostPortPair& host_port_pair) { + data_ = new OrderedSocketData(reads, reads_count, writes, writes_count); + session_deps_.socket_factory.AddSocketDataProvider(data_.get()); + http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); + session_ = http_session_->spdy_session_pool()-> + Get(host_port_pair, http_session_.get(), BoundNetLog()); + tcp_params_ = new TCPSocketParams(host_port_pair.host(), + host_port_pair.port(), + MEDIUM, GURL(), false); + return session_->Connect(host_port_pair.host(), tcp_params_, MEDIUM); + } + SpdySessionDependencies session_deps_; + scoped_refptr<OrderedSocketData> data_; + scoped_refptr<HttpNetworkSession> http_session_; + scoped_refptr<SpdySession> session_; + scoped_refptr<TCPSocketParams> tcp_params_; }; TEST_F(SpdyHttpStreamTest, SendRequest) { @@ -34,24 +52,10 @@ TEST_F(SpdyHttpStreamTest, SendRequest) { MockRead reads[] = { MockRead(false, 0, 2) // EOF }; - scoped_refptr<OrderedSocketData> data( - new OrderedSocketData(reads, arraysize(reads), - writes, arraysize(writes))); - session_deps.socket_factory.AddSocketDataProvider(data.get()); - - scoped_refptr<HttpNetworkSession> http_session( - SpdySessionDependencies::SpdyCreateSession(&session_deps)); - scoped_refptr<SpdySessionPool> spdy_session_pool( - http_session->spdy_session_pool()); + HostPortPair host_port_pair("www.google.com", 80); - scoped_refptr<SpdySession> session = - spdy_session_pool->Get( - host_port_pair, http_session.get(), BoundNetLog()); - scoped_refptr<TCPSocketParams> tcp_params = - new TCPSocketParams(host_port_pair.host(), host_port_pair.port(), - MEDIUM, GURL(), false); - int rv = session->Connect(host_port_pair.host(), tcp_params, MEDIUM); - ASSERT_EQ(OK, rv); + EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), + host_port_pair)); HttpRequestInfo request; request.method = "GET"; @@ -61,13 +65,55 @@ TEST_F(SpdyHttpStreamTest, SendRequest) { scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream()); ASSERT_EQ( OK, - http_stream->InitializeStream(session, request, BoundNetLog(), NULL)); + http_stream->InitializeStream(session_, request, BoundNetLog(), NULL)); http_stream->InitializeRequest(base::Time::Now(), NULL); + EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(&response, &callback)); MessageLoop::current()->RunAllPending(); - EXPECT_TRUE(spdy_session_pool->HasSession(host_port_pair)); - spdy_session_pool->Remove(session); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(host_port_pair)); + http_session_->spdy_session_pool()->Remove(session_); +} + +// Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 +TEST_F(SpdyHttpStreamTest, SpdyURLTest) { + EnableCompression(false); + SpdySession::SetSSLMode(false); + + scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); + MockWrite writes[] = { + CreateMockWrite(*req.get(), 1), + }; + MockRead reads[] = { + MockRead(false, 0, 2), // EOF + }; + + HostPortPair host_port_pair("www.google.com", 80); + EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), + host_port_pair)); + + HttpRequestInfo request; + request.method = "GET"; + request.url = GURL("http://www.google.com/foo?query=what#anchor"); + TestCompletionCallback callback; + HttpResponseInfo response; + scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream()); + ASSERT_EQ( + OK, + http_stream->InitializeStream(session_, request, BoundNetLog(), NULL)); + http_stream->InitializeRequest(base::Time::Now(), NULL); + + spdy::SpdyHeaderBlock* spdy_header = + http_stream->stream()->spdy_headers().get(); + if (spdy_header->find("url") != spdy_header->end()) + EXPECT_EQ("http://www.google.com/foo?query=what", + spdy_header->find("url")->second); + else + FAIL() << "No url is set in spdy_header!"; + + MessageLoop::current()->RunAllPending(); + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(host_port_pair)); + http_session_->spdy_session_pool()->Remove(session_); } // TODO(willchan): Write a longer test for SpdyStream that exercises all |