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_spdy2.h" | 5 #include "net/spdy/spdy_test_util_spdy2.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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 extra_header_count, | 447 extra_header_count, |
448 /*compressed*/ false, | 448 /*compressed*/ false, |
449 stream_id, | 449 stream_id, |
450 LOWEST, | 450 LOWEST, |
451 SYN_STREAM, | 451 SYN_STREAM, |
452 CONTROL_FLAG_NONE, | 452 CONTROL_FLAG_NONE, |
453 kConnectHeaders, | 453 kConnectHeaders, |
454 arraysize(kConnectHeaders)); | 454 arraysize(kConnectHeaders)); |
455 } | 455 } |
456 | 456 |
| 457 // Constructs a standard SPDY SYN_STREAM frame for a WebSocket over SPDY |
| 458 // opening handshake. |
| 459 SpdyFrame* ConstructSpdyWebSocket(int stream_id, |
| 460 const char* path, |
| 461 const char* host, |
| 462 const char* origin) { |
| 463 const char* const kWebSocketHeaders[] = { |
| 464 "path", |
| 465 path, |
| 466 "host", |
| 467 host, |
| 468 "version", |
| 469 "WebSocket/13", |
| 470 "scheme", |
| 471 "ws", |
| 472 "origin", |
| 473 origin |
| 474 }; |
| 475 return ConstructSpdyControlFrame(/*extra_headers*/ NULL, |
| 476 /*extra_header_count*/ 0, |
| 477 /*compressed*/ false, |
| 478 stream_id, |
| 479 LOWEST, |
| 480 SYN_STREAM, |
| 481 CONTROL_FLAG_NONE, |
| 482 kWebSocketHeaders, |
| 483 arraysize(kWebSocketHeaders)); |
| 484 } |
| 485 |
457 // Constructs a standard SPDY push SYN packet. | 486 // Constructs a standard SPDY push SYN packet. |
458 // |extra_headers| are the extra header-value pairs, which typically | 487 // |extra_headers| are the extra header-value pairs, which typically |
459 // will vary the most between calls. | 488 // will vary the most between calls. |
460 // Returns a SpdyFrame. | 489 // Returns a SpdyFrame. |
461 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 490 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
462 int extra_header_count, | 491 int extra_header_count, |
463 int stream_id, | 492 int stream_id, |
464 int associated_stream_id) { | 493 int associated_stream_id) { |
465 const char* const kStandardGetHeaders[] = { | 494 const char* const kStandardGetHeaders[] = { |
466 "hello", | 495 "hello", |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 extra_header_count, | 676 extra_header_count, |
648 false, | 677 false, |
649 stream_id, | 678 stream_id, |
650 LOWEST, | 679 LOWEST, |
651 SYN_REPLY, | 680 SYN_REPLY, |
652 CONTROL_FLAG_NONE, | 681 CONTROL_FLAG_NONE, |
653 kStandardGetHeaders, | 682 kStandardGetHeaders, |
654 arraysize(kStandardGetHeaders)); | 683 arraysize(kStandardGetHeaders)); |
655 } | 684 } |
656 | 685 |
| 686 // Constructs a standard SPDY SYN_REPLY packet to match the WebSocket over SPDY |
| 687 // opening handshake. |
| 688 // Returns a SpdyFrame. |
| 689 SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id) { |
| 690 static const char* const kStandardWebSocketHeaders[] = { |
| 691 "status", |
| 692 "101" |
| 693 }; |
| 694 return ConstructSpdyControlFrame(NULL, |
| 695 0, |
| 696 false, |
| 697 stream_id, |
| 698 LOWEST, |
| 699 SYN_REPLY, |
| 700 CONTROL_FLAG_NONE, |
| 701 kStandardWebSocketHeaders, |
| 702 arraysize(kStandardWebSocketHeaders)); |
| 703 } |
| 704 |
657 // Constructs a standard SPDY POST SYN packet. | 705 // Constructs a standard SPDY POST SYN packet. |
658 // |content_length| is the size of post data. | 706 // |content_length| is the size of post data. |
659 // |extra_headers| are the extra header-value pairs, which typically | 707 // |extra_headers| are the extra header-value pairs, which typically |
660 // will vary the most between calls. | 708 // will vary the most between calls. |
661 // Returns a SpdyFrame. | 709 // Returns a SpdyFrame. |
662 SpdyFrame* ConstructSpdyPost(int64 content_length, | 710 SpdyFrame* ConstructSpdyPost(int64 content_length, |
663 const char* const extra_headers[], | 711 const char* const extra_headers[], |
664 int extra_header_count) { | 712 int extra_header_count) { |
665 std::string length_str = base::Int64ToString(content_length); | 713 std::string length_str = base::Int64ToString(content_length); |
666 const char* post_headers[] = { | 714 const char* post_headers[] = { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 } | 801 } |
754 | 802 |
755 // Constructs a single SPDY data frame with the given content. | 803 // Constructs a single SPDY data frame with the given content. |
756 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, | 804 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, |
757 uint32 len, bool fin) { | 805 uint32 len, bool fin) { |
758 BufferedSpdyFramer framer(2); | 806 BufferedSpdyFramer framer(2); |
759 return framer.CreateDataFrame( | 807 return framer.CreateDataFrame( |
760 stream_id, data, len, fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); | 808 stream_id, data, len, fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); |
761 } | 809 } |
762 | 810 |
| 811 // Constructs a SPDY HEADERS frame for a WebSocket frame over SPDY. |
| 812 SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id, |
| 813 const char* length, |
| 814 bool fin) { |
| 815 static const char* const kHeaders[] = { |
| 816 "opcode", |
| 817 "1", // text frame |
| 818 "length", |
| 819 length, |
| 820 "fin", |
| 821 fin ? "1" : "0" |
| 822 }; |
| 823 return ConstructSpdyControlFrame(/*extra_headers*/ NULL, |
| 824 /*extra_header_count*/ 0, |
| 825 /*compression*/ false, |
| 826 stream_id, |
| 827 LOWEST, |
| 828 HEADERS, |
| 829 CONTROL_FLAG_NONE, |
| 830 kHeaders, |
| 831 arraysize(kHeaders)); |
| 832 } |
| 833 |
763 // Wraps |frame| in the payload of a data frame in stream |stream_id|. | 834 // Wraps |frame| in the payload of a data frame in stream |stream_id|. |
764 SpdyFrame* ConstructWrappedSpdyFrame( | 835 SpdyFrame* ConstructWrappedSpdyFrame( |
765 const scoped_ptr<SpdyFrame>& frame, | 836 const scoped_ptr<SpdyFrame>& frame, |
766 int stream_id) { | 837 int stream_id) { |
767 return ConstructSpdyBodyFrame(stream_id, frame->data(), | 838 return ConstructSpdyBodyFrame(stream_id, frame->data(), |
768 frame->length() + SpdyFrame::kHeaderSize, | 839 frame->length() + SpdyFrame::kHeaderSize, |
769 false); | 840 false); |
770 } | 841 } |
771 | 842 |
772 // Construct an expected SPDY reply string. | 843 // Construct an expected SPDY reply string. |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 } | 1092 } |
1022 | 1093 |
1023 SpdyTestStateHelper::~SpdyTestStateHelper() { | 1094 SpdyTestStateHelper::~SpdyTestStateHelper() { |
1024 SpdySession::ResetStaticSettingsToInit(); | 1095 SpdySession::ResetStaticSettingsToInit(); |
1025 // TODO(rch): save/restore this value | 1096 // TODO(rch): save/restore this value |
1026 BufferedSpdyFramer::set_enable_compression_default(true); | 1097 BufferedSpdyFramer::set_enable_compression_default(true); |
1027 } | 1098 } |
1028 | 1099 |
1029 } // namespace test_spdy2 | 1100 } // namespace test_spdy2 |
1030 } // namespace net | 1101 } // namespace net |
OLD | NEW |