| Index: net/spdy/spdy_test_util_spdy3.cc
|
| diff --git a/net/spdy/spdy_test_util_spdy3.cc b/net/spdy/spdy_test_util_spdy3.cc
|
| index 660c19dc0610d400793d73cd3ad7ecb3729a31f5..6516ee8d81b432d107eb10889005b34a313bb47a 100644
|
| --- a/net/spdy/spdy_test_util_spdy3.cc
|
| +++ b/net/spdy/spdy_test_util_spdy3.cc
|
| @@ -134,9 +134,9 @@ MockRead* ChopReadFrame(const SpdyFrame& frame, int num_chunks) {
|
| // where the even entries are the header names, and the odd entries are the
|
| // header values.
|
| // |headers| gets filled in from |extra_headers|.
|
| -void AppendHeadersToSpdyFrame(const char* const extra_headers[],
|
| - int extra_header_count,
|
| - SpdyHeaderBlock* headers) {
|
| +void AppendToHeaderBlock(const char* const extra_headers[],
|
| + int extra_header_count,
|
| + SpdyHeaderBlock* headers) {
|
| std::string this_header;
|
| std::string this_value;
|
|
|
| @@ -176,6 +176,39 @@ void AppendHeadersToSpdyFrame(const char* const extra_headers[],
|
| }
|
| }
|
|
|
| +scoped_ptr<SpdyHeaderBlock> ConstructGetHeaderBlock(base::StringPiece url) {
|
| + std::string scheme, host, path;
|
| + ParseUrl(url.data(), &scheme, &host, &path);
|
| + const char* const headers[] = {
|
| + ":method", "GET",
|
| + ":path", path.c_str(),
|
| + ":host", host.c_str(),
|
| + ":scheme", scheme.c_str(),
|
| + ":version", "HTTP/1.1"
|
| + };
|
| + scoped_ptr<SpdyHeaderBlock> header_block(new SpdyHeaderBlock());
|
| + AppendToHeaderBlock(headers, arraysize(headers) / 2, header_block.get());
|
| + return header_block.Pass();
|
| +}
|
| +
|
| +scoped_ptr<SpdyHeaderBlock> ConstructPostHeaderBlock(base::StringPiece url,
|
| + int64 content_length) {
|
| + std::string scheme, host, path;
|
| + ParseUrl(url.data(), &scheme, &host, &path);
|
| + std::string length_str = base::Int64ToString(content_length);
|
| + const char* const headers[] = {
|
| + ":method", "POST",
|
| + ":path", path.c_str(),
|
| + ":host", host.c_str(),
|
| + ":scheme", scheme.c_str(),
|
| + ":version", "HTTP/1.1",
|
| + "content-length", length_str.c_str()
|
| + };
|
| + scoped_ptr<SpdyHeaderBlock> header_block(new SpdyHeaderBlock());
|
| + AppendToHeaderBlock(headers, arraysize(headers) / 2, header_block.get());
|
| + return header_block.Pass();
|
| +}
|
| +
|
| // Writes |val| to a location of size |len|, in big-endian format.
|
| // in the buffer pointed to by |buffer_handle|.
|
| // Updates the |*buffer_handle| pointer by |len|
|
| @@ -201,26 +234,9 @@ int AppendToBuffer(int val,
|
| return len;
|
| }
|
|
|
| -// Construct a SPDY packet.
|
| -// |head| is the start of the packet, up to but not including
|
| -// the header value pairs.
|
| -// |extra_headers| are the extra header-value pairs, which typically
|
| -// will vary the most between calls.
|
| -// |tail| is any (relatively constant) header-value pairs to add.
|
| -// |buffer| is the buffer we're filling in.
|
| -// Returns a SpdyFrame.
|
| -SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info,
|
| - const char* const extra_headers[],
|
| - int extra_header_count,
|
| - const char* const tail[],
|
| - int tail_header_count) {
|
| - BufferedSpdyFramer framer(3, header_info.compressed);
|
| - SpdyHeaderBlock headers;
|
| - // Copy in the extra headers to our map.
|
| - AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers);
|
| - // Copy in the tail headers to our map.
|
| - if (tail && tail_header_count)
|
| - AppendHeadersToSpdyFrame(tail, tail_header_count, &headers);
|
| +SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info,
|
| + scoped_ptr<SpdyHeaderBlock> headers) {
|
| + BufferedSpdyFramer framer(kSpdyVersion3, header_info.compressed);
|
| SpdyFrame* frame = NULL;
|
| switch (header_info.kind) {
|
| case SYN_STREAM:
|
| @@ -228,18 +244,18 @@ SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info,
|
| header_info.priority,
|
| header_info.credential_slot,
|
| header_info.control_flags,
|
| - header_info.compressed, &headers);
|
| + header_info.compressed, headers.get());
|
| break;
|
| case SYN_REPLY:
|
| frame = framer.CreateSynReply(header_info.id, header_info.control_flags,
|
| - header_info.compressed, &headers);
|
| + header_info.compressed, headers.get());
|
| break;
|
| case RST_STREAM:
|
| frame = framer.CreateRstStream(header_info.id, header_info.status);
|
| break;
|
| case HEADERS:
|
| frame = framer.CreateHeaders(header_info.id, header_info.control_flags,
|
| - header_info.compressed, &headers);
|
| + header_info.compressed, headers.get());
|
| break;
|
| default:
|
| frame = framer.CreateDataFrame(header_info.id, header_info.data,
|
| @@ -250,6 +266,18 @@ SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info,
|
| return frame;
|
| }
|
|
|
| +SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info,
|
| + const char* const extra_headers[],
|
| + int extra_header_count,
|
| + const char* const tail[],
|
| + int tail_header_count) {
|
| + scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock());
|
| + AppendToHeaderBlock(extra_headers, extra_header_count, headers.get());
|
| + if (tail && tail_header_count)
|
| + AppendToHeaderBlock(tail, tail_header_count, headers.get());
|
| + return ConstructSpdyFrame(header_info, headers.Pass());
|
| +}
|
| +
|
| // Construct an expected SPDY SETTINGS frame.
|
| // |settings| are the settings to set.
|
| // Returns the constructed frame. The caller takes ownership of the frame.
|
| @@ -382,14 +410,14 @@ SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[],
|
| 0, // Length
|
| DATA_FLAG_NONE // Data Flags
|
| };
|
| - return ConstructSpdyPacket(kSynStartHeader,
|
| - extra_headers,
|
| - extra_header_count,
|
| - kHeaders,
|
| - kHeadersSize / 2);
|
| + return ConstructSpdyFrame(kSynStartHeader,
|
| + extra_headers,
|
| + extra_header_count,
|
| + kHeaders,
|
| + kHeadersSize / 2);
|
| }
|
|
|
| -// Constructs a standard SPDY GET SYN packet, optionally compressed
|
| +// Constructs a standard SPDY GET SYN frame, optionally compressed
|
| // for the url |url|.
|
| // |extra_headers| are the extra header-value pairs, which typically
|
| // will vary the most between calls.
|
| @@ -412,25 +440,10 @@ SpdyFrame* ConstructSpdyGet(const char* const url,
|
| 0, // Length
|
| DATA_FLAG_NONE // Data Flags
|
| };
|
| -
|
| - std::string scheme, host, path;
|
| - ParseUrl(url, &scheme, &host, &path);
|
| - const char* const headers[] = {
|
| - ":method", "GET",
|
| - ":path", path.c_str(),
|
| - ":host", host.c_str(),
|
| - ":scheme", scheme.c_str(),
|
| - ":version", "HTTP/1.1"
|
| - };
|
| - return ConstructSpdyPacket(
|
| - kSynStartHeader,
|
| - NULL,
|
| - 0,
|
| - headers,
|
| - arraysize(headers) / 2);
|
| + return ConstructSpdyFrame(kSynStartHeader, ConstructGetHeaderBlock(url));
|
| }
|
|
|
| -// Constructs a standard SPDY GET SYN packet, optionally compressed.
|
| +// Constructs a standard SPDY GET SYN frame, optionally compressed.
|
| // |extra_headers| are the extra header-value pairs, which typically
|
| // will vary the most between calls.
|
| // Returns a SpdyFrame.
|
| @@ -443,7 +456,7 @@ SpdyFrame* ConstructSpdyGet(const char* const extra_headers[],
|
| stream_id, request_priority, true);
|
| }
|
|
|
| -// Constructs a standard SPDY GET SYN packet, optionally compressed.
|
| +// Constructs a standard SPDY GET SYN frame, optionally compressed.
|
| // |extra_headers| are the extra header-value pairs, which typically
|
| // will vary the most between calls.
|
| // Returns a SpdyFrame.
|
| @@ -492,7 +505,7 @@ SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[],
|
| arraysize(kConnectHeaders));
|
| }
|
|
|
| -// Constructs a standard SPDY push SYN packet.
|
| +// Constructs a standard SPDY push SYN frame.
|
| // |extra_headers| are the extra header-value pairs, which typically
|
| // will vary the most between calls.
|
| // Returns a SpdyFrame.
|
| @@ -592,7 +605,7 @@ SpdyFrame* ConstructSpdyPushHeaders(int stream_id,
|
| arraysize(kStandardGetHeaders));
|
| }
|
|
|
| -// Constructs a standard SPDY SYN_REPLY packet with the specified status code.
|
| +// Constructs a standard SPDY SYN_REPLY frame with the specified status code.
|
| // Returns a SpdyFrame.
|
| SpdyFrame* ConstructSpdySynReplyError(const char* const status,
|
| const char* const* const extra_headers,
|
| @@ -614,7 +627,7 @@ SpdyFrame* ConstructSpdySynReplyError(const char* const status,
|
| arraysize(kStandardGetHeaders));
|
| }
|
|
|
| -// Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET.
|
| +// Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET.
|
| // |extra_headers| are the extra header-value pairs, which typically
|
| // will vary the most between calls.
|
| // Returns a SpdyFrame.
|
| @@ -626,7 +639,7 @@ SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) {
|
| arraysize(kExtraHeaders)/2, stream_id);
|
| }
|
|
|
| -// Constructs a standard SPDY SYN_REPLY packet with an Internal Server
|
| +// Constructs a standard SPDY SYN_REPLY frame with an Internal Server
|
| // Error status code.
|
| // Returns a SpdyFrame.
|
| SpdyFrame* ConstructSpdySynReplyError(int stream_id) {
|
| @@ -636,7 +649,7 @@ SpdyFrame* ConstructSpdySynReplyError(int stream_id) {
|
|
|
|
|
|
|
| -// Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET.
|
| +// Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET.
|
| // |extra_headers| are the extra header-value pairs, which typically
|
| // will vary the most between calls.
|
| // Returns a SpdyFrame.
|
| @@ -659,35 +672,36 @@ SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[],
|
| arraysize(kStandardGetHeaders));
|
| }
|
|
|
| -// Constructs a standard SPDY POST SYN packet.
|
| +// Constructs a standard SPDY POST SYN frame.
|
| // |content_length| is the size of post data.
|
| // |extra_headers| are the extra header-value pairs, which typically
|
| // will vary the most between calls.
|
| // Returns a SpdyFrame.
|
| -SpdyFrame* ConstructSpdyPost(int64 content_length,
|
| +SpdyFrame* ConstructSpdyPost(const char* url,
|
| + SpdyStreamId stream_id,
|
| + int64 content_length,
|
| + RequestPriority priority,
|
| const char* const extra_headers[],
|
| int extra_header_count) {
|
| - std::string length_str = base::Int64ToString(content_length);
|
| - const char* post_headers[] = {
|
| - ":method", "POST",
|
| - ":path", "/",
|
| - ":host", "www.google.com",
|
| - ":scheme", "http",
|
| - ":version", "HTTP/1.1",
|
| - "content-length", length_str.c_str()
|
| + const SpdyHeaderInfo kSynStartHeader = {
|
| + SYN_STREAM, // Kind = Syn
|
| + stream_id, // Stream ID
|
| + 0, // Associated stream ID
|
| + ConvertRequestPriorityToSpdyPriority(priority, kSpdyVersion3),
|
| + // Priority
|
| + 0, // Credential Slot
|
| + CONTROL_FLAG_NONE, // Control Flags
|
| + false, // Compressed
|
| + RST_STREAM_INVALID, // Status
|
| + NULL, // Data
|
| + 0, // Length
|
| + DATA_FLAG_NONE // Data Flags
|
| };
|
| - return ConstructSpdyControlFrame(extra_headers,
|
| - extra_header_count,
|
| - false,
|
| - 1,
|
| - LOWEST,
|
| - SYN_STREAM,
|
| - CONTROL_FLAG_NONE,
|
| - post_headers,
|
| - arraysize(post_headers));
|
| + return ConstructSpdyFrame(
|
| + kSynStartHeader, ConstructPostHeaderBlock(url, content_length));
|
| }
|
|
|
| -// Constructs a chunked transfer SPDY POST SYN packet.
|
| +// Constructs a chunked transfer SPDY POST SYN frame.
|
| // |extra_headers| are the extra header-value pairs, which typically
|
| // will vary the most between calls.
|
| // Returns a SpdyFrame.
|
| @@ -711,7 +725,7 @@ SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[],
|
| arraysize(post_headers));
|
| }
|
|
|
| -// Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST.
|
| +// Constructs a standard SPDY SYN_REPLY frame to match the SPDY POST.
|
| // |extra_headers| are the extra header-value pairs, which typically
|
| // will vary the most between calls.
|
| // Returns a SpdyFrame.
|
| @@ -767,14 +781,14 @@ int ConstructSpdyReplyString(const char* const extra_headers[],
|
| int extra_header_count,
|
| char* buffer,
|
| int buffer_length) {
|
| - int packet_size = 0;
|
| + int frame_size = 0;
|
| char* buffer_write = buffer;
|
| int buffer_left = buffer_length;
|
| SpdyHeaderBlock headers;
|
| if (!buffer || !buffer_length)
|
| return 0;
|
| // Copy in the extra headers.
|
| - AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers);
|
| + AppendToHeaderBlock(extra_headers, extra_header_count, &headers);
|
| // The iterator gets us the list of header/value pairs in sorted order.
|
| SpdyHeaderBlock::iterator next = headers.begin();
|
| SpdyHeaderBlock::iterator last = headers.end();
|
| @@ -784,14 +798,14 @@ int ConstructSpdyReplyString(const char* const extra_headers[],
|
| const char* header_string = next->first.c_str();
|
| if (header_string && header_string[0] == ':')
|
| header_string++;
|
| - packet_size += AppendToBuffer(header_string,
|
| - strlen(header_string),
|
| - &buffer_write,
|
| - &buffer_left);
|
| - packet_size += AppendToBuffer(": ",
|
| - strlen(": "),
|
| - &buffer_write,
|
| - &buffer_left);
|
| + frame_size += AppendToBuffer(header_string,
|
| + strlen(header_string),
|
| + &buffer_write,
|
| + &buffer_left);
|
| + frame_size += AppendToBuffer(": ",
|
| + strlen(": "),
|
| + &buffer_write,
|
| + &buffer_left);
|
| // Write the value(s).
|
| const char* value_string = next->second.c_str();
|
| // Check if it's split among two or more values.
|
| @@ -801,39 +815,39 @@ int ConstructSpdyReplyString(const char* const extra_headers[],
|
| // Handle the first N-1 values.
|
| while (current_len < value_len) {
|
| // Finish this line -- write the current value.
|
| - packet_size += AppendToBuffer(value_string + offset,
|
| - current_len - offset,
|
| - &buffer_write,
|
| - &buffer_left);
|
| - packet_size += AppendToBuffer("\n",
|
| - strlen("\n"),
|
| - &buffer_write,
|
| - &buffer_left);
|
| + frame_size += AppendToBuffer(value_string + offset,
|
| + current_len - offset,
|
| + &buffer_write,
|
| + &buffer_left);
|
| + frame_size += AppendToBuffer("\n",
|
| + strlen("\n"),
|
| + &buffer_write,
|
| + &buffer_left);
|
| // Advance to next value.
|
| offset = current_len + 1;
|
| current_len += 1 + strlen(value_string + offset);
|
| // Start another line -- add the header again.
|
| - packet_size += AppendToBuffer(header_string,
|
| - next->first.length(),
|
| - &buffer_write,
|
| - &buffer_left);
|
| - packet_size += AppendToBuffer(": ",
|
| - strlen(": "),
|
| - &buffer_write,
|
| - &buffer_left);
|
| + frame_size += AppendToBuffer(header_string,
|
| + next->first.length(),
|
| + &buffer_write,
|
| + &buffer_left);
|
| + frame_size += AppendToBuffer(": ",
|
| + strlen(": "),
|
| + &buffer_write,
|
| + &buffer_left);
|
| }
|
| EXPECT_EQ(value_len, current_len);
|
| // Copy the last (or only) value.
|
| - packet_size += AppendToBuffer(value_string + offset,
|
| - value_len - offset,
|
| - &buffer_write,
|
| - &buffer_left);
|
| - packet_size += AppendToBuffer("\n",
|
| - strlen("\n"),
|
| - &buffer_write,
|
| - &buffer_left);
|
| + frame_size += AppendToBuffer(value_string + offset,
|
| + value_len - offset,
|
| + &buffer_write,
|
| + &buffer_left);
|
| + frame_size += AppendToBuffer("\n",
|
| + strlen("\n"),
|
| + &buffer_write,
|
| + &buffer_left);
|
| }
|
| - return packet_size;
|
| + return frame_size;
|
| }
|
|
|
| // Create a MockWrite from the given SpdyFrame.
|
|
|