diff options
author | erikchen@google.com <erikchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-05 17:59:58 +0000 |
---|---|---|
committer | erikchen@google.com <erikchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-05 17:59:58 +0000 |
commit | e3ebba0fbbfb2c7eec286a964717859aa70b9fcf (patch) | |
tree | b2a53d996ca4537fbb6516dcddba122d1cb6cbcd /net/spdy/spdy_test_util.cc | |
parent | 1b7cde151f8e0e922a8c52c6ca48f6f1c6de21ec (diff) | |
download | chromium_src-e3ebba0fbbfb2c7eec286a964717859aa70b9fcf.zip chromium_src-e3ebba0fbbfb2c7eec286a964717859aa70b9fcf.tar.gz chromium_src-e3ebba0fbbfb2c7eec286a964717859aa70b9fcf.tar.bz2 |
Implement server push protocol 2.
TEST=net_unittests
BUG=34761
Review URL: http://codereview.chromium.org/3020032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55095 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy/spdy_test_util.cc')
-rw-r--r-- | net/spdy/spdy_test_util.cc | 295 |
1 files changed, 219 insertions, 76 deletions
diff --git a/net/spdy/spdy_test_util.cc b/net/spdy/spdy_test_util.cc index aa566d1..56d45ec 100644 --- a/net/spdy/spdy_test_util.cc +++ b/net/spdy/spdy_test_util.cc @@ -251,6 +251,57 @@ int ConstructSpdyHeader(const char* const extra_headers[], return n; } +spdy::SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], + int extra_header_count, + bool compressed, + int stream_id, + RequestPriority request_priority, + spdy::SpdyControlType type, + spdy::SpdyControlFlags flags, + const char* const* kHeaders, + int kHeadersSize) { + return ConstructSpdyControlFrame(extra_headers, + extra_header_count, + compressed, + stream_id, + request_priority, + type, + flags, + kHeaders, + kHeadersSize, + 0); +} + +spdy::SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], + int extra_header_count, + bool compressed, + int stream_id, + RequestPriority request_priority, + spdy::SpdyControlType type, + spdy::SpdyControlFlags flags, + const char* const* kHeaders, + int kHeadersSize, + int associated_stream_id) { + const SpdyHeaderInfo kSynStartHeader = { + type, // Kind = Syn + stream_id, // Stream ID + associated_stream_id, // Associated stream ID + net::ConvertRequestPriorityToSpdyPriority(request_priority), + // Priority + flags, // Control Flags + compressed, // Compressed + spdy::INVALID, // Status + NULL, // Data + 0, // Length + spdy::DATA_FLAG_NONE // Data Flags + }; + return ConstructSpdyPacket(kSynStartHeader, + extra_headers, + extra_header_count, + kHeaders, + kHeadersSize / 2); +} + // Constructs a standard SPDY GET SYN packet, optionally compressed // for the url |url|. // |extra_headers| are the extra header-value pairs, which typically @@ -319,19 +370,6 @@ spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], bool compressed, int stream_id, RequestPriority request_priority) { - const SpdyHeaderInfo kSynStartHeader = { - spdy::SYN_STREAM, // Kind = Syn - stream_id, // Stream ID - 0, // Associated stream ID - net::ConvertRequestPriorityToSpdyPriority(request_priority), - // Priority - spdy::CONTROL_FLAG_FIN, // Control Flags - compressed, // Compressed - spdy::INVALID, // Status - NULL, // Data - 0, // Length - spdy::DATA_FLAG_NONE // Data Flags - }; static const char* const kStandardGetHeaders[] = { "method", "GET", @@ -344,12 +382,132 @@ spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], "version", "HTTP/1.1" }; - return ConstructSpdyPacket( - kSynStartHeader, - extra_headers, - extra_header_count, - kStandardGetHeaders, - arraysize(kStandardGetHeaders) / 2); + return ConstructSpdyControlFrame(extra_headers, + extra_header_count, + compressed, + stream_id, + request_priority, + spdy::SYN_STREAM, + spdy::CONTROL_FLAG_FIN, + kStandardGetHeaders, + arraysize(kStandardGetHeaders)); +} + +// Constructs a standard SPDY push SYN packet. +// |extra_headers| are the extra header-value pairs, which typically +// will vary the most between calls. +// Returns a SpdyFrame. +spdy::SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], + int extra_header_count, + int stream_id, + int associated_stream_id) { + const char* const kStandardGetHeaders[] = { + "hello", + "bye", + "status", + "200", + "version", + "HTTP/1.1" + }; + return ConstructSpdyControlFrame(extra_headers, + extra_header_count, + false, + stream_id, + LOWEST, + spdy::SYN_STREAM, + spdy::CONTROL_FLAG_NONE, + kStandardGetHeaders, + arraysize(kStandardGetHeaders), + associated_stream_id); +} + +spdy::SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], + int extra_header_count, + int stream_id, + int associated_stream_id, + const char* path) { + const char* const kStandardGetHeaders[] = { + "hello", + "bye", + "path", + path, + "status", + "200 OK", + "url", + path, + "version", + "HTTP/1.1" + }; + return ConstructSpdyControlFrame(extra_headers, + extra_header_count, + false, + stream_id, + LOWEST, + spdy::SYN_STREAM, + spdy::CONTROL_FLAG_NONE, + kStandardGetHeaders, + arraysize(kStandardGetHeaders), + associated_stream_id); + +} +spdy::SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], + int extra_header_count, + int stream_id, + int associated_stream_id, + const char* path, + const char* status, + const char* location, + const char* url) { + const char* const kStandardGetHeaders[] = { + "hello", + "bye", + "path", + path, + "status", + status, + "location", + location, + "url", + url, + "version", + "HTTP/1.1" + }; + return ConstructSpdyControlFrame(extra_headers, + extra_header_count, + false, + stream_id, + LOWEST, + spdy::SYN_STREAM, + spdy::CONTROL_FLAG_NONE, + kStandardGetHeaders, + arraysize(kStandardGetHeaders), + associated_stream_id); +} + +// Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. +// |extra_headers| are the extra header-value pairs, which typically +// will vary the most between calls. +// Returns a SpdyFrame. +spdy::SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) { + static const char* const kStandardGetHeaders[] = { + "hello", + "bye", + "status", + "301 Moved Permanently", + "location", + "http://www.foo.com/index.php", + "version", + "HTTP/1.1" + }; + return ConstructSpdyControlFrame(NULL, + 0, + false, + stream_id, + LOWEST, + spdy::SYN_REPLY, + spdy::CONTROL_FLAG_NONE, + kStandardGetHeaders, + arraysize(kStandardGetHeaders)); } // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. @@ -359,19 +517,6 @@ spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], int extra_header_count, int stream_id) { - const SpdyHeaderInfo kSynStartHeader = { - spdy::SYN_REPLY, // Kind = SynReply - stream_id, // Stream ID - 0, // Associated stream ID - net::ConvertRequestPriorityToSpdyPriority(LOWEST), - // Priority - spdy::CONTROL_FLAG_NONE, // Control Flags - false, // Compressed - spdy::INVALID, // Status - NULL, // Data - 0, // Length - spdy::DATA_FLAG_NONE // Data Flags - }; static const char* const kStandardGetHeaders[] = { "hello", "bye", @@ -382,12 +527,15 @@ spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], "version", "HTTP/1.1" }; - return ConstructSpdyPacket( - kSynStartHeader, - extra_headers, - extra_header_count, - kStandardGetHeaders, - arraysize(kStandardGetHeaders) / 2); + return ConstructSpdyControlFrame(extra_headers, + extra_header_count, + false, + stream_id, + LOWEST, + spdy::SYN_REPLY, + spdy::CONTROL_FLAG_NONE, + kStandardGetHeaders, + arraysize(kStandardGetHeaders)); } // Constructs a standard SPDY POST SYN packet. @@ -398,19 +546,6 @@ spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], spdy::SpdyFrame* ConstructSpdyPost(int64 content_length, const char* const extra_headers[], int extra_header_count) { - const SpdyHeaderInfo kSynStartHeader = { - spdy::SYN_STREAM, // Kind = Syn - 1, // Stream ID - 0, // Associated stream ID - net::ConvertRequestPriorityToSpdyPriority(LOWEST), - // Priority - spdy::CONTROL_FLAG_NONE, // Control Flags - false, // Compressed - spdy::INVALID, // Status - NULL, // Data - 0, // Length - spdy::DATA_FLAG_NONE // Data Flags - }; std::string length_str = base::Int64ToString(content_length); const char* post_headers[] = { "method", @@ -426,12 +561,15 @@ spdy::SpdyFrame* ConstructSpdyPost(int64 content_length, "content-length", length_str.c_str() }; - return ConstructSpdyPacket( - kSynStartHeader, - extra_headers, - extra_header_count, - post_headers, - arraysize(post_headers) / 2); + return ConstructSpdyControlFrame(extra_headers, + extra_header_count, + false, + 1, + LOWEST, + spdy::SYN_STREAM, + spdy::CONTROL_FLAG_NONE, + post_headers, + arraysize(post_headers)); } // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. @@ -440,19 +578,6 @@ spdy::SpdyFrame* ConstructSpdyPost(int64 content_length, // Returns a SpdyFrame. spdy::SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], int extra_header_count) { - const SpdyHeaderInfo kSynStartHeader = { - spdy::SYN_REPLY, // Kind = SynReply - 1, // Stream ID - 0, // Associated stream ID - net::ConvertRequestPriorityToSpdyPriority(LOWEST), - // Priority - spdy::CONTROL_FLAG_NONE, // Control Flags - false, // Compressed - spdy::INVALID, // Status - NULL, // Data - 0, // Length - spdy::DATA_FLAG_NONE // Data Flags - }; static const char* const kStandardGetHeaders[] = { "hello", "bye", @@ -463,12 +588,15 @@ spdy::SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], "version", "HTTP/1.1" }; - return ConstructSpdyPacket( - kSynStartHeader, - extra_headers, - extra_header_count, - kStandardGetHeaders, - arraysize(kStandardGetHeaders) / 2); + return ConstructSpdyControlFrame(extra_headers, + extra_header_count, + false, + 1, + LOWEST, + spdy::SYN_REPLY, + spdy::CONTROL_FLAG_NONE, + kStandardGetHeaders, + arraysize(kStandardGetHeaders)); } // Constructs a single SPDY data frame with the contents "hello!" @@ -607,4 +735,19 @@ ProxyService* SpdyCreateFixedProxyService(const std::string& proxy) { return ProxyService::CreateFixed(proxy_config); } +const SpdyHeaderInfo make_spdy_header(spdy::SpdyControlType type) { + const SpdyHeaderInfo kHeader = { + type, // Kind = Syn + 1, // Stream ID + 0, // Associated stream ID + 2, // Priority + spdy::CONTROL_FLAG_FIN, // Control Flags + false, // Compressed + spdy::INVALID, // Status + NULL, // Data + 0, // Length + spdy::DATA_FLAG_NONE // Data Flags + }; + return kHeader; +} } // namespace net |