Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / net / spdy / spdy_websocket_test_util_spdy2.cc
blob1a459494a1537257d0c97b8d5799e85e2a1c6ba6
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
3 // found in the LICENSE file.
5 #include "net/spdy/spdy_websocket_test_util_spdy2.h"
7 #include "net/spdy/buffered_spdy_framer.h"
8 #include "net/spdy/spdy_http_utils.h"
9 #include "net/spdy/spdy_test_util_spdy2.h"
11 static const int kDefaultAssociatedStreamId = 0;
12 static const bool kDefaultCompressed = false;
13 static const char* const kDefaultDataPointer = NULL;
14 static const uint32 kDefaultDataLength = 0;
15 static const char** const kDefaultExtraHeaders = NULL;
16 static const int kDefaultExtraHeaderCount = 0;
18 namespace net {
20 namespace test_spdy2 {
22 SpdyFrame* ConstructSpdyWebSocketSynStream(int stream_id,
23 const char* path,
24 const char* host,
25 const char* origin) {
26 const char* const kWebSocketHeaders[] = {
27 "path",
28 path,
29 "host",
30 host,
31 "version",
32 "WebSocket/13",
33 "scheme",
34 "ws",
35 "origin",
36 origin
38 return ConstructSpdyControlFrame(/*extra_headers*/ NULL,
39 /*extra_header_count*/ 0,
40 /*compressed*/ false,
41 stream_id,
42 HIGHEST,
43 SYN_STREAM,
44 CONTROL_FLAG_NONE,
45 kWebSocketHeaders,
46 arraysize(kWebSocketHeaders));
49 SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id) {
50 static const char* const kStandardWebSocketHeaders[] = {
51 "status",
52 "101"
54 return ConstructSpdyControlFrame(NULL,
56 false,
57 stream_id,
58 LOWEST,
59 SYN_REPLY,
60 CONTROL_FLAG_NONE,
61 kStandardWebSocketHeaders,
62 arraysize(kStandardWebSocketHeaders));
65 SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame(
66 const char* const headers[],
67 int header_count,
68 SpdyStreamId stream_id,
69 RequestPriority request_priority) {
71 // SPDY SYN_STREAM control frame header.
72 const SpdyHeaderInfo kSynStreamHeader = {
73 SYN_STREAM,
74 stream_id,
75 kDefaultAssociatedStreamId,
76 ConvertRequestPriorityToSpdyPriority(request_priority, 2),
77 CONTROL_FLAG_NONE,
78 kDefaultCompressed,
79 INVALID,
80 kDefaultDataPointer,
81 kDefaultDataLength,
82 DATA_FLAG_NONE
85 // Construct SPDY SYN_STREAM control frame.
86 return ConstructSpdyPacket(
87 kSynStreamHeader,
88 kDefaultExtraHeaders,
89 kDefaultExtraHeaderCount,
90 headers,
91 header_count);
94 SpdyFrame* ConstructSpdyWebSocketHandshakeResponseFrame(
95 const char* const headers[],
96 int header_count,
97 SpdyStreamId stream_id,
98 RequestPriority request_priority) {
100 // SPDY SYN_REPLY control frame header.
101 const SpdyHeaderInfo kSynReplyHeader = {
102 SYN_REPLY,
103 stream_id,
104 kDefaultAssociatedStreamId,
105 ConvertRequestPriorityToSpdyPriority(request_priority, 2),
106 CONTROL_FLAG_NONE,
107 kDefaultCompressed,
108 INVALID,
109 kDefaultDataPointer,
110 kDefaultDataLength,
111 DATA_FLAG_NONE
114 // Construct SPDY SYN_REPLY control frame.
115 return ConstructSpdyPacket(
116 kSynReplyHeader,
117 kDefaultExtraHeaders,
118 kDefaultExtraHeaderCount,
119 headers,
120 header_count);
123 SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id,
124 const char* length,
125 bool fin) {
126 static const char* const kHeaders[] = {
127 "opcode",
128 "1", // text frame
129 "length",
130 length,
131 "fin",
132 fin ? "1" : "0"
134 return ConstructSpdyControlFrame(/*extra_headers*/ NULL,
135 /*extra_header_count*/ 0,
136 /*compression*/ false,
137 stream_id,
138 LOWEST,
139 HEADERS,
140 CONTROL_FLAG_NONE,
141 kHeaders,
142 arraysize(kHeaders));
145 SpdyFrame* ConstructSpdyWebSocketDataFrame(
146 const char* data,
147 int len,
148 SpdyStreamId stream_id,
149 bool fin) {
151 // Construct SPDY data frame.
152 BufferedSpdyFramer framer(2, false);
153 return framer.CreateDataFrame(
154 stream_id,
155 data,
156 len,
157 fin ? DATA_FLAG_FIN : DATA_FLAG_NONE);
160 } // namespace test_spdy2
162 } // namespace net