Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: net/spdy/spdy_test_util_spdy2.cc

Issue 12743006: [SPDY] Refactor tests in preparation for a fix for a session flow control bug (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_test_util_spdy2.h ('k') | net/spdy/spdy_test_util_spdy3.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/spdy_test_util_spdy2.h" 5 #include "net/spdy/spdy_test_util_spdy2.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // |num_chunks| is the number of chunks to create. 83 // |num_chunks| is the number of chunks to create.
84 MockRead* ChopReadFrame(const SpdyFrame& frame, int num_chunks) { 84 MockRead* ChopReadFrame(const SpdyFrame& frame, int num_chunks) {
85 return ChopReadFrame(frame.data(), frame.size(), num_chunks); 85 return ChopReadFrame(frame.data(), frame.size(), num_chunks);
86 } 86 }
87 87
88 // Adds headers and values to a map. 88 // Adds headers and values to a map.
89 // |extra_headers| is an array of { name, value } pairs, arranged as strings 89 // |extra_headers| is an array of { name, value } pairs, arranged as strings
90 // where the even entries are the header names, and the odd entries are the 90 // where the even entries are the header names, and the odd entries are the
91 // header values. 91 // header values.
92 // |headers| gets filled in from |extra_headers|. 92 // |headers| gets filled in from |extra_headers|.
93 void AppendHeadersToSpdyFrame(const char* const extra_headers[], 93 void AppendToHeaderBlock(const char* const extra_headers[],
94 int extra_header_count, 94 int extra_header_count,
95 SpdyHeaderBlock* headers) { 95 SpdyHeaderBlock* headers) {
96 std::string this_header; 96 std::string this_header;
97 std::string this_value; 97 std::string this_value;
98 98
99 if (!extra_header_count) 99 if (!extra_header_count)
100 return; 100 return;
101 101
102 // Sanity check: Non-NULL header list. 102 // Sanity check: Non-NULL header list.
103 DCHECK(NULL != extra_headers) << "NULL header value pair list"; 103 DCHECK(NULL != extra_headers) << "NULL header value pair list";
104 // Sanity check: Non-NULL header map. 104 // Sanity check: Non-NULL header map.
105 DCHECK(NULL != headers) << "NULL header map"; 105 DCHECK(NULL != headers) << "NULL header map";
(...skipping 19 matching lines...) Expand all
125 // Append the new value. 125 // Append the new value.
126 new_value += this_value; 126 new_value += this_value;
127 } else { 127 } else {
128 // Not a duplicate, just write the value. 128 // Not a duplicate, just write the value.
129 new_value = this_value; 129 new_value = this_value;
130 } 130 }
131 (*headers)[this_header] = new_value; 131 (*headers)[this_header] = new_value;
132 } 132 }
133 } 133 }
134 134
135 scoped_ptr<SpdyHeaderBlock> ConstructGetHeaderBlock(base::StringPiece url) {
136 std::string scheme, host, path;
137 ParseUrl(url.data(), &scheme, &host, &path);
138 const char* const headers[] = {
139 "method", "GET",
140 "url", path.c_str(),
141 "host", host.c_str(),
142 "scheme", scheme.c_str(),
143 "version", "HTTP/1.1"
144 };
145 scoped_ptr<SpdyHeaderBlock> header_block(new SpdyHeaderBlock());
146 AppendToHeaderBlock(headers, arraysize(headers) / 2, header_block.get());
147 return header_block.Pass();
148 }
149
150 scoped_ptr<SpdyHeaderBlock> ConstructPostHeaderBlock(base::StringPiece url,
151 int64 content_length) {
152 std::string scheme, host, path;
153 ParseUrl(url.data(), &scheme, &host, &path);
154 std::string length_str = base::Int64ToString(content_length);
155 const char* const headers[] = {
156 "method", "POST",
157 "url", path.c_str(),
158 "host", host.c_str(),
159 "scheme", scheme.c_str(),
160 "version", "HTTP/1.1",
161 "content-length", length_str.c_str()
162 };
163 scoped_ptr<SpdyHeaderBlock> header_block(new SpdyHeaderBlock());
164 AppendToHeaderBlock(headers, arraysize(headers) / 2, header_block.get());
165 return header_block.Pass();
166 }
167
135 // Writes |val| to a location of size |len|, in big-endian format. 168 // Writes |val| to a location of size |len|, in big-endian format.
136 // in the buffer pointed to by |buffer_handle|. 169 // in the buffer pointed to by |buffer_handle|.
137 // Updates the |*buffer_handle| pointer by |len| 170 // Updates the |*buffer_handle| pointer by |len|
138 // Returns the number of bytes written 171 // Returns the number of bytes written
139 int AppendToBuffer(int val, 172 int AppendToBuffer(int val,
140 int len, 173 int len,
141 unsigned char** buffer_handle, 174 unsigned char** buffer_handle,
142 int* buffer_len_remaining) { 175 int* buffer_len_remaining) {
143 if (len <= 0) 176 if (len <= 0)
144 return 0; 177 return 0;
145 DCHECK((size_t) len <= sizeof(len)) << "Data length too long for data type"; 178 DCHECK((size_t) len <= sizeof(len)) << "Data length too long for data type";
146 DCHECK(NULL != buffer_handle) << "NULL buffer handle"; 179 DCHECK(NULL != buffer_handle) << "NULL buffer handle";
147 DCHECK(NULL != *buffer_handle) << "NULL pointer"; 180 DCHECK(NULL != *buffer_handle) << "NULL pointer";
148 DCHECK(NULL != buffer_len_remaining) 181 DCHECK(NULL != buffer_len_remaining)
149 << "NULL buffer remainder length pointer"; 182 << "NULL buffer remainder length pointer";
150 DCHECK_GE(*buffer_len_remaining, len) << "Insufficient buffer size"; 183 DCHECK_GE(*buffer_len_remaining, len) << "Insufficient buffer size";
151 for (int i = 0; i < len; i++) { 184 for (int i = 0; i < len; i++) {
152 int shift = (8 * (len - (i + 1))); 185 int shift = (8 * (len - (i + 1)));
153 unsigned char val_chunk = (val >> shift) & 0x0FF; 186 unsigned char val_chunk = (val >> shift) & 0x0FF;
154 *(*buffer_handle)++ = val_chunk; 187 *(*buffer_handle)++ = val_chunk;
155 *buffer_len_remaining += 1; 188 *buffer_len_remaining += 1;
156 } 189 }
157 return len; 190 return len;
158 } 191 }
159 192
160 // Construct a SPDY packet. 193 SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info,
161 // |head| is the start of the packet, up to but not including 194 scoped_ptr<SpdyHeaderBlock> headers) {
162 // the header value pairs. 195 BufferedSpdyFramer framer(kSpdyVersion2, header_info.compressed);
163 // |extra_headers| are the extra header-value pairs, which typically
164 // will vary the most between calls.
165 // |tail| is any (relatively constant) header-value pairs to add.
166 // |buffer| is the buffer we're filling in.
167 // Returns a SpdyFrame.
168 SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info,
169 const char* const extra_headers[],
170 int extra_header_count,
171 const char* const tail[],
172 int tail_header_count) {
173 BufferedSpdyFramer framer(2, header_info.compressed);
174 SpdyHeaderBlock headers;
175 // Copy in the extra headers to our map.
176 AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers);
177 // Copy in the tail headers to our map.
178 if (tail && tail_header_count)
179 AppendHeadersToSpdyFrame(tail, tail_header_count, &headers);
180 SpdyFrame* frame = NULL; 196 SpdyFrame* frame = NULL;
181 switch (header_info.kind) { 197 switch (header_info.kind) {
182 case SYN_STREAM: 198 case SYN_STREAM:
183 frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, 199 frame = framer.CreateSynStream(header_info.id, header_info.assoc_id,
184 header_info.priority, 0, 200 header_info.priority, 0,
185 header_info.control_flags, 201 header_info.control_flags,
186 header_info.compressed, &headers); 202 header_info.compressed, headers.get());
187 break; 203 break;
188 case SYN_REPLY: 204 case SYN_REPLY:
189 frame = framer.CreateSynReply(header_info.id, header_info.control_flags, 205 frame = framer.CreateSynReply(header_info.id, header_info.control_flags,
190 header_info.compressed, &headers); 206 header_info.compressed, headers.get());
191 break; 207 break;
192 case RST_STREAM: 208 case RST_STREAM:
193 frame = framer.CreateRstStream(header_info.id, header_info.status); 209 frame = framer.CreateRstStream(header_info.id, header_info.status);
194 break; 210 break;
195 case HEADERS: 211 case HEADERS:
196 frame = framer.CreateHeaders(header_info.id, header_info.control_flags, 212 frame = framer.CreateHeaders(header_info.id, header_info.control_flags,
197 header_info.compressed, &headers); 213 header_info.compressed, headers.get());
198 break; 214 break;
199 default: 215 default:
200 frame = framer.CreateDataFrame(header_info.id, header_info.data, 216 frame = framer.CreateDataFrame(header_info.id, header_info.data,
201 header_info.data_length, 217 header_info.data_length,
202 header_info.data_flags); 218 header_info.data_flags);
203 break; 219 break;
204 } 220 }
205 return frame; 221 return frame;
206 } 222 }
207 223
224 SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info,
225 const char* const extra_headers[],
226 int extra_header_count,
227 const char* const tail[],
228 int tail_header_count) {
229 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock());
230 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get());
231 if (tail && tail_header_count)
232 AppendToHeaderBlock(tail, tail_header_count, headers.get());
233 return ConstructSpdyFrame(header_info, headers.Pass());
234 }
235
208 // Construct an expected SPDY SETTINGS frame. 236 // Construct an expected SPDY SETTINGS frame.
209 // |settings| are the settings to set. 237 // |settings| are the settings to set.
210 // Returns the constructed frame. The caller takes ownership of the frame. 238 // Returns the constructed frame. The caller takes ownership of the frame.
211 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) { 239 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) {
212 BufferedSpdyFramer framer(2, false); 240 BufferedSpdyFramer framer(2, false);
213 return framer.CreateSettings(settings); 241 return framer.CreateSettings(settings);
214 } 242 }
215 243
216 // Construct an expected SPDY CREDENTIAL frame. 244 // Construct an expected SPDY CREDENTIAL frame.
217 // |credential| is the credential to sen. 245 // |credential| is the credential to sen.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 associated_stream_id, // Associated stream ID 357 associated_stream_id, // Associated stream ID
330 ConvertRequestPriorityToSpdyPriority(request_priority, 2), 358 ConvertRequestPriorityToSpdyPriority(request_priority, 2),
331 // Priority 359 // Priority
332 flags, // Control Flags 360 flags, // Control Flags
333 compressed, // Compressed 361 compressed, // Compressed
334 RST_STREAM_INVALID, // Status 362 RST_STREAM_INVALID, // Status
335 NULL, // Data 363 NULL, // Data
336 0, // Length 364 0, // Length
337 DATA_FLAG_NONE // Data Flags 365 DATA_FLAG_NONE // Data Flags
338 }; 366 };
339 return ConstructSpdyPacket(kSynStartHeader, 367 return ConstructSpdyFrame(kSynStartHeader,
340 extra_headers, 368 extra_headers,
341 extra_header_count, 369 extra_header_count,
342 kHeaders, 370 kHeaders,
343 kHeadersSize / 2); 371 kHeadersSize / 2);
344 } 372 }
345 373
346 // Constructs a standard SPDY GET SYN packet, optionally compressed 374 // Constructs a standard SPDY GET SYN frame, optionally compressed
347 // for the url |url|. 375 // for the url |url|.
348 // |extra_headers| are the extra header-value pairs, which typically 376 // |extra_headers| are the extra header-value pairs, which typically
349 // will vary the most between calls. 377 // will vary the most between calls.
350 // Returns a SpdyFrame. 378 // Returns a SpdyFrame.
351 SpdyFrame* ConstructSpdyGet(const char* const url, 379 SpdyFrame* ConstructSpdyGet(const char* const url,
352 bool compressed, 380 bool compressed,
353 SpdyStreamId stream_id, 381 SpdyStreamId stream_id,
354 RequestPriority request_priority) { 382 RequestPriority request_priority) {
355 const SpdyHeaderInfo kSynStartHeader = { 383 const SpdyHeaderInfo kSynStartHeader = {
356 SYN_STREAM, // Kind = Syn 384 SYN_STREAM, // Kind = Syn
357 stream_id, // Stream ID 385 stream_id, // Stream ID
358 0, // Associated stream ID 386 0, // Associated stream ID
359 ConvertRequestPriorityToSpdyPriority(request_priority, 2), 387 ConvertRequestPriorityToSpdyPriority(request_priority, 2),
360 // Priority 388 // Priority
361 CONTROL_FLAG_FIN, // Control Flags 389 CONTROL_FLAG_FIN, // Control Flags
362 compressed, // Compressed 390 compressed, // Compressed
363 RST_STREAM_INVALID, // Status 391 RST_STREAM_INVALID, // Status
364 NULL, // Data 392 NULL, // Data
365 0, // Length 393 0, // Length
366 DATA_FLAG_NONE // Data Flags 394 DATA_FLAG_NONE // Data Flags
367 }; 395 };
368 396 return ConstructSpdyFrame(kSynStartHeader, ConstructGetHeaderBlock(url));
369 std::string scheme, host, path;
370 ParseUrl(url, &scheme, &host, &path);
371 const char* const headers[] = {
372 "method", "GET",
373 "url", path.c_str(),
374 "host", host.c_str(),
375 "scheme", scheme.c_str(),
376 "version", "HTTP/1.1"
377 };
378 return ConstructSpdyPacket(
379 kSynStartHeader,
380 NULL,
381 0,
382 headers,
383 arraysize(headers) / 2);
384 } 397 }
385 398
386 // Constructs a standard SPDY GET SYN packet, optionally compressed. 399 // Constructs a standard SPDY GET SYN frame, optionally compressed.
387 // |extra_headers| are the extra header-value pairs, which typically 400 // |extra_headers| are the extra header-value pairs, which typically
388 // will vary the most between calls. 401 // will vary the most between calls.
389 // Returns a SpdyFrame. 402 // Returns a SpdyFrame.
390 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], 403 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[],
391 int extra_header_count, 404 int extra_header_count,
392 bool compressed, 405 bool compressed,
393 int stream_id, 406 int stream_id,
394 RequestPriority request_priority) { 407 RequestPriority request_priority) {
395 return ConstructSpdyGet(extra_headers, extra_header_count, compressed, 408 return ConstructSpdyGet(extra_headers, extra_header_count, compressed,
396 stream_id, request_priority, true); 409 stream_id, request_priority, true);
397 } 410 }
398 411
399 // Constructs a standard SPDY GET SYN packet, optionally compressed. 412 // Constructs a standard SPDY GET SYN frame, optionally compressed.
400 // |extra_headers| are the extra header-value pairs, which typically 413 // |extra_headers| are the extra header-value pairs, which typically
401 // will vary the most between calls. 414 // will vary the most between calls.
402 // Returns a SpdyFrame. 415 // Returns a SpdyFrame.
403 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], 416 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[],
404 int extra_header_count, 417 int extra_header_count,
405 bool compressed, 418 bool compressed,
406 int stream_id, 419 int stream_id,
407 RequestPriority request_priority, 420 RequestPriority request_priority,
408 bool direct) { 421 bool direct) {
409 const char* const kStandardGetHeaders[] = { 422 const char* const kStandardGetHeaders[] = {
(...skipping 28 matching lines...) Expand all
438 extra_header_count, 451 extra_header_count,
439 /*compressed*/ false, 452 /*compressed*/ false,
440 stream_id, 453 stream_id,
441 LOWEST, 454 LOWEST,
442 SYN_STREAM, 455 SYN_STREAM,
443 CONTROL_FLAG_NONE, 456 CONTROL_FLAG_NONE,
444 kConnectHeaders, 457 kConnectHeaders,
445 arraysize(kConnectHeaders)); 458 arraysize(kConnectHeaders));
446 } 459 }
447 460
448 // Constructs a standard SPDY push SYN packet. 461 // Constructs a standard SPDY push SYN frame.
449 // |extra_headers| are the extra header-value pairs, which typically 462 // |extra_headers| are the extra header-value pairs, which typically
450 // will vary the most between calls. 463 // will vary the most between calls.
451 // Returns a SpdyFrame. 464 // Returns a SpdyFrame.
452 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], 465 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[],
453 int extra_header_count, 466 int extra_header_count,
454 int stream_id, 467 int stream_id,
455 int associated_stream_id) { 468 int associated_stream_id) {
456 const char* const kStandardGetHeaders[] = { 469 const char* const kStandardGetHeaders[] = {
457 "hello", "bye", 470 "hello", "bye",
458 "status", "200", 471 "status", "200",
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 extra_header_count, 561 extra_header_count,
549 false, 562 false,
550 stream_id, 563 stream_id,
551 LOWEST, 564 LOWEST,
552 HEADERS, 565 HEADERS,
553 CONTROL_FLAG_NONE, 566 CONTROL_FLAG_NONE,
554 kStandardGetHeaders, 567 kStandardGetHeaders,
555 arraysize(kStandardGetHeaders)); 568 arraysize(kStandardGetHeaders));
556 } 569 }
557 570
558 // Constructs a standard SPDY SYN_REPLY packet with the specified status code. 571 // Constructs a standard SPDY SYN_REPLY frame with the specified status code.
559 // Returns a SpdyFrame. 572 // Returns a SpdyFrame.
560 SpdyFrame* ConstructSpdySynReplyError(const char* const status, 573 SpdyFrame* ConstructSpdySynReplyError(const char* const status,
561 const char* const* const extra_headers, 574 const char* const* const extra_headers,
562 int extra_header_count, 575 int extra_header_count,
563 int stream_id) { 576 int stream_id) {
564 const char* const kStandardGetHeaders[] = { 577 const char* const kStandardGetHeaders[] = {
565 "hello", "bye", 578 "hello", "bye",
566 "status", status, 579 "status", status,
567 "version", "HTTP/1.1" 580 "version", "HTTP/1.1"
568 }; 581 };
569 return ConstructSpdyControlFrame(extra_headers, 582 return ConstructSpdyControlFrame(extra_headers,
570 extra_header_count, 583 extra_header_count,
571 false, 584 false,
572 stream_id, 585 stream_id,
573 LOWEST, 586 LOWEST,
574 SYN_REPLY, 587 SYN_REPLY,
575 CONTROL_FLAG_NONE, 588 CONTROL_FLAG_NONE,
576 kStandardGetHeaders, 589 kStandardGetHeaders,
577 arraysize(kStandardGetHeaders)); 590 arraysize(kStandardGetHeaders));
578 } 591 }
579 592
580 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. 593 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET.
581 // |extra_headers| are the extra header-value pairs, which typically 594 // |extra_headers| are the extra header-value pairs, which typically
582 // will vary the most between calls. 595 // will vary the most between calls.
583 // Returns a SpdyFrame. 596 // Returns a SpdyFrame.
584 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) { 597 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) {
585 static const char* const kExtraHeaders[] = { 598 static const char* const kExtraHeaders[] = {
586 "location", "http://www.foo.com/index.php", 599 "location", "http://www.foo.com/index.php",
587 }; 600 };
588 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, 601 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders,
589 arraysize(kExtraHeaders)/2, stream_id); 602 arraysize(kExtraHeaders)/2, stream_id);
590 } 603 }
591 604
592 // Constructs a standard SPDY SYN_REPLY packet with an Internal Server 605 // Constructs a standard SPDY SYN_REPLY frame with an Internal Server
593 // Error status code. 606 // Error status code.
594 // Returns a SpdyFrame. 607 // Returns a SpdyFrame.
595 SpdyFrame* ConstructSpdySynReplyError(int stream_id) { 608 SpdyFrame* ConstructSpdySynReplyError(int stream_id) {
596 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); 609 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1);
597 } 610 }
598 611
599 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. 612 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET.
600 // |extra_headers| are the extra header-value pairs, which typically 613 // |extra_headers| are the extra header-value pairs, which typically
601 // will vary the most between calls. 614 // will vary the most between calls.
602 // Returns a SpdyFrame. 615 // Returns a SpdyFrame.
603 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], 616 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[],
604 int extra_header_count, 617 int extra_header_count,
605 int stream_id) { 618 int stream_id) {
606 static const char* const kStandardGetHeaders[] = { 619 static const char* const kStandardGetHeaders[] = {
607 "hello", "bye", 620 "hello", "bye",
608 "status", "200", 621 "status", "200",
609 "version", "HTTP/1.1" 622 "version", "HTTP/1.1"
610 }; 623 };
611 return ConstructSpdyControlFrame(extra_headers, 624 return ConstructSpdyControlFrame(extra_headers,
612 extra_header_count, 625 extra_header_count,
613 false, 626 false,
614 stream_id, 627 stream_id,
615 LOWEST, 628 LOWEST,
616 SYN_REPLY, 629 SYN_REPLY,
617 CONTROL_FLAG_NONE, 630 CONTROL_FLAG_NONE,
618 kStandardGetHeaders, 631 kStandardGetHeaders,
619 arraysize(kStandardGetHeaders)); 632 arraysize(kStandardGetHeaders));
620 } 633 }
621 634
622 // Constructs a standard SPDY POST SYN packet. 635 // Constructs a standard SPDY POST SYN frame.
623 // |content_length| is the size of post data. 636 // |content_length| is the size of post data.
624 // |extra_headers| are the extra header-value pairs, which typically 637 // |extra_headers| are the extra header-value pairs, which typically
625 // will vary the most between calls. 638 // will vary the most between calls.
626 // Returns a SpdyFrame. 639 // Returns a SpdyFrame.
627 SpdyFrame* ConstructSpdyPost(int64 content_length, 640 SpdyFrame* ConstructSpdyPost(const char* url,
641 int64 content_length,
628 const char* const extra_headers[], 642 const char* const extra_headers[],
629 int extra_header_count) { 643 int extra_header_count) {
630 std::string length_str = base::Int64ToString(content_length); 644 const SpdyHeaderInfo kSynStartHeader = {
631 const char* post_headers[] = { 645 SYN_STREAM, // Kind = Syn
632 "method", "POST", 646 1, // Stream ID
633 "url", "/", 647 0, // Associated stream ID
634 "host", "www.google.com", 648 ConvertRequestPriorityToSpdyPriority(LOWEST, 2),
635 "scheme", "http", 649 // Priority
636 "version", "HTTP/1.1", 650 CONTROL_FLAG_NONE, // Control Flags
637 "content-length", length_str.c_str() 651 false, // Compressed
652 RST_STREAM_INVALID, // Status
653 NULL, // Data
654 0, // Length
655 DATA_FLAG_NONE // Data Flags
638 }; 656 };
639 return ConstructSpdyControlFrame(extra_headers, 657 return ConstructSpdyFrame(
640 extra_header_count, 658 kSynStartHeader, ConstructPostHeaderBlock(url, content_length));
641 false,
642 1,
643 LOWEST,
644 SYN_STREAM,
645 CONTROL_FLAG_NONE,
646 post_headers,
647 arraysize(post_headers));
648 } 659 }
649 660
650 // Constructs a chunked transfer SPDY POST SYN packet. 661 // Constructs a chunked transfer SPDY POST SYN frame.
651 // |extra_headers| are the extra header-value pairs, which typically 662 // |extra_headers| are the extra header-value pairs, which typically
652 // will vary the most between calls. 663 // will vary the most between calls.
653 // Returns a SpdyFrame. 664 // Returns a SpdyFrame.
654 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], 665 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[],
655 int extra_header_count) { 666 int extra_header_count) {
656 const char* post_headers[] = { 667 const char* post_headers[] = {
657 "method", "POST", 668 "method", "POST",
658 "url", "/", 669 "url", "/",
659 "host", "www.google.com", 670 "host", "www.google.com",
660 "scheme", "http", 671 "scheme", "http",
661 "version", "HTTP/1.1" 672 "version", "HTTP/1.1"
662 }; 673 };
663 return ConstructSpdyControlFrame(extra_headers, 674 return ConstructSpdyControlFrame(extra_headers,
664 extra_header_count, 675 extra_header_count,
665 false, 676 false,
666 1, 677 1,
667 LOWEST, 678 LOWEST,
668 SYN_STREAM, 679 SYN_STREAM,
669 CONTROL_FLAG_NONE, 680 CONTROL_FLAG_NONE,
670 post_headers, 681 post_headers,
671 arraysize(post_headers)); 682 arraysize(post_headers));
672 } 683 }
673 684
674 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. 685 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY POST.
675 // |extra_headers| are the extra header-value pairs, which typically 686 // |extra_headers| are the extra header-value pairs, which typically
676 // will vary the most between calls. 687 // will vary the most between calls.
677 // Returns a SpdyFrame. 688 // Returns a SpdyFrame.
678 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], 689 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[],
679 int extra_header_count) { 690 int extra_header_count) {
680 static const char* const kStandardGetHeaders[] = { 691 static const char* const kStandardGetHeaders[] = {
681 "hello", "bye", 692 "hello", "bye",
682 "status", "200", 693 "status", "200",
683 "url", "/index.php", 694 "url", "/index.php",
684 "version", "HTTP/1.1" 695 "version", "HTTP/1.1"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 730
720 // Construct an expected SPDY reply string. 731 // Construct an expected SPDY reply string.
721 // |extra_headers| are the extra header-value pairs, which typically 732 // |extra_headers| are the extra header-value pairs, which typically
722 // will vary the most between calls. 733 // will vary the most between calls.
723 // |buffer| is the buffer we're filling in. 734 // |buffer| is the buffer we're filling in.
724 // Returns the number of bytes written into |buffer|. 735 // Returns the number of bytes written into |buffer|.
725 int ConstructSpdyReplyString(const char* const extra_headers[], 736 int ConstructSpdyReplyString(const char* const extra_headers[],
726 int extra_header_count, 737 int extra_header_count,
727 char* buffer, 738 char* buffer,
728 int buffer_length) { 739 int buffer_length) {
729 int packet_size = 0; 740 int frame_size = 0;
730 char* buffer_write = buffer; 741 char* buffer_write = buffer;
731 int buffer_left = buffer_length; 742 int buffer_left = buffer_length;
732 SpdyHeaderBlock headers; 743 SpdyHeaderBlock headers;
733 if (!buffer || !buffer_length) 744 if (!buffer || !buffer_length)
734 return 0; 745 return 0;
735 // Copy in the extra headers. 746 // Copy in the extra headers.
736 AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers); 747 AppendToHeaderBlock(extra_headers, extra_header_count, &headers);
737 // The iterator gets us the list of header/value pairs in sorted order. 748 // The iterator gets us the list of header/value pairs in sorted order.
738 SpdyHeaderBlock::iterator next = headers.begin(); 749 SpdyHeaderBlock::iterator next = headers.begin();
739 SpdyHeaderBlock::iterator last = headers.end(); 750 SpdyHeaderBlock::iterator last = headers.end();
740 for ( ; next != last; ++next) { 751 for ( ; next != last; ++next) {
741 // Write the header. 752 // Write the header.
742 int value_len, current_len, offset; 753 int value_len, current_len, offset;
743 const char* header_string = next->first.c_str(); 754 const char* header_string = next->first.c_str();
744 packet_size += AppendToBuffer(header_string, 755 frame_size += AppendToBuffer(header_string,
745 next->first.length(), 756 next->first.length(),
746 &buffer_write, 757 &buffer_write,
747 &buffer_left); 758 &buffer_left);
748 packet_size += AppendToBuffer(": ", 759 frame_size += AppendToBuffer(": ",
749 strlen(": "), 760 strlen(": "),
750 &buffer_write, 761 &buffer_write,
751 &buffer_left); 762 &buffer_left);
752 // Write the value(s). 763 // Write the value(s).
753 const char* value_string = next->second.c_str(); 764 const char* value_string = next->second.c_str();
754 // Check if it's split among two or more values. 765 // Check if it's split among two or more values.
755 value_len = next->second.length(); 766 value_len = next->second.length();
756 current_len = strlen(value_string); 767 current_len = strlen(value_string);
757 offset = 0; 768 offset = 0;
758 // Handle the first N-1 values. 769 // Handle the first N-1 values.
759 while (current_len < value_len) { 770 while (current_len < value_len) {
760 // Finish this line -- write the current value. 771 // Finish this line -- write the current value.
761 packet_size += AppendToBuffer(value_string + offset, 772 frame_size += AppendToBuffer(value_string + offset,
762 current_len - offset, 773 current_len - offset,
763 &buffer_write, 774 &buffer_write,
764 &buffer_left); 775 &buffer_left);
765 packet_size += AppendToBuffer("\n", 776 frame_size += AppendToBuffer("\n",
766 strlen("\n"), 777 strlen("\n"),
767 &buffer_write, 778 &buffer_write,
768 &buffer_left); 779 &buffer_left);
769 // Advance to next value. 780 // Advance to next value.
770 offset = current_len + 1; 781 offset = current_len + 1;
771 current_len += 1 + strlen(value_string + offset); 782 current_len += 1 + strlen(value_string + offset);
772 // Start another line -- add the header again. 783 // Start another line -- add the header again.
773 packet_size += AppendToBuffer(header_string, 784 frame_size += AppendToBuffer(header_string,
774 next->first.length(), 785 next->first.length(),
775 &buffer_write, 786 &buffer_write,
776 &buffer_left); 787 &buffer_left);
777 packet_size += AppendToBuffer(": ", 788 frame_size += AppendToBuffer(": ",
778 strlen(": "), 789 strlen(": "),
779 &buffer_write, 790 &buffer_write,
780 &buffer_left); 791 &buffer_left);
781 } 792 }
782 EXPECT_EQ(value_len, current_len); 793 EXPECT_EQ(value_len, current_len);
783 // Copy the last (or only) value. 794 // Copy the last (or only) value.
784 packet_size += AppendToBuffer(value_string + offset, 795 frame_size += AppendToBuffer(value_string + offset,
785 value_len - offset, 796 value_len - offset,
786 &buffer_write, 797 &buffer_write,
787 &buffer_left); 798 &buffer_left);
788 packet_size += AppendToBuffer("\n", 799 frame_size += AppendToBuffer("\n",
789 strlen("\n"), 800 strlen("\n"),
790 &buffer_write, 801 &buffer_write,
791 &buffer_left); 802 &buffer_left);
792 } 803 }
793 return packet_size; 804 return frame_size;
794 } 805 }
795 806
796 // Create a MockWrite from the given SpdyFrame. 807 // Create a MockWrite from the given SpdyFrame.
797 MockWrite CreateMockWrite(const SpdyFrame& req) { 808 MockWrite CreateMockWrite(const SpdyFrame& req) {
798 return MockWrite(ASYNC, req.data(), req.size()); 809 return MockWrite(ASYNC, req.data(), req.size());
799 } 810 }
800 811
801 // Create a MockWrite from the given SpdyFrame and sequence number. 812 // Create a MockWrite from the given SpdyFrame and sequence number.
802 MockWrite CreateMockWrite(const SpdyFrame& req, int seq) { 813 MockWrite CreateMockWrite(const SpdyFrame& req, int seq) {
803 return CreateMockWrite(req, seq, ASYNC); 814 return CreateMockWrite(req, seq, ASYNC);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 RST_STREAM_INVALID, // Status 984 RST_STREAM_INVALID, // Status
974 NULL, // Data 985 NULL, // Data
975 0, // Length 986 0, // Length
976 DATA_FLAG_NONE // Data Flags 987 DATA_FLAG_NONE // Data Flags
977 }; 988 };
978 return kHeader; 989 return kHeader;
979 } 990 }
980 991
981 } // namespace test_spdy2 992 } // namespace test_spdy2
982 } // namespace net 993 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_test_util_spdy2.h ('k') | net/spdy/spdy_test_util_spdy3.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698