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

Side by Side Diff: net/spdy/spdy_test_util_spdy3.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_spdy3.h ('k') | net/spdy/spdy_websocket_test_util_spdy2.cc » ('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_spdy3.h" 5 #include "net/spdy/spdy_test_util_spdy3.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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // |num_chunks| is the number of chunks to create. 127 // |num_chunks| is the number of chunks to create.
128 MockRead* ChopReadFrame(const SpdyFrame& frame, int num_chunks) { 128 MockRead* ChopReadFrame(const SpdyFrame& frame, int num_chunks) {
129 return ChopReadFrame(frame.data(), frame.size(), num_chunks); 129 return ChopReadFrame(frame.data(), frame.size(), num_chunks);
130 } 130 }
131 131
132 // Adds headers and values to a map. 132 // Adds headers and values to a map.
133 // |extra_headers| is an array of { name, value } pairs, arranged as strings 133 // |extra_headers| is an array of { name, value } pairs, arranged as strings
134 // where the even entries are the header names, and the odd entries are the 134 // where the even entries are the header names, and the odd entries are the
135 // header values. 135 // header values.
136 // |headers| gets filled in from |extra_headers|. 136 // |headers| gets filled in from |extra_headers|.
137 void AppendHeadersToSpdyFrame(const char* const extra_headers[], 137 void AppendToHeaderBlock(const char* const extra_headers[],
138 int extra_header_count, 138 int extra_header_count,
139 SpdyHeaderBlock* headers) { 139 SpdyHeaderBlock* headers) {
140 std::string this_header; 140 std::string this_header;
141 std::string this_value; 141 std::string this_value;
142 142
143 if (!extra_header_count) 143 if (!extra_header_count)
144 return; 144 return;
145 145
146 // Sanity check: Non-NULL header list. 146 // Sanity check: Non-NULL header list.
147 DCHECK(NULL != extra_headers) << "NULL header value pair list"; 147 DCHECK(NULL != extra_headers) << "NULL header value pair list";
148 // Sanity check: Non-NULL header map. 148 // Sanity check: Non-NULL header map.
149 DCHECK(NULL != headers) << "NULL header map"; 149 DCHECK(NULL != headers) << "NULL header map";
(...skipping 19 matching lines...) Expand all
169 // Append the new value. 169 // Append the new value.
170 new_value += this_value; 170 new_value += this_value;
171 } else { 171 } else {
172 // Not a duplicate, just write the value. 172 // Not a duplicate, just write the value.
173 new_value = this_value; 173 new_value = this_value;
174 } 174 }
175 (*headers)[this_header] = new_value; 175 (*headers)[this_header] = new_value;
176 } 176 }
177 } 177 }
178 178
179 scoped_ptr<SpdyHeaderBlock> ConstructGetHeaderBlock(base::StringPiece url) {
180 std::string scheme, host, path;
181 ParseUrl(url.data(), &scheme, &host, &path);
182 const char* const headers[] = {
183 ":method", "GET",
184 ":path", path.c_str(),
185 ":host", host.c_str(),
186 ":scheme", scheme.c_str(),
187 ":version", "HTTP/1.1"
188 };
189 scoped_ptr<SpdyHeaderBlock> header_block(new SpdyHeaderBlock());
190 AppendToHeaderBlock(headers, arraysize(headers) / 2, header_block.get());
191 return header_block.Pass();
192 }
193
194 scoped_ptr<SpdyHeaderBlock> ConstructPostHeaderBlock(base::StringPiece url,
195 int64 content_length) {
196 std::string scheme, host, path;
197 ParseUrl(url.data(), &scheme, &host, &path);
198 std::string length_str = base::Int64ToString(content_length);
199 const char* const headers[] = {
200 ":method", "POST",
201 ":path", path.c_str(),
202 ":host", host.c_str(),
203 ":scheme", scheme.c_str(),
204 ":version", "HTTP/1.1",
205 "content-length", length_str.c_str()
206 };
207 scoped_ptr<SpdyHeaderBlock> header_block(new SpdyHeaderBlock());
208 AppendToHeaderBlock(headers, arraysize(headers) / 2, header_block.get());
209 return header_block.Pass();
210 }
211
179 // Writes |val| to a location of size |len|, in big-endian format. 212 // Writes |val| to a location of size |len|, in big-endian format.
180 // in the buffer pointed to by |buffer_handle|. 213 // in the buffer pointed to by |buffer_handle|.
181 // Updates the |*buffer_handle| pointer by |len| 214 // Updates the |*buffer_handle| pointer by |len|
182 // Returns the number of bytes written 215 // Returns the number of bytes written
183 int AppendToBuffer(int val, 216 int AppendToBuffer(int val,
184 int len, 217 int len,
185 unsigned char** buffer_handle, 218 unsigned char** buffer_handle,
186 int* buffer_len_remaining) { 219 int* buffer_len_remaining) {
187 if (len <= 0) 220 if (len <= 0)
188 return 0; 221 return 0;
189 DCHECK((size_t) len <= sizeof(len)) << "Data length too long for data type"; 222 DCHECK((size_t) len <= sizeof(len)) << "Data length too long for data type";
190 DCHECK(NULL != buffer_handle) << "NULL buffer handle"; 223 DCHECK(NULL != buffer_handle) << "NULL buffer handle";
191 DCHECK(NULL != *buffer_handle) << "NULL pointer"; 224 DCHECK(NULL != *buffer_handle) << "NULL pointer";
192 DCHECK(NULL != buffer_len_remaining) 225 DCHECK(NULL != buffer_len_remaining)
193 << "NULL buffer remainder length pointer"; 226 << "NULL buffer remainder length pointer";
194 DCHECK_GE(*buffer_len_remaining, len) << "Insufficient buffer size"; 227 DCHECK_GE(*buffer_len_remaining, len) << "Insufficient buffer size";
195 for (int i = 0; i < len; i++) { 228 for (int i = 0; i < len; i++) {
196 int shift = (8 * (len - (i + 1))); 229 int shift = (8 * (len - (i + 1)));
197 unsigned char val_chunk = (val >> shift) & 0x0FF; 230 unsigned char val_chunk = (val >> shift) & 0x0FF;
198 *(*buffer_handle)++ = val_chunk; 231 *(*buffer_handle)++ = val_chunk;
199 *buffer_len_remaining += 1; 232 *buffer_len_remaining += 1;
200 } 233 }
201 return len; 234 return len;
202 } 235 }
203 236
204 // Construct a SPDY packet. 237 SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info,
205 // |head| is the start of the packet, up to but not including 238 scoped_ptr<SpdyHeaderBlock> headers) {
206 // the header value pairs. 239 BufferedSpdyFramer framer(kSpdyVersion3, header_info.compressed);
207 // |extra_headers| are the extra header-value pairs, which typically
208 // will vary the most between calls.
209 // |tail| is any (relatively constant) header-value pairs to add.
210 // |buffer| is the buffer we're filling in.
211 // Returns a SpdyFrame.
212 SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info,
213 const char* const extra_headers[],
214 int extra_header_count,
215 const char* const tail[],
216 int tail_header_count) {
217 BufferedSpdyFramer framer(3, header_info.compressed);
218 SpdyHeaderBlock headers;
219 // Copy in the extra headers to our map.
220 AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers);
221 // Copy in the tail headers to our map.
222 if (tail && tail_header_count)
223 AppendHeadersToSpdyFrame(tail, tail_header_count, &headers);
224 SpdyFrame* frame = NULL; 240 SpdyFrame* frame = NULL;
225 switch (header_info.kind) { 241 switch (header_info.kind) {
226 case SYN_STREAM: 242 case SYN_STREAM:
227 frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, 243 frame = framer.CreateSynStream(header_info.id, header_info.assoc_id,
228 header_info.priority, 244 header_info.priority,
229 header_info.credential_slot, 245 header_info.credential_slot,
230 header_info.control_flags, 246 header_info.control_flags,
231 header_info.compressed, &headers); 247 header_info.compressed, headers.get());
232 break; 248 break;
233 case SYN_REPLY: 249 case SYN_REPLY:
234 frame = framer.CreateSynReply(header_info.id, header_info.control_flags, 250 frame = framer.CreateSynReply(header_info.id, header_info.control_flags,
235 header_info.compressed, &headers); 251 header_info.compressed, headers.get());
236 break; 252 break;
237 case RST_STREAM: 253 case RST_STREAM:
238 frame = framer.CreateRstStream(header_info.id, header_info.status); 254 frame = framer.CreateRstStream(header_info.id, header_info.status);
239 break; 255 break;
240 case HEADERS: 256 case HEADERS:
241 frame = framer.CreateHeaders(header_info.id, header_info.control_flags, 257 frame = framer.CreateHeaders(header_info.id, header_info.control_flags,
242 header_info.compressed, &headers); 258 header_info.compressed, headers.get());
243 break; 259 break;
244 default: 260 default:
245 frame = framer.CreateDataFrame(header_info.id, header_info.data, 261 frame = framer.CreateDataFrame(header_info.id, header_info.data,
246 header_info.data_length, 262 header_info.data_length,
247 header_info.data_flags); 263 header_info.data_flags);
248 break; 264 break;
249 } 265 }
250 return frame; 266 return frame;
251 } 267 }
252 268
269 SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info,
270 const char* const extra_headers[],
271 int extra_header_count,
272 const char* const tail[],
273 int tail_header_count) {
274 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock());
275 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get());
276 if (tail && tail_header_count)
277 AppendToHeaderBlock(tail, tail_header_count, headers.get());
278 return ConstructSpdyFrame(header_info, headers.Pass());
279 }
280
253 // Construct an expected SPDY SETTINGS frame. 281 // Construct an expected SPDY SETTINGS frame.
254 // |settings| are the settings to set. 282 // |settings| are the settings to set.
255 // Returns the constructed frame. The caller takes ownership of the frame. 283 // Returns the constructed frame. The caller takes ownership of the frame.
256 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) { 284 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) {
257 BufferedSpdyFramer framer(3, false); 285 BufferedSpdyFramer framer(3, false);
258 return framer.CreateSettings(settings); 286 return framer.CreateSettings(settings);
259 } 287 }
260 288
261 // Construct an expected SPDY CREDENTIAL frame. 289 // Construct an expected SPDY CREDENTIAL frame.
262 // |credential| is the credential to sen. 290 // |credential| is the credential to sen.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 ConvertRequestPriorityToSpdyPriority(request_priority, 3), 403 ConvertRequestPriorityToSpdyPriority(request_priority, 3),
376 // Priority 404 // Priority
377 0, // Credential Slot 405 0, // Credential Slot
378 flags, // Control Flags 406 flags, // Control Flags
379 compressed, // Compressed 407 compressed, // Compressed
380 RST_STREAM_INVALID, // Status 408 RST_STREAM_INVALID, // Status
381 NULL, // Data 409 NULL, // Data
382 0, // Length 410 0, // Length
383 DATA_FLAG_NONE // Data Flags 411 DATA_FLAG_NONE // Data Flags
384 }; 412 };
385 return ConstructSpdyPacket(kSynStartHeader, 413 return ConstructSpdyFrame(kSynStartHeader,
386 extra_headers, 414 extra_headers,
387 extra_header_count, 415 extra_header_count,
388 kHeaders, 416 kHeaders,
389 kHeadersSize / 2); 417 kHeadersSize / 2);
390 } 418 }
391 419
392 // Constructs a standard SPDY GET SYN packet, optionally compressed 420 // Constructs a standard SPDY GET SYN frame, optionally compressed
393 // for the url |url|. 421 // for the url |url|.
394 // |extra_headers| are the extra header-value pairs, which typically 422 // |extra_headers| are the extra header-value pairs, which typically
395 // will vary the most between calls. 423 // will vary the most between calls.
396 // Returns a SpdyFrame. 424 // Returns a SpdyFrame.
397 SpdyFrame* ConstructSpdyGet(const char* const url, 425 SpdyFrame* ConstructSpdyGet(const char* const url,
398 bool compressed, 426 bool compressed,
399 SpdyStreamId stream_id, 427 SpdyStreamId stream_id,
400 RequestPriority request_priority) { 428 RequestPriority request_priority) {
401 const SpdyHeaderInfo kSynStartHeader = { 429 const SpdyHeaderInfo kSynStartHeader = {
402 SYN_STREAM, // Kind = Syn 430 SYN_STREAM, // Kind = Syn
403 stream_id, // Stream ID 431 stream_id, // Stream ID
404 0, // Associated stream ID 432 0, // Associated stream ID
405 ConvertRequestPriorityToSpdyPriority(request_priority, 3), 433 ConvertRequestPriorityToSpdyPriority(request_priority, 3),
406 // Priority 434 // Priority
407 0, // Credential Slot 435 0, // Credential Slot
408 CONTROL_FLAG_FIN, // Control Flags 436 CONTROL_FLAG_FIN, // Control Flags
409 compressed, // Compressed 437 compressed, // Compressed
410 RST_STREAM_INVALID, // Status 438 RST_STREAM_INVALID, // Status
411 NULL, // Data 439 NULL, // Data
412 0, // Length 440 0, // Length
413 DATA_FLAG_NONE // Data Flags 441 DATA_FLAG_NONE // Data Flags
414 }; 442 };
415 443 return ConstructSpdyFrame(kSynStartHeader, ConstructGetHeaderBlock(url));
416 std::string scheme, host, path;
417 ParseUrl(url, &scheme, &host, &path);
418 const char* const headers[] = {
419 ":method", "GET",
420 ":path", path.c_str(),
421 ":host", host.c_str(),
422 ":scheme", scheme.c_str(),
423 ":version", "HTTP/1.1"
424 };
425 return ConstructSpdyPacket(
426 kSynStartHeader,
427 NULL,
428 0,
429 headers,
430 arraysize(headers) / 2);
431 } 444 }
432 445
433 // Constructs a standard SPDY GET SYN packet, optionally compressed. 446 // Constructs a standard SPDY GET SYN frame, optionally compressed.
434 // |extra_headers| are the extra header-value pairs, which typically 447 // |extra_headers| are the extra header-value pairs, which typically
435 // will vary the most between calls. 448 // will vary the most between calls.
436 // Returns a SpdyFrame. 449 // Returns a SpdyFrame.
437 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], 450 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[],
438 int extra_header_count, 451 int extra_header_count,
439 bool compressed, 452 bool compressed,
440 int stream_id, 453 int stream_id,
441 RequestPriority request_priority) { 454 RequestPriority request_priority) {
442 return ConstructSpdyGet(extra_headers, extra_header_count, compressed, 455 return ConstructSpdyGet(extra_headers, extra_header_count, compressed,
443 stream_id, request_priority, true); 456 stream_id, request_priority, true);
444 } 457 }
445 458
446 // Constructs a standard SPDY GET SYN packet, optionally compressed. 459 // Constructs a standard SPDY GET SYN frame, optionally compressed.
447 // |extra_headers| are the extra header-value pairs, which typically 460 // |extra_headers| are the extra header-value pairs, which typically
448 // will vary the most between calls. 461 // will vary the most between calls.
449 // Returns a SpdyFrame. 462 // Returns a SpdyFrame.
450 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], 463 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[],
451 int extra_header_count, 464 int extra_header_count,
452 bool compressed, 465 bool compressed,
453 int stream_id, 466 int stream_id,
454 RequestPriority request_priority, 467 RequestPriority request_priority,
455 bool direct) { 468 bool direct) {
456 const char* const kStandardGetHeaders[] = { 469 const char* const kStandardGetHeaders[] = {
(...skipping 28 matching lines...) Expand all
485 extra_header_count, 498 extra_header_count,
486 /*compressed*/ false, 499 /*compressed*/ false,
487 stream_id, 500 stream_id,
488 LOWEST, 501 LOWEST,
489 SYN_STREAM, 502 SYN_STREAM,
490 CONTROL_FLAG_NONE, 503 CONTROL_FLAG_NONE,
491 kConnectHeaders, 504 kConnectHeaders,
492 arraysize(kConnectHeaders)); 505 arraysize(kConnectHeaders));
493 } 506 }
494 507
495 // Constructs a standard SPDY push SYN packet. 508 // Constructs a standard SPDY push SYN frame.
496 // |extra_headers| are the extra header-value pairs, which typically 509 // |extra_headers| are the extra header-value pairs, which typically
497 // will vary the most between calls. 510 // will vary the most between calls.
498 // Returns a SpdyFrame. 511 // Returns a SpdyFrame.
499 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], 512 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[],
500 int extra_header_count, 513 int extra_header_count,
501 int stream_id, 514 int stream_id,
502 int associated_stream_id) { 515 int associated_stream_id) {
503 const char* const kStandardPushHeaders[] = { 516 const char* const kStandardPushHeaders[] = {
504 "hello", "bye", 517 "hello", "bye",
505 ":status", "200", 518 ":status", "200",
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 extra_header_count, 598 extra_header_count,
586 false, 599 false,
587 stream_id, 600 stream_id,
588 LOWEST, 601 LOWEST,
589 HEADERS, 602 HEADERS,
590 CONTROL_FLAG_NONE, 603 CONTROL_FLAG_NONE,
591 kStandardGetHeaders, 604 kStandardGetHeaders,
592 arraysize(kStandardGetHeaders)); 605 arraysize(kStandardGetHeaders));
593 } 606 }
594 607
595 // Constructs a standard SPDY SYN_REPLY packet with the specified status code. 608 // Constructs a standard SPDY SYN_REPLY frame with the specified status code.
596 // Returns a SpdyFrame. 609 // Returns a SpdyFrame.
597 SpdyFrame* ConstructSpdySynReplyError(const char* const status, 610 SpdyFrame* ConstructSpdySynReplyError(const char* const status,
598 const char* const* const extra_headers, 611 const char* const* const extra_headers,
599 int extra_header_count, 612 int extra_header_count,
600 int stream_id) { 613 int stream_id) {
601 const char* const kStandardGetHeaders[] = { 614 const char* const kStandardGetHeaders[] = {
602 "hello", "bye", 615 "hello", "bye",
603 ":status", status, 616 ":status", status,
604 ":version", "HTTP/1.1" 617 ":version", "HTTP/1.1"
605 }; 618 };
606 return ConstructSpdyControlFrame(extra_headers, 619 return ConstructSpdyControlFrame(extra_headers,
607 extra_header_count, 620 extra_header_count,
608 false, 621 false,
609 stream_id, 622 stream_id,
610 LOWEST, 623 LOWEST,
611 SYN_REPLY, 624 SYN_REPLY,
612 CONTROL_FLAG_NONE, 625 CONTROL_FLAG_NONE,
613 kStandardGetHeaders, 626 kStandardGetHeaders,
614 arraysize(kStandardGetHeaders)); 627 arraysize(kStandardGetHeaders));
615 } 628 }
616 629
617 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. 630 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET.
618 // |extra_headers| are the extra header-value pairs, which typically 631 // |extra_headers| are the extra header-value pairs, which typically
619 // will vary the most between calls. 632 // will vary the most between calls.
620 // Returns a SpdyFrame. 633 // Returns a SpdyFrame.
621 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) { 634 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) {
622 static const char* const kExtraHeaders[] = { 635 static const char* const kExtraHeaders[] = {
623 "location", "http://www.foo.com/index.php", 636 "location", "http://www.foo.com/index.php",
624 }; 637 };
625 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, 638 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders,
626 arraysize(kExtraHeaders)/2, stream_id); 639 arraysize(kExtraHeaders)/2, stream_id);
627 } 640 }
628 641
629 // Constructs a standard SPDY SYN_REPLY packet with an Internal Server 642 // Constructs a standard SPDY SYN_REPLY frame with an Internal Server
630 // Error status code. 643 // Error status code.
631 // Returns a SpdyFrame. 644 // Returns a SpdyFrame.
632 SpdyFrame* ConstructSpdySynReplyError(int stream_id) { 645 SpdyFrame* ConstructSpdySynReplyError(int stream_id) {
633 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); 646 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1);
634 } 647 }
635 648
636 649
637 650
638 651
639 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. 652 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET.
640 // |extra_headers| are the extra header-value pairs, which typically 653 // |extra_headers| are the extra header-value pairs, which typically
641 // will vary the most between calls. 654 // will vary the most between calls.
642 // Returns a SpdyFrame. 655 // Returns a SpdyFrame.
643 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], 656 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[],
644 int extra_header_count, 657 int extra_header_count,
645 int stream_id) { 658 int stream_id) {
646 static const char* const kStandardGetHeaders[] = { 659 static const char* const kStandardGetHeaders[] = {
647 "hello", "bye", 660 "hello", "bye",
648 ":status", "200", 661 ":status", "200",
649 ":version", "HTTP/1.1" 662 ":version", "HTTP/1.1"
650 }; 663 };
651 return ConstructSpdyControlFrame(extra_headers, 664 return ConstructSpdyControlFrame(extra_headers,
652 extra_header_count, 665 extra_header_count,
653 false, 666 false,
654 stream_id, 667 stream_id,
655 LOWEST, 668 LOWEST,
656 SYN_REPLY, 669 SYN_REPLY,
657 CONTROL_FLAG_NONE, 670 CONTROL_FLAG_NONE,
658 kStandardGetHeaders, 671 kStandardGetHeaders,
659 arraysize(kStandardGetHeaders)); 672 arraysize(kStandardGetHeaders));
660 } 673 }
661 674
662 // Constructs a standard SPDY POST SYN packet. 675 // Constructs a standard SPDY POST SYN frame.
663 // |content_length| is the size of post data. 676 // |content_length| is the size of post data.
664 // |extra_headers| are the extra header-value pairs, which typically 677 // |extra_headers| are the extra header-value pairs, which typically
665 // will vary the most between calls. 678 // will vary the most between calls.
666 // Returns a SpdyFrame. 679 // Returns a SpdyFrame.
667 SpdyFrame* ConstructSpdyPost(int64 content_length, 680 SpdyFrame* ConstructSpdyPost(const char* url,
681 SpdyStreamId stream_id,
682 int64 content_length,
683 RequestPriority priority,
668 const char* const extra_headers[], 684 const char* const extra_headers[],
669 int extra_header_count) { 685 int extra_header_count) {
670 std::string length_str = base::Int64ToString(content_length); 686 const SpdyHeaderInfo kSynStartHeader = {
671 const char* post_headers[] = { 687 SYN_STREAM, // Kind = Syn
672 ":method", "POST", 688 stream_id, // Stream ID
673 ":path", "/", 689 0, // Associated stream ID
674 ":host", "www.google.com", 690 ConvertRequestPriorityToSpdyPriority(priority, kSpdyVersion3),
675 ":scheme", "http", 691 // Priority
676 ":version", "HTTP/1.1", 692 0, // Credential Slot
677 "content-length", length_str.c_str() 693 CONTROL_FLAG_NONE, // Control Flags
694 false, // Compressed
695 RST_STREAM_INVALID, // Status
696 NULL, // Data
697 0, // Length
698 DATA_FLAG_NONE // Data Flags
678 }; 699 };
679 return ConstructSpdyControlFrame(extra_headers, 700 return ConstructSpdyFrame(
680 extra_header_count, 701 kSynStartHeader, ConstructPostHeaderBlock(url, content_length));
681 false,
682 1,
683 LOWEST,
684 SYN_STREAM,
685 CONTROL_FLAG_NONE,
686 post_headers,
687 arraysize(post_headers));
688 } 702 }
689 703
690 // Constructs a chunked transfer SPDY POST SYN packet. 704 // Constructs a chunked transfer SPDY POST SYN frame.
691 // |extra_headers| are the extra header-value pairs, which typically 705 // |extra_headers| are the extra header-value pairs, which typically
692 // will vary the most between calls. 706 // will vary the most between calls.
693 // Returns a SpdyFrame. 707 // Returns a SpdyFrame.
694 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], 708 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[],
695 int extra_header_count) { 709 int extra_header_count) {
696 const char* post_headers[] = { 710 const char* post_headers[] = {
697 ":method", "POST", 711 ":method", "POST",
698 ":path", "/", 712 ":path", "/",
699 ":host", "www.google.com", 713 ":host", "www.google.com",
700 ":scheme", "http", 714 ":scheme", "http",
701 ":version", "HTTP/1.1" 715 ":version", "HTTP/1.1"
702 }; 716 };
703 return ConstructSpdyControlFrame(extra_headers, 717 return ConstructSpdyControlFrame(extra_headers,
704 extra_header_count, 718 extra_header_count,
705 false, 719 false,
706 1, 720 1,
707 LOWEST, 721 LOWEST,
708 SYN_STREAM, 722 SYN_STREAM,
709 CONTROL_FLAG_NONE, 723 CONTROL_FLAG_NONE,
710 post_headers, 724 post_headers,
711 arraysize(post_headers)); 725 arraysize(post_headers));
712 } 726 }
713 727
714 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. 728 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY POST.
715 // |extra_headers| are the extra header-value pairs, which typically 729 // |extra_headers| are the extra header-value pairs, which typically
716 // will vary the most between calls. 730 // will vary the most between calls.
717 // Returns a SpdyFrame. 731 // Returns a SpdyFrame.
718 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], 732 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[],
719 int extra_header_count) { 733 int extra_header_count) {
720 static const char* const kStandardGetHeaders[] = { 734 static const char* const kStandardGetHeaders[] = {
721 "hello", "bye", 735 "hello", "bye",
722 ":status", "200", 736 ":status", "200",
723 "url", "/index.php", 737 "url", "/index.php",
724 ":version", "HTTP/1.1" 738 ":version", "HTTP/1.1"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 774
761 // Construct an expected SPDY reply string. 775 // Construct an expected SPDY reply string.
762 // |extra_headers| are the extra header-value pairs, which typically 776 // |extra_headers| are the extra header-value pairs, which typically
763 // will vary the most between calls. 777 // will vary the most between calls.
764 // |buffer| is the buffer we're filling in. 778 // |buffer| is the buffer we're filling in.
765 // Returns the number of bytes written into |buffer|. 779 // Returns the number of bytes written into |buffer|.
766 int ConstructSpdyReplyString(const char* const extra_headers[], 780 int ConstructSpdyReplyString(const char* const extra_headers[],
767 int extra_header_count, 781 int extra_header_count,
768 char* buffer, 782 char* buffer,
769 int buffer_length) { 783 int buffer_length) {
770 int packet_size = 0; 784 int frame_size = 0;
771 char* buffer_write = buffer; 785 char* buffer_write = buffer;
772 int buffer_left = buffer_length; 786 int buffer_left = buffer_length;
773 SpdyHeaderBlock headers; 787 SpdyHeaderBlock headers;
774 if (!buffer || !buffer_length) 788 if (!buffer || !buffer_length)
775 return 0; 789 return 0;
776 // Copy in the extra headers. 790 // Copy in the extra headers.
777 AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers); 791 AppendToHeaderBlock(extra_headers, extra_header_count, &headers);
778 // The iterator gets us the list of header/value pairs in sorted order. 792 // The iterator gets us the list of header/value pairs in sorted order.
779 SpdyHeaderBlock::iterator next = headers.begin(); 793 SpdyHeaderBlock::iterator next = headers.begin();
780 SpdyHeaderBlock::iterator last = headers.end(); 794 SpdyHeaderBlock::iterator last = headers.end();
781 for ( ; next != last; ++next) { 795 for ( ; next != last; ++next) {
782 // Write the header. 796 // Write the header.
783 int value_len, current_len, offset; 797 int value_len, current_len, offset;
784 const char* header_string = next->first.c_str(); 798 const char* header_string = next->first.c_str();
785 if (header_string && header_string[0] == ':') 799 if (header_string && header_string[0] == ':')
786 header_string++; 800 header_string++;
787 packet_size += AppendToBuffer(header_string, 801 frame_size += AppendToBuffer(header_string,
788 strlen(header_string), 802 strlen(header_string),
789 &buffer_write, 803 &buffer_write,
790 &buffer_left); 804 &buffer_left);
791 packet_size += AppendToBuffer(": ", 805 frame_size += AppendToBuffer(": ",
792 strlen(": "), 806 strlen(": "),
793 &buffer_write, 807 &buffer_write,
794 &buffer_left); 808 &buffer_left);
795 // Write the value(s). 809 // Write the value(s).
796 const char* value_string = next->second.c_str(); 810 const char* value_string = next->second.c_str();
797 // Check if it's split among two or more values. 811 // Check if it's split among two or more values.
798 value_len = next->second.length(); 812 value_len = next->second.length();
799 current_len = strlen(value_string); 813 current_len = strlen(value_string);
800 offset = 0; 814 offset = 0;
801 // Handle the first N-1 values. 815 // Handle the first N-1 values.
802 while (current_len < value_len) { 816 while (current_len < value_len) {
803 // Finish this line -- write the current value. 817 // Finish this line -- write the current value.
804 packet_size += AppendToBuffer(value_string + offset, 818 frame_size += AppendToBuffer(value_string + offset,
805 current_len - offset, 819 current_len - offset,
806 &buffer_write, 820 &buffer_write,
807 &buffer_left); 821 &buffer_left);
808 packet_size += AppendToBuffer("\n", 822 frame_size += AppendToBuffer("\n",
809 strlen("\n"), 823 strlen("\n"),
810 &buffer_write, 824 &buffer_write,
811 &buffer_left); 825 &buffer_left);
812 // Advance to next value. 826 // Advance to next value.
813 offset = current_len + 1; 827 offset = current_len + 1;
814 current_len += 1 + strlen(value_string + offset); 828 current_len += 1 + strlen(value_string + offset);
815 // Start another line -- add the header again. 829 // Start another line -- add the header again.
816 packet_size += AppendToBuffer(header_string, 830 frame_size += AppendToBuffer(header_string,
817 next->first.length(), 831 next->first.length(),
818 &buffer_write, 832 &buffer_write,
819 &buffer_left); 833 &buffer_left);
820 packet_size += AppendToBuffer(": ", 834 frame_size += AppendToBuffer(": ",
821 strlen(": "), 835 strlen(": "),
822 &buffer_write, 836 &buffer_write,
823 &buffer_left); 837 &buffer_left);
824 } 838 }
825 EXPECT_EQ(value_len, current_len); 839 EXPECT_EQ(value_len, current_len);
826 // Copy the last (or only) value. 840 // Copy the last (or only) value.
827 packet_size += AppendToBuffer(value_string + offset, 841 frame_size += AppendToBuffer(value_string + offset,
828 value_len - offset, 842 value_len - offset,
829 &buffer_write, 843 &buffer_write,
830 &buffer_left); 844 &buffer_left);
831 packet_size += AppendToBuffer("\n", 845 frame_size += AppendToBuffer("\n",
832 strlen("\n"), 846 strlen("\n"),
833 &buffer_write, 847 &buffer_write,
834 &buffer_left); 848 &buffer_left);
835 } 849 }
836 return packet_size; 850 return frame_size;
837 } 851 }
838 852
839 // Create a MockWrite from the given SpdyFrame. 853 // Create a MockWrite from the given SpdyFrame.
840 MockWrite CreateMockWrite(const SpdyFrame& req) { 854 MockWrite CreateMockWrite(const SpdyFrame& req) {
841 return MockWrite(ASYNC, req.data(), req.size()); 855 return MockWrite(ASYNC, req.data(), req.size());
842 } 856 }
843 857
844 // Create a MockWrite from the given SpdyFrame and sequence number. 858 // Create a MockWrite from the given SpdyFrame and sequence number.
845 MockWrite CreateMockWrite(const SpdyFrame& req, int seq) { 859 MockWrite CreateMockWrite(const SpdyFrame& req, int seq) {
846 return CreateMockWrite(req, seq, ASYNC); 860 return CreateMockWrite(req, seq, ASYNC);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 NULL, // Data 1038 NULL, // Data
1025 0, // Length 1039 0, // Length
1026 DATA_FLAG_NONE // Data Flags 1040 DATA_FLAG_NONE // Data Flags
1027 }; 1041 };
1028 return kHeader; 1042 return kHeader;
1029 } 1043 }
1030 1044
1031 } // namespace test_spdy3 1045 } // namespace test_spdy3
1032 1046
1033 } // namespace net 1047 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_test_util_spdy3.h ('k') | net/spdy/spdy_websocket_test_util_spdy2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698