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

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

Issue 3020032: Implement server push protocol 2. (Closed)
Patch Set: nits. Created 10 years, 4 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
« no previous file with comments | « net/spdy/spdy_test_util.h ('k') | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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.h" 5 #include "net/spdy/spdy_test_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (!*this_value) 244 if (!*this_value)
245 this_value = ""; 245 this_value = "";
246 int n = base::snprintf(buffer, 246 int n = base::snprintf(buffer,
247 buffer_length, 247 buffer_length,
248 "%s: %s\r\n", 248 "%s: %s\r\n",
249 this_header, 249 this_header,
250 this_value); 250 this_value);
251 return n; 251 return n;
252 } 252 }
253 253
254 spdy::SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[],
255 int extra_header_count,
256 bool compressed,
257 int stream_id,
258 RequestPriority request_priority,
259 spdy::SpdyControlType type,
260 spdy::SpdyControlFlags flags,
261 const char* const* kHeaders,
262 int kHeadersSize) {
263 return ConstructSpdyControlFrame(extra_headers,
264 extra_header_count,
265 compressed,
266 stream_id,
267 request_priority,
268 type,
269 flags,
270 kHeaders,
271 kHeadersSize,
272 0);
273 }
274
275 spdy::SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[],
276 int extra_header_count,
277 bool compressed,
278 int stream_id,
279 RequestPriority request_priority,
280 spdy::SpdyControlType type,
281 spdy::SpdyControlFlags flags,
282 const char* const* kHeaders,
283 int kHeadersSize,
284 int associated_stream_id) {
285 const SpdyHeaderInfo kSynStartHeader = {
286 type, // Kind = Syn
287 stream_id, // Stream ID
288 associated_stream_id, // Associated stream ID
289 net::ConvertRequestPriorityToSpdyPriority(request_priority),
290 // Priority
291 flags, // Control Flags
292 compressed, // Compressed
293 spdy::INVALID, // Status
294 NULL, // Data
295 0, // Length
296 spdy::DATA_FLAG_NONE // Data Flags
297 };
298 return ConstructSpdyPacket(kSynStartHeader,
299 extra_headers,
300 extra_header_count,
301 kHeaders,
302 kHeadersSize / 2);
303 }
304
254 // Constructs a standard SPDY GET SYN packet, optionally compressed 305 // Constructs a standard SPDY GET SYN packet, optionally compressed
255 // for the url |url|. 306 // for the url |url|.
256 // |extra_headers| are the extra header-value pairs, which typically 307 // |extra_headers| are the extra header-value pairs, which typically
257 // will vary the most between calls. 308 // will vary the most between calls.
258 // Returns a SpdyFrame. 309 // Returns a SpdyFrame.
259 spdy::SpdyFrame* ConstructSpdyGet(const char* const url, 310 spdy::SpdyFrame* ConstructSpdyGet(const char* const url,
260 bool compressed, 311 bool compressed,
261 int stream_id, 312 int stream_id,
262 RequestPriority request_priority) { 313 RequestPriority request_priority) {
263 const SpdyHeaderInfo kSynStartHeader = { 314 const SpdyHeaderInfo kSynStartHeader = {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 363
313 // Constructs a standard SPDY GET SYN packet, optionally compressed. 364 // Constructs a standard SPDY GET SYN packet, optionally compressed.
314 // |extra_headers| are the extra header-value pairs, which typically 365 // |extra_headers| are the extra header-value pairs, which typically
315 // will vary the most between calls. 366 // will vary the most between calls.
316 // Returns a SpdyFrame. 367 // Returns a SpdyFrame.
317 spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], 368 spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[],
318 int extra_header_count, 369 int extra_header_count,
319 bool compressed, 370 bool compressed,
320 int stream_id, 371 int stream_id,
321 RequestPriority request_priority) { 372 RequestPriority request_priority) {
322 const SpdyHeaderInfo kSynStartHeader = {
323 spdy::SYN_STREAM, // Kind = Syn
324 stream_id, // Stream ID
325 0, // Associated stream ID
326 net::ConvertRequestPriorityToSpdyPriority(request_priority),
327 // Priority
328 spdy::CONTROL_FLAG_FIN, // Control Flags
329 compressed, // Compressed
330 spdy::INVALID, // Status
331 NULL, // Data
332 0, // Length
333 spdy::DATA_FLAG_NONE // Data Flags
334 };
335 static const char* const kStandardGetHeaders[] = { 373 static const char* const kStandardGetHeaders[] = {
336 "method", 374 "method",
337 "GET", 375 "GET",
338 "url", 376 "url",
339 "/", 377 "/",
340 "host", 378 "host",
341 "www.google.com", 379 "www.google.com",
342 "scheme", 380 "scheme",
343 "http", 381 "http",
344 "version", 382 "version",
345 "HTTP/1.1" 383 "HTTP/1.1"
346 }; 384 };
347 return ConstructSpdyPacket( 385 return ConstructSpdyControlFrame(extra_headers,
348 kSynStartHeader, 386 extra_header_count,
349 extra_headers, 387 compressed,
350 extra_header_count, 388 stream_id,
351 kStandardGetHeaders, 389 request_priority,
352 arraysize(kStandardGetHeaders) / 2); 390 spdy::SYN_STREAM,
391 spdy::CONTROL_FLAG_FIN,
392 kStandardGetHeaders,
393 arraysize(kStandardGetHeaders));
394 }
395
396 // Constructs a standard SPDY push SYN packet.
397 // |extra_headers| are the extra header-value pairs, which typically
398 // will vary the most between calls.
399 // Returns a SpdyFrame.
400 spdy::SpdyFrame* ConstructSpdyPush(const char* const extra_headers[],
401 int extra_header_count,
402 int stream_id,
403 int associated_stream_id) {
404 const char* const kStandardGetHeaders[] = {
405 "hello",
406 "bye",
407 "status",
408 "200",
409 "version",
410 "HTTP/1.1"
411 };
412 return ConstructSpdyControlFrame(extra_headers,
413 extra_header_count,
414 false,
415 stream_id,
416 LOWEST,
417 spdy::SYN_STREAM,
418 spdy::CONTROL_FLAG_NONE,
419 kStandardGetHeaders,
420 arraysize(kStandardGetHeaders),
421 associated_stream_id);
422 }
423
424 spdy::SpdyFrame* ConstructSpdyPush(const char* const extra_headers[],
425 int extra_header_count,
426 int stream_id,
427 int associated_stream_id,
428 const char* path) {
429 const char* const kStandardGetHeaders[] = {
430 "hello",
431 "bye",
432 "path",
433 path,
434 "status",
435 "200 OK",
436 "url",
437 path,
438 "version",
439 "HTTP/1.1"
440 };
441 return ConstructSpdyControlFrame(extra_headers,
442 extra_header_count,
443 false,
444 stream_id,
445 LOWEST,
446 spdy::SYN_STREAM,
447 spdy::CONTROL_FLAG_NONE,
448 kStandardGetHeaders,
449 arraysize(kStandardGetHeaders),
450 associated_stream_id);
451
452 }
453 spdy::SpdyFrame* ConstructSpdyPush(const char* const extra_headers[],
454 int extra_header_count,
455 int stream_id,
456 int associated_stream_id,
457 const char* path,
458 const char* status,
459 const char* location,
460 const char* url) {
461 const char* const kStandardGetHeaders[] = {
462 "hello",
463 "bye",
464 "path",
465 path,
466 "status",
467 status,
468 "location",
469 location,
470 "url",
471 url,
472 "version",
473 "HTTP/1.1"
474 };
475 return ConstructSpdyControlFrame(extra_headers,
476 extra_header_count,
477 false,
478 stream_id,
479 LOWEST,
480 spdy::SYN_STREAM,
481 spdy::CONTROL_FLAG_NONE,
482 kStandardGetHeaders,
483 arraysize(kStandardGetHeaders),
484 associated_stream_id);
353 } 485 }
354 486
355 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. 487 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET.
488 // |extra_headers| are the extra header-value pairs, which typically
489 // will vary the most between calls.
490 // Returns a SpdyFrame.
491 spdy::SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) {
492 static const char* const kStandardGetHeaders[] = {
493 "hello",
494 "bye",
495 "status",
496 "301 Moved Permanently",
497 "location",
498 "http://www.foo.com/index.php",
499 "version",
500 "HTTP/1.1"
501 };
502 return ConstructSpdyControlFrame(NULL,
503 0,
504 false,
505 stream_id,
506 LOWEST,
507 spdy::SYN_REPLY,
508 spdy::CONTROL_FLAG_NONE,
509 kStandardGetHeaders,
510 arraysize(kStandardGetHeaders));
511 }
512
513 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET.
356 // |extra_headers| are the extra header-value pairs, which typically 514 // |extra_headers| are the extra header-value pairs, which typically
357 // will vary the most between calls. 515 // will vary the most between calls.
358 // Returns a SpdyFrame. 516 // Returns a SpdyFrame.
359 spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], 517 spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[],
360 int extra_header_count, 518 int extra_header_count,
361 int stream_id) { 519 int stream_id) {
362 const SpdyHeaderInfo kSynStartHeader = {
363 spdy::SYN_REPLY, // Kind = SynReply
364 stream_id, // Stream ID
365 0, // Associated stream ID
366 net::ConvertRequestPriorityToSpdyPriority(LOWEST),
367 // Priority
368 spdy::CONTROL_FLAG_NONE, // Control Flags
369 false, // Compressed
370 spdy::INVALID, // Status
371 NULL, // Data
372 0, // Length
373 spdy::DATA_FLAG_NONE // Data Flags
374 };
375 static const char* const kStandardGetHeaders[] = { 520 static const char* const kStandardGetHeaders[] = {
376 "hello", 521 "hello",
377 "bye", 522 "bye",
378 "status", 523 "status",
379 "200", 524 "200",
380 "url", 525 "url",
381 "/index.php", 526 "/index.php",
382 "version", 527 "version",
383 "HTTP/1.1" 528 "HTTP/1.1"
384 }; 529 };
385 return ConstructSpdyPacket( 530 return ConstructSpdyControlFrame(extra_headers,
386 kSynStartHeader, 531 extra_header_count,
387 extra_headers, 532 false,
388 extra_header_count, 533 stream_id,
389 kStandardGetHeaders, 534 LOWEST,
390 arraysize(kStandardGetHeaders) / 2); 535 spdy::SYN_REPLY,
536 spdy::CONTROL_FLAG_NONE,
537 kStandardGetHeaders,
538 arraysize(kStandardGetHeaders));
391 } 539 }
392 540
393 // Constructs a standard SPDY POST SYN packet. 541 // Constructs a standard SPDY POST SYN packet.
394 // |content_length| is the size of post data. 542 // |content_length| is the size of post data.
395 // |extra_headers| are the extra header-value pairs, which typically 543 // |extra_headers| are the extra header-value pairs, which typically
396 // will vary the most between calls. 544 // will vary the most between calls.
397 // Returns a SpdyFrame. 545 // Returns a SpdyFrame.
398 spdy::SpdyFrame* ConstructSpdyPost(int64 content_length, 546 spdy::SpdyFrame* ConstructSpdyPost(int64 content_length,
399 const char* const extra_headers[], 547 const char* const extra_headers[],
400 int extra_header_count) { 548 int extra_header_count) {
401 const SpdyHeaderInfo kSynStartHeader = {
402 spdy::SYN_STREAM, // Kind = Syn
403 1, // Stream ID
404 0, // Associated stream ID
405 net::ConvertRequestPriorityToSpdyPriority(LOWEST),
406 // Priority
407 spdy::CONTROL_FLAG_NONE, // Control Flags
408 false, // Compressed
409 spdy::INVALID, // Status
410 NULL, // Data
411 0, // Length
412 spdy::DATA_FLAG_NONE // Data Flags
413 };
414 std::string length_str = base::Int64ToString(content_length); 549 std::string length_str = base::Int64ToString(content_length);
415 const char* post_headers[] = { 550 const char* post_headers[] = {
416 "method", 551 "method",
417 "POST", 552 "POST",
418 "url", 553 "url",
419 "/", 554 "/",
420 "host", 555 "host",
421 "www.google.com", 556 "www.google.com",
422 "scheme", 557 "scheme",
423 "http", 558 "http",
424 "version", 559 "version",
425 "HTTP/1.1", 560 "HTTP/1.1",
426 "content-length", 561 "content-length",
427 length_str.c_str() 562 length_str.c_str()
428 }; 563 };
429 return ConstructSpdyPacket( 564 return ConstructSpdyControlFrame(extra_headers,
430 kSynStartHeader, 565 extra_header_count,
431 extra_headers, 566 false,
432 extra_header_count, 567 1,
433 post_headers, 568 LOWEST,
434 arraysize(post_headers) / 2); 569 spdy::SYN_STREAM,
570 spdy::CONTROL_FLAG_NONE,
571 post_headers,
572 arraysize(post_headers));
435 } 573 }
436 574
437 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. 575 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST.
438 // |extra_headers| are the extra header-value pairs, which typically 576 // |extra_headers| are the extra header-value pairs, which typically
439 // will vary the most between calls. 577 // will vary the most between calls.
440 // Returns a SpdyFrame. 578 // Returns a SpdyFrame.
441 spdy::SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], 579 spdy::SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[],
442 int extra_header_count) { 580 int extra_header_count) {
443 const SpdyHeaderInfo kSynStartHeader = {
444 spdy::SYN_REPLY, // Kind = SynReply
445 1, // Stream ID
446 0, // Associated stream ID
447 net::ConvertRequestPriorityToSpdyPriority(LOWEST),
448 // Priority
449 spdy::CONTROL_FLAG_NONE, // Control Flags
450 false, // Compressed
451 spdy::INVALID, // Status
452 NULL, // Data
453 0, // Length
454 spdy::DATA_FLAG_NONE // Data Flags
455 };
456 static const char* const kStandardGetHeaders[] = { 581 static const char* const kStandardGetHeaders[] = {
457 "hello", 582 "hello",
458 "bye", 583 "bye",
459 "status", 584 "status",
460 "200", 585 "200",
461 "url", 586 "url",
462 "/index.php", 587 "/index.php",
463 "version", 588 "version",
464 "HTTP/1.1" 589 "HTTP/1.1"
465 }; 590 };
466 return ConstructSpdyPacket( 591 return ConstructSpdyControlFrame(extra_headers,
467 kSynStartHeader, 592 extra_header_count,
468 extra_headers, 593 false,
469 extra_header_count, 594 1,
470 kStandardGetHeaders, 595 LOWEST,
471 arraysize(kStandardGetHeaders) / 2); 596 spdy::SYN_REPLY,
597 spdy::CONTROL_FLAG_NONE,
598 kStandardGetHeaders,
599 arraysize(kStandardGetHeaders));
472 } 600 }
473 601
474 // Constructs a single SPDY data frame with the contents "hello!" 602 // Constructs a single SPDY data frame with the contents "hello!"
475 spdy::SpdyFrame* ConstructSpdyBodyFrame(int stream_id, bool fin) { 603 spdy::SpdyFrame* ConstructSpdyBodyFrame(int stream_id, bool fin) {
476 spdy::SpdyFramer framer; 604 spdy::SpdyFramer framer;
477 return 605 return
478 framer.CreateDataFrame(stream_id, "hello!", 6, 606 framer.CreateDataFrame(stream_id, "hello!", 6,
479 fin ? spdy::DATA_FLAG_FIN : spdy::DATA_FLAG_NONE); 607 fin ? spdy::DATA_FLAG_FIN : spdy::DATA_FLAG_NONE);
480 } 608 }
481 609
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 728 }
601 729
602 // This creates a proxy for testing purposes. 730 // This creates a proxy for testing purposes.
603 // |proxy| should be in the form "myproxy:70". 731 // |proxy| should be in the form "myproxy:70".
604 ProxyService* SpdyCreateFixedProxyService(const std::string& proxy) { 732 ProxyService* SpdyCreateFixedProxyService(const std::string& proxy) {
605 net::ProxyConfig proxy_config; 733 net::ProxyConfig proxy_config;
606 proxy_config.proxy_rules().ParseFromString(proxy); 734 proxy_config.proxy_rules().ParseFromString(proxy);
607 return ProxyService::CreateFixed(proxy_config); 735 return ProxyService::CreateFixed(proxy_config);
608 } 736 }
609 737
738 const SpdyHeaderInfo make_spdy_header(spdy::SpdyControlType type) {
739 const SpdyHeaderInfo kHeader = {
740 type, // Kind = Syn
741 1, // Stream ID
742 0, // Associated stream ID
743 2, // Priority
744 spdy::CONTROL_FLAG_FIN, // Control Flags
745 false, // Compressed
746 spdy::INVALID, // Status
747 NULL, // Data
748 0, // Length
749 spdy::DATA_FLAG_NONE // Data Flags
750 };
751 return kHeader;
752 }
610 } // namespace net 753 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698