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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 extra_header_count, | 497 extra_header_count, |
498 /*compressed*/ false, | 498 /*compressed*/ false, |
499 stream_id, | 499 stream_id, |
500 LOWEST, | 500 LOWEST, |
501 SYN_STREAM, | 501 SYN_STREAM, |
502 CONTROL_FLAG_NONE, | 502 CONTROL_FLAG_NONE, |
503 kConnectHeaders, | 503 kConnectHeaders, |
504 arraysize(kConnectHeaders)); | 504 arraysize(kConnectHeaders)); |
505 } | 505 } |
506 | 506 |
507 // Constructs a standard SPDY SYN_STREAM frame for a WebSocket over SPDY | |
508 // opening handshake. | |
509 SpdyFrame* ConstructSpdyWebSocket(int stream_id, | |
510 const char* path, | |
511 const char* host, | |
512 const char* origin) { | |
513 const char* const kWebSocketHeaders[] = { | |
514 ":path", | |
515 path, | |
516 ":host", | |
517 host, | |
518 ":version", | |
519 "WebSocket/13", | |
520 ":scheme", | |
521 "ws", | |
522 ":origin", | |
523 origin | |
524 }; | |
525 return ConstructSpdyControlFrame(/*extra_headers*/ NULL, | |
526 /*extra_header_count*/ 0, | |
527 /*compressed*/ false, | |
528 stream_id, | |
529 LOWEST, | |
530 SYN_STREAM, | |
531 CONTROL_FLAG_NONE, | |
532 kWebSocketHeaders, | |
533 arraysize(kWebSocketHeaders)); | |
534 } | |
535 | |
536 // Constructs a standard SPDY push SYN packet. | 507 // Constructs a standard SPDY push SYN packet. |
537 // |extra_headers| are the extra header-value pairs, which typically | 508 // |extra_headers| are the extra header-value pairs, which typically |
538 // will vary the most between calls. | 509 // will vary the most between calls. |
539 // Returns a SpdyFrame. | 510 // Returns a SpdyFrame. |
540 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 511 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
541 int extra_header_count, | 512 int extra_header_count, |
542 int stream_id, | 513 int stream_id, |
543 int associated_stream_id) { | 514 int associated_stream_id) { |
544 const char* const kStandardPushHeaders[] = { | 515 const char* const kStandardPushHeaders[] = { |
545 "hello", "bye", | 516 "hello", "bye", |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 extra_header_count, | 674 extra_header_count, |
704 false, | 675 false, |
705 stream_id, | 676 stream_id, |
706 LOWEST, | 677 LOWEST, |
707 SYN_REPLY, | 678 SYN_REPLY, |
708 CONTROL_FLAG_NONE, | 679 CONTROL_FLAG_NONE, |
709 kStandardGetHeaders, | 680 kStandardGetHeaders, |
710 arraysize(kStandardGetHeaders)); | 681 arraysize(kStandardGetHeaders)); |
711 } | 682 } |
712 | 683 |
713 // Constructs a standard SPDY SYN_REPLY packet to match the WebSocket over SPDY | |
714 // opening handshake. | |
715 // Returns a SpdyFrame. | |
716 SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id) { | |
717 static const char* const kStandardWebSocketHeaders[] = { | |
718 ":status", | |
719 "101" | |
720 }; | |
721 return ConstructSpdyControlFrame(NULL, | |
722 0, | |
723 false, | |
724 stream_id, | |
725 LOWEST, | |
726 SYN_REPLY, | |
727 CONTROL_FLAG_NONE, | |
728 kStandardWebSocketHeaders, | |
729 arraysize(kStandardWebSocketHeaders)); | |
730 } | |
731 | |
732 // Constructs a standard SPDY POST SYN packet. | 684 // Constructs a standard SPDY POST SYN packet. |
733 // |content_length| is the size of post data. | 685 // |content_length| is the size of post data. |
734 // |extra_headers| are the extra header-value pairs, which typically | 686 // |extra_headers| are the extra header-value pairs, which typically |
735 // will vary the most between calls. | 687 // will vary the most between calls. |
736 // Returns a SpdyFrame. | 688 // Returns a SpdyFrame. |
737 SpdyFrame* ConstructSpdyPost(int64 content_length, | 689 SpdyFrame* ConstructSpdyPost(int64 content_length, |
738 const char* const extra_headers[], | 690 const char* const extra_headers[], |
739 int extra_header_count) { | 691 int extra_header_count) { |
740 std::string length_str = base::Int64ToString(content_length); | 692 std::string length_str = base::Int64ToString(content_length); |
741 const char* post_headers[] = { | 693 const char* post_headers[] = { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 } | 780 } |
829 | 781 |
830 // Constructs a single SPDY data frame with the given content. | 782 // Constructs a single SPDY data frame with the given content. |
831 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, | 783 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, |
832 uint32 len, bool fin) { | 784 uint32 len, bool fin) { |
833 BufferedSpdyFramer framer(3); | 785 BufferedSpdyFramer framer(3); |
834 return framer.CreateDataFrame( | 786 return framer.CreateDataFrame( |
835 stream_id, data, len, fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); | 787 stream_id, data, len, fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); |
836 } | 788 } |
837 | 789 |
838 // Constructs a SPDY HEADERS frame for a WebSocket frame over SPDY. | |
839 SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id, | |
840 const char* length, | |
841 bool fin) { | |
842 static const char* const kHeaders[] = { | |
843 ":opcode", | |
844 "1", // text frame | |
845 ":length", | |
846 length, | |
847 ":fin", | |
848 fin ? "1" : "0" | |
849 }; | |
850 return ConstructSpdyControlFrame(/*extra_headers*/ NULL, | |
851 /*extra_header_count*/ 0, | |
852 /*compression*/ false, | |
853 stream_id, | |
854 LOWEST, | |
855 HEADERS, | |
856 CONTROL_FLAG_NONE, | |
857 kHeaders, | |
858 arraysize(kHeaders)); | |
859 } | |
860 | |
861 // Wraps |frame| in the payload of a data frame in stream |stream_id|. | 790 // Wraps |frame| in the payload of a data frame in stream |stream_id|. |
862 SpdyFrame* ConstructWrappedSpdyFrame( | 791 SpdyFrame* ConstructWrappedSpdyFrame( |
863 const scoped_ptr<SpdyFrame>& frame, | 792 const scoped_ptr<SpdyFrame>& frame, |
864 int stream_id) { | 793 int stream_id) { |
865 return ConstructSpdyBodyFrame(stream_id, frame->data(), | 794 return ConstructSpdyBodyFrame(stream_id, frame->data(), |
866 frame->length() + SpdyFrame::kHeaderSize, | 795 frame->length() + SpdyFrame::kHeaderSize, |
867 false); | 796 false); |
868 } | 797 } |
869 | 798 |
870 // Construct an expected SPDY reply string. | 799 // Construct an expected SPDY reply string. |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 SpdyTestStateHelper::~SpdyTestStateHelper() { | 1061 SpdyTestStateHelper::~SpdyTestStateHelper() { |
1133 SpdySession::ResetStaticSettingsToInit(); | 1062 SpdySession::ResetStaticSettingsToInit(); |
1134 // TODO(rch): save/restore this value | 1063 // TODO(rch): save/restore this value |
1135 BufferedSpdyFramer::set_enable_compression_default(true); | 1064 BufferedSpdyFramer::set_enable_compression_default(true); |
1136 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); | 1065 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); |
1137 } | 1066 } |
1138 | 1067 |
1139 } // namespace test_spdy3 | 1068 } // namespace test_spdy3 |
1140 | 1069 |
1141 } // namespace net | 1070 } // namespace net |
OLD | NEW |