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_websocket_test_util_spdy3.h" | 5 #include "net/spdy/spdy_websocket_test_util_spdy3.h" |
6 | 6 |
7 #include "net/spdy/buffered_spdy_framer.h" | 7 #include "net/spdy/buffered_spdy_framer.h" |
8 #include "net/spdy/spdy_http_utils.h" | 8 #include "net/spdy/spdy_http_utils.h" |
9 #include "net/spdy/spdy_test_util_spdy3.h" | 9 #include "net/spdy/spdy_test_util_spdy3.h" |
10 | 10 |
11 static const int kDefaultAssociatedStreamId = 0; | 11 static const int kDefaultAssociatedStreamId = 0; |
12 static const bool kDefaultCompressed = false; | 12 static const bool kDefaultCompressed = false; |
13 static const char* const kDefaultDataPointer = NULL; | 13 static const char* const kDefaultDataPointer = NULL; |
14 static const uint32 kDefaultDataLength = 0; | 14 static const uint32 kDefaultDataLength = 0; |
15 static const char** const kDefaultExtraHeaders = NULL; | 15 static const char** const kDefaultExtraHeaders = NULL; |
16 static const int kDefaultExtraHeaderCount = 0; | 16 static const int kDefaultExtraHeaderCount = 0; |
17 static const int kDefaultCredentialSlot = 0; | 17 static const int kDefaultCredentialSlot = 0; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 namespace test_spdy3 { | 21 namespace test_spdy3 { |
22 | 22 |
| 23 SpdyFrame* ConstructSpdyWebSocketSynStream(int stream_id, |
| 24 const char* path, |
| 25 const char* host, |
| 26 const char* origin) { |
| 27 const char* const kWebSocketHeaders[] = { |
| 28 ":path", |
| 29 path, |
| 30 ":host", |
| 31 host, |
| 32 ":version", |
| 33 "WebSocket/13", |
| 34 ":scheme", |
| 35 "ws", |
| 36 ":origin", |
| 37 origin |
| 38 }; |
| 39 return ConstructSpdyControlFrame(/*extra_headers*/ NULL, |
| 40 /*extra_header_count*/ 0, |
| 41 /*compressed*/ false, |
| 42 stream_id, |
| 43 HIGHEST, |
| 44 SYN_STREAM, |
| 45 CONTROL_FLAG_NONE, |
| 46 kWebSocketHeaders, |
| 47 arraysize(kWebSocketHeaders)); |
| 48 } |
| 49 |
| 50 SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id) { |
| 51 static const char* const kStandardWebSocketHeaders[] = { |
| 52 ":status", |
| 53 "101" |
| 54 }; |
| 55 return ConstructSpdyControlFrame(NULL, |
| 56 0, |
| 57 false, |
| 58 stream_id, |
| 59 LOWEST, |
| 60 SYN_REPLY, |
| 61 CONTROL_FLAG_NONE, |
| 62 kStandardWebSocketHeaders, |
| 63 arraysize(kStandardWebSocketHeaders)); |
| 64 } |
| 65 |
23 SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame( | 66 SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame( |
24 const char* const headers[], | 67 const char* const headers[], |
25 int header_count, | 68 int header_count, |
26 SpdyStreamId stream_id, | 69 SpdyStreamId stream_id, |
27 RequestPriority request_priority) { | 70 RequestPriority request_priority) { |
28 | 71 |
29 // SPDY SYN_STREAM control frame header. | 72 // SPDY SYN_STREAM control frame header. |
30 const SpdyHeaderInfo kSynStreamHeader = { | 73 const SpdyHeaderInfo kSynStreamHeader = { |
31 SYN_STREAM, | 74 SYN_STREAM, |
32 stream_id, | 75 stream_id, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 116 |
74 // Construct SPDY SYN_REPLY control frame. | 117 // Construct SPDY SYN_REPLY control frame. |
75 return ConstructSpdyPacket( | 118 return ConstructSpdyPacket( |
76 kSynReplyHeader, | 119 kSynReplyHeader, |
77 kDefaultExtraHeaders, | 120 kDefaultExtraHeaders, |
78 kDefaultExtraHeaderCount, | 121 kDefaultExtraHeaderCount, |
79 headers, | 122 headers, |
80 header_count); | 123 header_count); |
81 } | 124 } |
82 | 125 |
| 126 SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id, |
| 127 const char* length, |
| 128 bool fin) { |
| 129 static const char* const kHeaders[] = { |
| 130 ":opcode", |
| 131 "1", // text frame |
| 132 ":length", |
| 133 length, |
| 134 ":fin", |
| 135 fin ? "1" : "0" |
| 136 }; |
| 137 return ConstructSpdyControlFrame(/*extra_headers*/ NULL, |
| 138 /*extra_header_count*/ 0, |
| 139 /*compression*/ false, |
| 140 stream_id, |
| 141 LOWEST, |
| 142 HEADERS, |
| 143 CONTROL_FLAG_NONE, |
| 144 kHeaders, |
| 145 arraysize(kHeaders)); |
| 146 } |
| 147 |
83 SpdyFrame* ConstructSpdyWebSocketDataFrame( | 148 SpdyFrame* ConstructSpdyWebSocketDataFrame( |
84 const char* data, | 149 const char* data, |
85 int len, | 150 int len, |
86 SpdyStreamId stream_id, | 151 SpdyStreamId stream_id, |
87 bool fin) { | 152 bool fin) { |
88 | 153 |
89 // Construct SPDY data frame. | 154 // Construct SPDY data frame. |
90 BufferedSpdyFramer framer(3); | 155 BufferedSpdyFramer framer(3); |
91 return framer.CreateDataFrame( | 156 return framer.CreateDataFrame( |
92 stream_id, | 157 stream_id, |
93 data, | 158 data, |
94 len, | 159 len, |
95 fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); | 160 fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); |
96 } | 161 } |
97 | 162 |
98 } // namespace test_spdy3 | 163 } // namespace test_spdy3 |
99 | 164 |
100 } // namespace net | 165 } // namespace net |
OLD | NEW |