| 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 |
| 507 // Constructs a standard SPDY push SYN packet. | 536 // Constructs a standard SPDY push SYN packet. |
| 508 // |extra_headers| are the extra header-value pairs, which typically | 537 // |extra_headers| are the extra header-value pairs, which typically |
| 509 // will vary the most between calls. | 538 // will vary the most between calls. |
| 510 // Returns a SpdyFrame. | 539 // Returns a SpdyFrame. |
| 511 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 540 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 512 int extra_header_count, | 541 int extra_header_count, |
| 513 int stream_id, | 542 int stream_id, |
| 514 int associated_stream_id) { | 543 int associated_stream_id) { |
| 515 const char* const kStandardPushHeaders[] = { | 544 const char* const kStandardPushHeaders[] = { |
| 516 "hello", "bye", | 545 "hello", "bye", |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 extra_header_count, | 703 extra_header_count, |
| 675 false, | 704 false, |
| 676 stream_id, | 705 stream_id, |
| 677 LOWEST, | 706 LOWEST, |
| 678 SYN_REPLY, | 707 SYN_REPLY, |
| 679 CONTROL_FLAG_NONE, | 708 CONTROL_FLAG_NONE, |
| 680 kStandardGetHeaders, | 709 kStandardGetHeaders, |
| 681 arraysize(kStandardGetHeaders)); | 710 arraysize(kStandardGetHeaders)); |
| 682 } | 711 } |
| 683 | 712 |
| 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 |
| 684 // Constructs a standard SPDY POST SYN packet. | 732 // Constructs a standard SPDY POST SYN packet. |
| 685 // |content_length| is the size of post data. | 733 // |content_length| is the size of post data. |
| 686 // |extra_headers| are the extra header-value pairs, which typically | 734 // |extra_headers| are the extra header-value pairs, which typically |
| 687 // will vary the most between calls. | 735 // will vary the most between calls. |
| 688 // Returns a SpdyFrame. | 736 // Returns a SpdyFrame. |
| 689 SpdyFrame* ConstructSpdyPost(int64 content_length, | 737 SpdyFrame* ConstructSpdyPost(int64 content_length, |
| 690 const char* const extra_headers[], | 738 const char* const extra_headers[], |
| 691 int extra_header_count) { | 739 int extra_header_count) { |
| 692 std::string length_str = base::Int64ToString(content_length); | 740 std::string length_str = base::Int64ToString(content_length); |
| 693 const char* post_headers[] = { | 741 const char* post_headers[] = { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 } | 828 } |
| 781 | 829 |
| 782 // Constructs a single SPDY data frame with the given content. | 830 // Constructs a single SPDY data frame with the given content. |
| 783 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, | 831 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, |
| 784 uint32 len, bool fin) { | 832 uint32 len, bool fin) { |
| 785 BufferedSpdyFramer framer(3); | 833 BufferedSpdyFramer framer(3); |
| 786 return framer.CreateDataFrame( | 834 return framer.CreateDataFrame( |
| 787 stream_id, data, len, fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); | 835 stream_id, data, len, fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); |
| 788 } | 836 } |
| 789 | 837 |
| 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 |
| 790 // Wraps |frame| in the payload of a data frame in stream |stream_id|. | 861 // Wraps |frame| in the payload of a data frame in stream |stream_id|. |
| 791 SpdyFrame* ConstructWrappedSpdyFrame( | 862 SpdyFrame* ConstructWrappedSpdyFrame( |
| 792 const scoped_ptr<SpdyFrame>& frame, | 863 const scoped_ptr<SpdyFrame>& frame, |
| 793 int stream_id) { | 864 int stream_id) { |
| 794 return ConstructSpdyBodyFrame(stream_id, frame->data(), | 865 return ConstructSpdyBodyFrame(stream_id, frame->data(), |
| 795 frame->length() + SpdyFrame::kHeaderSize, | 866 frame->length() + SpdyFrame::kHeaderSize, |
| 796 false); | 867 false); |
| 797 } | 868 } |
| 798 | 869 |
| 799 // Construct an expected SPDY reply string. | 870 // Construct an expected SPDY reply string. |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 SpdyTestStateHelper::~SpdyTestStateHelper() { | 1132 SpdyTestStateHelper::~SpdyTestStateHelper() { |
| 1062 SpdySession::ResetStaticSettingsToInit(); | 1133 SpdySession::ResetStaticSettingsToInit(); |
| 1063 // TODO(rch): save/restore this value | 1134 // TODO(rch): save/restore this value |
| 1064 BufferedSpdyFramer::set_enable_compression_default(true); | 1135 BufferedSpdyFramer::set_enable_compression_default(true); |
| 1065 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); | 1136 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); |
| 1066 } | 1137 } |
| 1067 | 1138 |
| 1068 } // namespace test_spdy3 | 1139 } // namespace test_spdy3 |
| 1069 | 1140 |
| 1070 } // namespace net | 1141 } // namespace net |
| OLD | NEW |