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;
20 namespace test_spdy2
{
22 SpdyFrame
* ConstructSpdyWebSocketSynStream(int stream_id
,
26 const char* const kWebSocketHeaders
[] = {
38 return ConstructSpdyControlFrame(/*extra_headers*/ NULL
,
39 /*extra_header_count*/ 0,
46 arraysize(kWebSocketHeaders
));
49 SpdyFrame
* ConstructSpdyWebSocketSynReply(int stream_id
) {
50 static const char* const kStandardWebSocketHeaders
[] = {
54 return ConstructSpdyControlFrame(NULL
,
61 kStandardWebSocketHeaders
,
62 arraysize(kStandardWebSocketHeaders
));
65 SpdyFrame
* ConstructSpdyWebSocketHandshakeRequestFrame(
66 const char* const headers
[],
68 SpdyStreamId stream_id
,
69 RequestPriority request_priority
) {
71 // SPDY SYN_STREAM control frame header.
72 const SpdyHeaderInfo kSynStreamHeader
= {
75 kDefaultAssociatedStreamId
,
76 ConvertRequestPriorityToSpdyPriority(request_priority
, 2),
85 // Construct SPDY SYN_STREAM control frame.
86 return ConstructSpdyPacket(
89 kDefaultExtraHeaderCount
,
94 SpdyFrame
* ConstructSpdyWebSocketHandshakeResponseFrame(
95 const char* const headers
[],
97 SpdyStreamId stream_id
,
98 RequestPriority request_priority
) {
100 // SPDY SYN_REPLY control frame header.
101 const SpdyHeaderInfo kSynReplyHeader
= {
104 kDefaultAssociatedStreamId
,
105 ConvertRequestPriorityToSpdyPriority(request_priority
, 2),
114 // Construct SPDY SYN_REPLY control frame.
115 return ConstructSpdyPacket(
117 kDefaultExtraHeaders
,
118 kDefaultExtraHeaderCount
,
123 SpdyFrame
* ConstructSpdyWebSocketHeadersFrame(int stream_id
,
126 static const char* const kHeaders
[] = {
134 return ConstructSpdyControlFrame(/*extra_headers*/ NULL
,
135 /*extra_header_count*/ 0,
136 /*compression*/ false,
142 arraysize(kHeaders
));
145 SpdyFrame
* ConstructSpdyWebSocketDataFrame(
148 SpdyStreamId stream_id
,
151 // Construct SPDY data frame.
152 BufferedSpdyFramer
framer(2, false);
153 return framer
.CreateDataFrame(
157 fin
? DATA_FLAG_FIN
: DATA_FLAG_NONE
);
160 } // namespace test_spdy2