1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/spdy/spdy_websocket_test_util_spdy3.h"
#include "net/spdy/buffered_spdy_framer.h"
#include "net/spdy/spdy_http_utils.h"
#include "net/spdy/spdy_test_util_spdy3.h"
static const int kDefaultAssociatedStreamId = 0;
static const bool kDefaultCompressed = false;
static const char* const kDefaultDataPointer = NULL;
static const uint32 kDefaultDataLength = 0;
static const char** const kDefaultExtraHeaders = NULL;
static const int kDefaultExtraHeaderCount = 0;
static const int kDefaultCredentialSlot = 0;
namespace net {
namespace test_spdy3 {
SpdyFrame* ConstructSpdyWebSocketSynStream(int stream_id,
const char* path,
const char* host,
const char* origin) {
SpdyTestUtil util(kProtoSPDY3);
const char* const kWebSocketHeaders[] = {
":path",
path,
":host",
host,
":version",
"WebSocket/13",
":scheme",
"ws",
":origin",
origin
};
return util.ConstructSpdyControlFrame(/*extra_headers*/ NULL,
/*extra_header_count*/ 0,
/*compressed*/ false,
stream_id,
HIGHEST,
SYN_STREAM,
CONTROL_FLAG_NONE,
kWebSocketHeaders,
arraysize(kWebSocketHeaders),
0);
}
SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id) {
SpdyTestUtil util(kProtoSPDY3);
static const char* const kStandardWebSocketHeaders[] = {
":status",
"101"
};
return util.ConstructSpdyControlFrame(NULL,
0,
false,
stream_id,
LOWEST,
SYN_REPLY,
CONTROL_FLAG_NONE,
kStandardWebSocketHeaders,
arraysize(kStandardWebSocketHeaders),
0);
}
SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame(
const char* const headers[],
int header_count,
SpdyStreamId stream_id,
RequestPriority request_priority) {
SpdyTestUtil util(kProtoSPDY3);
// SPDY SYN_STREAM control frame header.
const SpdyHeaderInfo kSynStreamHeader = {
SYN_STREAM,
stream_id,
kDefaultAssociatedStreamId,
ConvertRequestPriorityToSpdyPriority(request_priority, 3),
kDefaultCredentialSlot,
CONTROL_FLAG_NONE,
kDefaultCompressed,
RST_STREAM_INVALID,
kDefaultDataPointer,
kDefaultDataLength,
DATA_FLAG_NONE
};
// Construct SPDY SYN_STREAM control frame.
return util.ConstructSpdyFrame(
kSynStreamHeader,
kDefaultExtraHeaders,
kDefaultExtraHeaderCount,
headers,
header_count);
}
SpdyFrame* ConstructSpdyWebSocketHandshakeResponseFrame(
const char* const headers[],
int header_count,
SpdyStreamId stream_id,
RequestPriority request_priority) {
SpdyTestUtil util(kProtoSPDY3);
// SPDY SYN_REPLY control frame header.
const SpdyHeaderInfo kSynReplyHeader = {
SYN_REPLY,
stream_id,
kDefaultAssociatedStreamId,
ConvertRequestPriorityToSpdyPriority(request_priority, 3),
kDefaultCredentialSlot,
CONTROL_FLAG_NONE,
kDefaultCompressed,
RST_STREAM_INVALID,
kDefaultDataPointer,
kDefaultDataLength,
DATA_FLAG_NONE
};
// Construct SPDY SYN_REPLY control frame.
return util.ConstructSpdyFrame(
kSynReplyHeader,
kDefaultExtraHeaders,
kDefaultExtraHeaderCount,
headers,
header_count);
}
SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id,
const char* length,
bool fin) {
SpdyTestUtil util(kProtoSPDY3);
static const char* const kHeaders[] = {
":opcode",
"1", // text frame
":length",
length,
":fin",
fin ? "1" : "0"
};
return util.ConstructSpdyControlFrame(/*extra_headers*/ NULL,
/*extra_header_count*/ 0,
/*compression*/ false,
stream_id,
LOWEST,
HEADERS,
CONTROL_FLAG_NONE,
kHeaders,
arraysize(kHeaders),
0);
}
SpdyFrame* ConstructSpdyWebSocketDataFrame(
const char* data,
int len,
SpdyStreamId stream_id,
bool fin) {
// Construct SPDY data frame.
BufferedSpdyFramer framer(SPDY3, false);
return framer.CreateDataFrame(
stream_id,
data,
len,
fin ? DATA_FLAG_FIN : DATA_FLAG_NONE);
}
} // namespace test_spdy3
} // namespace net
|