OLD | NEW |
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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 464 } |
465 | 465 |
466 // Constructs a standard SPDY push SYN packet. | 466 // Constructs a standard SPDY push SYN packet. |
467 // |extra_headers| are the extra header-value pairs, which typically | 467 // |extra_headers| are the extra header-value pairs, which typically |
468 // will vary the most between calls. | 468 // will vary the most between calls. |
469 // Returns a SpdyFrame. | 469 // Returns a SpdyFrame. |
470 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 470 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
471 int extra_header_count, | 471 int extra_header_count, |
472 int stream_id, | 472 int stream_id, |
473 int associated_stream_id) { | 473 int associated_stream_id) { |
474 const char* const kStandardGetHeaders[] = { | 474 const char* const kStandardPushHeaders[] = { |
475 "hello", | 475 "hello", "bye", |
476 "bye", | 476 ":status", "200", |
477 "status", | 477 ":version", "HTTP/1.1" |
478 "200", | |
479 "version", | |
480 "HTTP/1.1" | |
481 }; | 478 }; |
482 return ConstructSpdyControlFrame(extra_headers, | 479 return ConstructSpdyControlFrame(extra_headers, |
483 extra_header_count, | 480 extra_header_count, |
484 false, | 481 false, |
485 stream_id, | 482 stream_id, |
486 LOWEST, | 483 LOWEST, |
487 SYN_STREAM, | 484 SYN_STREAM, |
488 CONTROL_FLAG_NONE, | 485 CONTROL_FLAG_NONE, |
489 kStandardGetHeaders, | 486 kStandardPushHeaders, |
490 arraysize(kStandardGetHeaders), | 487 arraysize(kStandardPushHeaders), |
491 associated_stream_id); | 488 associated_stream_id); |
492 } | 489 } |
493 | 490 |
494 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 491 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
495 int extra_header_count, | 492 int extra_header_count, |
496 int stream_id, | 493 int stream_id, |
497 int associated_stream_id, | 494 int associated_stream_id, |
498 const char* url) { | 495 const char* url) { |
499 const char* const kStandardGetHeaders[] = { | 496 GURL gurl(url); |
| 497 |
| 498 std::string str_path = gurl.PathForRequest(); |
| 499 std::string str_scheme = gurl.scheme(); |
| 500 std::string str_host = gurl.host(); |
| 501 if (gurl.has_port()) { |
| 502 str_host += ":"; |
| 503 str_host += gurl.port(); |
| 504 } |
| 505 scoped_array<char> req(new char[str_path.size() + 1]); |
| 506 scoped_array<char> scheme(new char[str_scheme.size() + 1]); |
| 507 scoped_array<char> host(new char[str_host.size() + 1]); |
| 508 memcpy(req.get(), str_path.c_str(), str_path.size()); |
| 509 memcpy(scheme.get(), str_scheme.c_str(), str_scheme.size()); |
| 510 memcpy(host.get(), str_host.c_str(), str_host.size()); |
| 511 req.get()[str_path.size()] = '\0'; |
| 512 scheme.get()[str_scheme.size()] = '\0'; |
| 513 host.get()[str_host.size()] = '\0'; |
| 514 |
| 515 const char* const headers[] = { |
500 "hello", | 516 "hello", |
501 "bye", | 517 "bye", |
502 "status", | 518 ":status", |
503 "200 OK", | 519 "200 OK", |
504 "url", | 520 ":version", |
505 url, | 521 "HTTP/1.1", |
506 "version", | 522 ":path", |
507 "HTTP/1.1" | 523 req.get(), |
| 524 ":host", |
| 525 host.get(), |
| 526 ":scheme", |
| 527 scheme.get(), |
508 }; | 528 }; |
509 return ConstructSpdyControlFrame(extra_headers, | 529 return ConstructSpdyControlFrame(extra_headers, |
510 extra_header_count, | 530 extra_header_count, |
511 false, | 531 false, |
512 stream_id, | 532 stream_id, |
513 LOWEST, | 533 LOWEST, |
514 SYN_STREAM, | 534 SYN_STREAM, |
515 CONTROL_FLAG_NONE, | 535 CONTROL_FLAG_NONE, |
516 kStandardGetHeaders, | 536 headers, |
517 arraysize(kStandardGetHeaders), | 537 arraysize(headers), |
518 associated_stream_id); | 538 associated_stream_id); |
519 | 539 |
520 } | 540 } |
521 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 541 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
522 int extra_header_count, | 542 int extra_header_count, |
523 int stream_id, | 543 int stream_id, |
524 int associated_stream_id, | 544 int associated_stream_id, |
525 const char* url, | 545 const char* url, |
526 const char* status, | 546 const char* status, |
527 const char* location) { | 547 const char* location) { |
| 548 GURL gurl(url); |
| 549 |
| 550 std::string str_path = gurl.PathForRequest(); |
| 551 std::string str_scheme = gurl.scheme(); |
| 552 std::string str_host = gurl.host(); |
| 553 if (gurl.has_port()) { |
| 554 str_host += ":"; |
| 555 str_host += gurl.port(); |
| 556 } |
| 557 scoped_array<char> req(new char[str_path.size() + 1]); |
| 558 scoped_array<char> scheme(new char[str_scheme.size() + 1]); |
| 559 scoped_array<char> host(new char[str_host.size() + 1]); |
| 560 memcpy(req.get(), str_path.c_str(), str_path.size()); |
| 561 memcpy(scheme.get(), str_scheme.c_str(), str_scheme.size()); |
| 562 memcpy(host.get(), str_host.c_str(), str_host.size()); |
| 563 req.get()[str_path.size()] = '\0'; |
| 564 scheme.get()[str_scheme.size()] = '\0'; |
| 565 host.get()[str_host.size()] = '\0'; |
| 566 |
528 const char* const kStandardGetHeaders[] = { | 567 const char* const kStandardGetHeaders[] = { |
529 "hello", | 568 "hello", |
530 "bye", | 569 "bye", |
531 "status", | 570 ":status", |
532 status, | 571 status, |
533 "location", | 572 "location", |
534 location, | 573 location, |
535 "url", | 574 ":path", |
536 url, | 575 req.get(), |
537 "version", | 576 ":host", |
| 577 host.get(), |
| 578 ":scheme", |
| 579 scheme.get(), |
| 580 ":version", |
538 "HTTP/1.1" | 581 "HTTP/1.1" |
539 }; | 582 }; |
540 return ConstructSpdyControlFrame(extra_headers, | 583 return ConstructSpdyControlFrame(extra_headers, |
541 extra_header_count, | 584 extra_header_count, |
542 false, | 585 false, |
543 stream_id, | 586 stream_id, |
544 LOWEST, | 587 LOWEST, |
545 SYN_STREAM, | 588 SYN_STREAM, |
546 CONTROL_FLAG_NONE, | 589 CONTROL_FLAG_NONE, |
547 kStandardGetHeaders, | 590 kStandardGetHeaders, |
548 arraysize(kStandardGetHeaders), | 591 arraysize(kStandardGetHeaders), |
549 associated_stream_id); | 592 associated_stream_id); |
550 } | 593 } |
551 | 594 |
552 SpdyFrame* ConstructSpdyPush(int stream_id, | 595 SpdyFrame* ConstructSpdyPush(int stream_id, |
553 int associated_stream_id, | 596 int associated_stream_id, |
554 const char* url) { | 597 const char* url) { |
555 const char* const kStandardGetHeaders[] = { | 598 GURL gurl(url); |
556 "url", | 599 |
557 url | 600 std::string str_path = gurl.PathForRequest(); |
| 601 std::string str_scheme = gurl.scheme(); |
| 602 std::string str_host = gurl.host(); |
| 603 if (gurl.has_port()) { |
| 604 str_host += ":"; |
| 605 str_host += gurl.port(); |
| 606 } |
| 607 scoped_array<char> req(new char[str_path.size() + 1]); |
| 608 scoped_array<char> scheme(new char[str_scheme.size() + 1]); |
| 609 scoped_array<char> host(new char[str_host.size() + 1]); |
| 610 memcpy(req.get(), str_path.c_str(), str_path.size()); |
| 611 memcpy(scheme.get(), str_scheme.c_str(), str_scheme.size()); |
| 612 memcpy(host.get(), str_host.c_str(), str_host.size()); |
| 613 req.get()[str_path.size()] = '\0'; |
| 614 scheme.get()[str_scheme.size()] = '\0'; |
| 615 host.get()[str_host.size()] = '\0'; |
| 616 |
| 617 const char* const headers[] = { |
| 618 req.get(), |
| 619 ":host", |
| 620 host.get(), |
| 621 ":scheme", |
| 622 scheme.get(), |
558 }; | 623 }; |
559 return ConstructSpdyControlFrame(0, | 624 return ConstructSpdyControlFrame(0, |
560 0, | 625 0, |
561 false, | 626 false, |
562 stream_id, | 627 stream_id, |
563 LOWEST, | 628 LOWEST, |
564 SYN_STREAM, | 629 SYN_STREAM, |
565 CONTROL_FLAG_NONE, | 630 CONTROL_FLAG_NONE, |
566 kStandardGetHeaders, | 631 headers, |
567 arraysize(kStandardGetHeaders), | 632 arraysize(headers), |
568 associated_stream_id); | 633 associated_stream_id); |
569 } | 634 } |
570 | 635 |
571 SpdyFrame* ConstructSpdyPushHeaders(int stream_id, | 636 SpdyFrame* ConstructSpdyPushHeaders(int stream_id, |
572 const char* const extra_headers[], | 637 const char* const extra_headers[], |
573 int extra_header_count) { | 638 int extra_header_count) { |
574 const char* const kStandardGetHeaders[] = { | 639 const char* const kStandardGetHeaders[] = { |
575 "status", | 640 ":status", |
576 "200 OK", | 641 "200 OK", |
577 "version", | 642 ":version", |
578 "HTTP/1.1" | 643 "HTTP/1.1" |
579 }; | 644 }; |
580 return ConstructSpdyControlFrame(extra_headers, | 645 return ConstructSpdyControlFrame(extra_headers, |
581 extra_header_count, | 646 extra_header_count, |
582 false, | 647 false, |
583 stream_id, | 648 stream_id, |
584 LOWEST, | 649 LOWEST, |
585 HEADERS, | 650 HEADERS, |
586 CONTROL_FLAG_NONE, | 651 CONTROL_FLAG_NONE, |
587 kStandardGetHeaders, | 652 kStandardGetHeaders, |
588 arraysize(kStandardGetHeaders)); | 653 arraysize(kStandardGetHeaders)); |
589 } | 654 } |
590 | 655 |
591 // Constructs a standard SPDY SYN_REPLY packet with the specified status code. | 656 // Constructs a standard SPDY SYN_REPLY packet with the specified status code. |
592 // Returns a SpdyFrame. | 657 // Returns a SpdyFrame. |
593 SpdyFrame* ConstructSpdySynReplyError( | 658 SpdyFrame* ConstructSpdySynReplyError( |
594 const char* const status, | 659 const char* const status, |
595 const char* const* const extra_headers, | 660 const char* const* const extra_headers, |
596 int extra_header_count, | 661 int extra_header_count, |
597 int stream_id) { | 662 int stream_id) { |
598 const char* const kStandardGetHeaders[] = { | 663 const char* const kStandardGetHeaders[] = { |
599 "hello", | 664 "hello", |
600 "bye", | 665 "bye", |
601 "status", | 666 ":status", |
602 status, | 667 status, |
603 "version", | 668 ":version", |
604 "HTTP/1.1" | 669 "HTTP/1.1" |
605 }; | 670 }; |
606 return ConstructSpdyControlFrame(extra_headers, | 671 return ConstructSpdyControlFrame(extra_headers, |
607 extra_header_count, | 672 extra_header_count, |
608 false, | 673 false, |
609 stream_id, | 674 stream_id, |
610 LOWEST, | 675 LOWEST, |
611 SYN_REPLY, | 676 SYN_REPLY, |
612 CONTROL_FLAG_NONE, | 677 CONTROL_FLAG_NONE, |
613 kStandardGetHeaders, | 678 kStandardGetHeaders, |
(...skipping 26 matching lines...) Expand all Loading... |
640 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. | 705 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. |
641 // |extra_headers| are the extra header-value pairs, which typically | 706 // |extra_headers| are the extra header-value pairs, which typically |
642 // will vary the most between calls. | 707 // will vary the most between calls. |
643 // Returns a SpdyFrame. | 708 // Returns a SpdyFrame. |
644 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], | 709 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], |
645 int extra_header_count, | 710 int extra_header_count, |
646 int stream_id) { | 711 int stream_id) { |
647 static const char* const kStandardGetHeaders[] = { | 712 static const char* const kStandardGetHeaders[] = { |
648 "hello", | 713 "hello", |
649 "bye", | 714 "bye", |
650 "status", | 715 ":status", |
651 "200", | 716 "200", |
652 "version", | 717 ":version", |
653 "HTTP/1.1" | 718 "HTTP/1.1" |
654 }; | 719 }; |
655 return ConstructSpdyControlFrame(extra_headers, | 720 return ConstructSpdyControlFrame(extra_headers, |
656 extra_header_count, | 721 extra_header_count, |
657 false, | 722 false, |
658 stream_id, | 723 stream_id, |
659 LOWEST, | 724 LOWEST, |
660 SYN_REPLY, | 725 SYN_REPLY, |
661 CONTROL_FLAG_NONE, | 726 CONTROL_FLAG_NONE, |
662 kStandardGetHeaders, | 727 kStandardGetHeaders, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 | 793 |
729 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. | 794 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. |
730 // |extra_headers| are the extra header-value pairs, which typically | 795 // |extra_headers| are the extra header-value pairs, which typically |
731 // will vary the most between calls. | 796 // will vary the most between calls. |
732 // Returns a SpdyFrame. | 797 // Returns a SpdyFrame. |
733 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], | 798 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], |
734 int extra_header_count) { | 799 int extra_header_count) { |
735 static const char* const kStandardGetHeaders[] = { | 800 static const char* const kStandardGetHeaders[] = { |
736 "hello", | 801 "hello", |
737 "bye", | 802 "bye", |
738 "status", | 803 ":status", |
739 "200", | 804 "200", |
740 "url", | 805 "url", |
741 "/index.php", | 806 "/index.php", |
742 "version", | 807 ":version", |
743 "HTTP/1.1" | 808 "HTTP/1.1" |
744 }; | 809 }; |
745 return ConstructSpdyControlFrame(extra_headers, | 810 return ConstructSpdyControlFrame(extra_headers, |
746 extra_header_count, | 811 extra_header_count, |
747 false, | 812 false, |
748 1, | 813 1, |
749 LOWEST, | 814 LOWEST, |
750 SYN_REPLY, | 815 SYN_REPLY, |
751 CONTROL_FLAG_NONE, | 816 CONTROL_FLAG_NONE, |
752 kStandardGetHeaders, | 817 kStandardGetHeaders, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 return 0; | 860 return 0; |
796 // Copy in the extra headers. | 861 // Copy in the extra headers. |
797 AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers); | 862 AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers); |
798 // The iterator gets us the list of header/value pairs in sorted order. | 863 // The iterator gets us the list of header/value pairs in sorted order. |
799 SpdyHeaderBlock::iterator next = headers.begin(); | 864 SpdyHeaderBlock::iterator next = headers.begin(); |
800 SpdyHeaderBlock::iterator last = headers.end(); | 865 SpdyHeaderBlock::iterator last = headers.end(); |
801 for ( ; next != last; ++next) { | 866 for ( ; next != last; ++next) { |
802 // Write the header. | 867 // Write the header. |
803 int value_len, current_len, offset; | 868 int value_len, current_len, offset; |
804 const char* header_string = next->first.c_str(); | 869 const char* header_string = next->first.c_str(); |
| 870 if (header_string && header_string[0] == ':') |
| 871 header_string++; |
805 packet_size += AppendToBuffer(header_string, | 872 packet_size += AppendToBuffer(header_string, |
806 next->first.length(), | 873 strlen(header_string), |
807 &buffer_write, | 874 &buffer_write, |
808 &buffer_left); | 875 &buffer_left); |
809 packet_size += AppendToBuffer(": ", | 876 packet_size += AppendToBuffer(": ", |
810 strlen(": "), | 877 strlen(": "), |
811 &buffer_write, | 878 &buffer_write, |
812 &buffer_left); | 879 &buffer_left); |
813 // Write the value(s). | 880 // Write the value(s). |
814 const char* value_string = next->second.c_str(); | 881 const char* value_string = next->second.c_str(); |
815 // Check if it's split among two or more values. | 882 // Check if it's split among two or more values. |
816 value_len = next->second.length(); | 883 value_len = next->second.length(); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 | 1089 |
1023 SpdyTestStateHelper::~SpdyTestStateHelper() { | 1090 SpdyTestStateHelper::~SpdyTestStateHelper() { |
1024 SpdySession::ResetStaticSettingsToInit(); | 1091 SpdySession::ResetStaticSettingsToInit(); |
1025 // TODO(rch): save/restore this value | 1092 // TODO(rch): save/restore this value |
1026 SpdyFramer::set_enable_compression_default(true); | 1093 SpdyFramer::set_enable_compression_default(true); |
1027 } | 1094 } |
1028 | 1095 |
1029 } // namespace test_spdy3 | 1096 } // namespace test_spdy3 |
1030 | 1097 |
1031 } // namespace net | 1098 } // namespace net |
OLD | NEW |