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