| 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 #ifndef NET_SPDY_SPDY_TEST_UTIL_SPDY2_H_ | 5 #ifndef NET_SPDY_SPDY_TEST_UTIL_SPDY2_H_ |
| 6 #define NET_SPDY_SPDY_TEST_UTIL_SPDY2_H_ | 6 #define NET_SPDY_SPDY_TEST_UTIL_SPDY2_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/string_piece.h" |
| 9 #include "net/base/cert_verifier.h" | 11 #include "net/base/cert_verifier.h" |
| 10 #include "net/base/host_port_pair.h" | 12 #include "net/base/host_port_pair.h" |
| 11 #include "net/base/mock_host_resolver.h" | 13 #include "net/base/mock_host_resolver.h" |
| 12 #include "net/base/request_priority.h" | 14 #include "net/base/request_priority.h" |
| 13 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
| 14 #include "net/http/http_cache.h" | 16 #include "net/http/http_cache.h" |
| 15 #include "net/http/http_network_layer.h" | 17 #include "net/http/http_network_layer.h" |
| 16 #include "net/http/http_network_session.h" | 18 #include "net/http/http_network_session.h" |
| 17 #include "net/http/http_server_properties_impl.h" | 19 #include "net/http/http_server_properties_impl.h" |
| 18 #include "net/http/http_transaction_factory.h" | 20 #include "net/http/http_transaction_factory.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // Chop a SpdyFrame into an array of MockReads. | 70 // Chop a SpdyFrame into an array of MockReads. |
| 69 // |frame| is the frame to chop. | 71 // |frame| is the frame to chop. |
| 70 // |num_chunks| is the number of chunks to create. | 72 // |num_chunks| is the number of chunks to create. |
| 71 MockRead* ChopReadFrame(const SpdyFrame& frame, int num_chunks); | 73 MockRead* ChopReadFrame(const SpdyFrame& frame, int num_chunks); |
| 72 | 74 |
| 73 // Adds headers and values to a map. | 75 // Adds headers and values to a map. |
| 74 // |extra_headers| is an array of { name, value } pairs, arranged as strings | 76 // |extra_headers| is an array of { name, value } pairs, arranged as strings |
| 75 // where the even entries are the header names, and the odd entries are the | 77 // where the even entries are the header names, and the odd entries are the |
| 76 // header values. | 78 // header values. |
| 77 // |headers| gets filled in from |extra_headers|. | 79 // |headers| gets filled in from |extra_headers|. |
| 78 void AppendHeadersToSpdyFrame(const char* const extra_headers[], | 80 void AppendToHeaderBlock(const char* const extra_headers[], |
| 79 int extra_header_count, | 81 int extra_header_count, |
| 80 SpdyHeaderBlock* headers); | 82 SpdyHeaderBlock* headers); |
| 83 |
| 84 // Constructs a HeaderBlock for a GET request for the given URL. |
| 85 scoped_ptr<SpdyHeaderBlock> ConstructGetHeaderBlock(base::StringPiece url); |
| 86 |
| 87 // Constructs a HeaderBlock for a POST request for the given URL. |
| 88 scoped_ptr<SpdyHeaderBlock> ConstructPostHeaderBlock(base::StringPiece url, |
| 89 int64 content_length); |
| 81 | 90 |
| 82 // Writes |str| of the given |len| to the buffer pointed to by |buffer_handle|. | 91 // Writes |str| of the given |len| to the buffer pointed to by |buffer_handle|. |
| 83 // Uses a template so buffer_handle can be a char* or an unsigned char*. | 92 // Uses a template so buffer_handle can be a char* or an unsigned char*. |
| 84 // Updates the |*buffer_handle| pointer by |len| | 93 // Updates the |*buffer_handle| pointer by |len| |
| 85 // Returns the number of bytes written into *|buffer_handle| | 94 // Returns the number of bytes written into *|buffer_handle| |
| 86 template<class T> | 95 template<class T> |
| 87 int AppendToBuffer(const char* str, | 96 int AppendToBuffer(const char* str, |
| 88 int len, | 97 int len, |
| 89 T** buffer_handle, | 98 T** buffer_handle, |
| 90 int* buffer_len_remaining) { | 99 int* buffer_len_remaining) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 102 | 111 |
| 103 // Writes |val| to a location of size |len|, in big-endian format. | 112 // Writes |val| to a location of size |len|, in big-endian format. |
| 104 // in the buffer pointed to by |buffer_handle|. | 113 // in the buffer pointed to by |buffer_handle|. |
| 105 // Updates the |*buffer_handle| pointer by |len| | 114 // Updates the |*buffer_handle| pointer by |len| |
| 106 // Returns the number of bytes written | 115 // Returns the number of bytes written |
| 107 int AppendToBuffer(int val, | 116 int AppendToBuffer(int val, |
| 108 int len, | 117 int len, |
| 109 unsigned char** buffer_handle, | 118 unsigned char** buffer_handle, |
| 110 int* buffer_len_remaining); | 119 int* buffer_len_remaining); |
| 111 | 120 |
| 112 // Construct a SPDY packet. | 121 // Construct a SPDY frame. |
| 113 // |head| is the start of the packet, up to but not including | 122 SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info, |
| 114 // the header value pairs. | 123 scoped_ptr<SpdyHeaderBlock> headers); |
| 124 |
| 125 // Construct a SPDY frame. |
| 115 // |extra_headers| are the extra header-value pairs, which typically | 126 // |extra_headers| are the extra header-value pairs, which typically |
| 116 // will vary the most between calls. | 127 // will vary the most between calls. |
| 117 // |tail| is any (relatively constant) header-value pairs to add. | 128 // |tail| is any (relatively constant) header-value pairs to add. |
| 118 // |buffer| is the buffer we're filling in. | |
| 119 // Returns a SpdyFrame. | 129 // Returns a SpdyFrame. |
| 120 SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info, | 130 SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info, |
| 121 const char* const extra_headers[], | 131 const char* const extra_headers[], |
| 122 int extra_header_count, | 132 int extra_header_count, |
| 123 const char* const tail[], | 133 const char* const tail[], |
| 124 int tail_header_count); | 134 int tail_header_count); |
| 125 | 135 |
| 126 // Construct a generic SpdyControlFrame. | 136 // Construct a generic SpdyControlFrame. |
| 127 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], | 137 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], |
| 128 int extra_header_count, | 138 int extra_header_count, |
| 129 bool compressed, | 139 bool compressed, |
| 130 int stream_id, | 140 int stream_id, |
| 131 RequestPriority request_priority, | 141 RequestPriority request_priority, |
| 132 SpdyControlType type, | 142 SpdyControlType type, |
| 133 SpdyControlFlags flags, | 143 SpdyControlFlags flags, |
| 134 const char* const* kHeaders, | 144 const char* const* kHeaders, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // |extra_headers| are the extra header-value pairs. | 195 // |extra_headers| are the extra header-value pairs. |
| 186 // |buffer| is the buffer we're filling in. | 196 // |buffer| is the buffer we're filling in. |
| 187 // |index| is the index of the header we want. | 197 // |index| is the index of the header we want. |
| 188 // Returns the number of bytes written into |buffer|. | 198 // Returns the number of bytes written into |buffer|. |
| 189 int ConstructSpdyHeader(const char* const extra_headers[], | 199 int ConstructSpdyHeader(const char* const extra_headers[], |
| 190 int extra_header_count, | 200 int extra_header_count, |
| 191 char* buffer, | 201 char* buffer, |
| 192 int buffer_length, | 202 int buffer_length, |
| 193 int index); | 203 int index); |
| 194 | 204 |
| 195 // Constructs a standard SPDY GET SYN packet, optionally compressed | 205 // Constructs a standard SPDY GET SYN frame, optionally compressed |
| 196 // for the url |url|. | 206 // for the url |url|. |
| 197 // |extra_headers| are the extra header-value pairs, which typically | 207 // |extra_headers| are the extra header-value pairs, which typically |
| 198 // will vary the most between calls. | 208 // will vary the most between calls. |
| 199 // Returns a SpdyFrame. | 209 // Returns a SpdyFrame. |
| 200 SpdyFrame* ConstructSpdyGet(const char* const url, | 210 SpdyFrame* ConstructSpdyGet(const char* const url, |
| 201 bool compressed, | 211 bool compressed, |
| 202 SpdyStreamId stream_id, | 212 SpdyStreamId stream_id, |
| 203 RequestPriority request_priority); | 213 RequestPriority request_priority); |
| 204 | 214 |
| 205 // Constructs a standard SPDY GET SYN packet, optionally compressed. | 215 // Constructs a standard SPDY GET SYN frame, optionally compressed. |
| 206 // |extra_headers| are the extra header-value pairs, which typically | 216 // |extra_headers| are the extra header-value pairs, which typically |
| 207 // will vary the most between calls. | 217 // will vary the most between calls. |
| 208 // Returns a SpdyFrame. | 218 // Returns a SpdyFrame. |
| 209 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 219 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
| 210 int extra_header_count, | 220 int extra_header_count, |
| 211 bool compressed, | 221 bool compressed, |
| 212 int stream_id, | 222 int stream_id, |
| 213 RequestPriority request_priority); | 223 RequestPriority request_priority); |
| 214 | 224 |
| 215 // Constructs a standard SPDY GET SYN packet, optionally compressed. | 225 // Constructs a standard SPDY GET SYN frame, optionally compressed. |
| 216 // |extra_headers| are the extra header-value pairs, which typically | 226 // |extra_headers| are the extra header-value pairs, which typically |
| 217 // will vary the most between calls. If |direct| is false, the | 227 // will vary the most between calls. If |direct| is false, the |
| 218 // the full url will be used instead of simply the path. | 228 // the full url will be used instead of simply the path. |
| 219 // Returns a SpdyFrame. | 229 // Returns a SpdyFrame. |
| 220 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 230 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
| 221 int extra_header_count, | 231 int extra_header_count, |
| 222 bool compressed, | 232 bool compressed, |
| 223 int stream_id, | 233 int stream_id, |
| 224 RequestPriority request_priority, | 234 RequestPriority request_priority, |
| 225 bool direct); | 235 bool direct); |
| 226 | 236 |
| 227 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. | 237 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. |
| 228 SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], | 238 SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], |
| 229 int extra_header_count, | 239 int extra_header_count, |
| 230 int stream_id); | 240 int stream_id); |
| 231 | 241 |
| 232 // Constructs a standard SPDY push SYN packet. | 242 // Constructs a standard SPDY push SYN frame. |
| 233 // |extra_headers| are the extra header-value pairs, which typically | 243 // |extra_headers| are the extra header-value pairs, which typically |
| 234 // will vary the most between calls. | 244 // will vary the most between calls. |
| 235 // Returns a SpdyFrame. | 245 // Returns a SpdyFrame. |
| 236 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 246 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 237 int extra_header_count, | 247 int extra_header_count, |
| 238 int stream_id, | 248 int stream_id, |
| 239 int associated_stream_id); | 249 int associated_stream_id); |
| 240 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 250 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 241 int extra_header_count, | 251 int extra_header_count, |
| 242 int stream_id, | 252 int stream_id, |
| 243 int associated_stream_id, | 253 int associated_stream_id, |
| 244 const char* url); | 254 const char* url); |
| 245 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 255 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 246 int extra_header_count, | 256 int extra_header_count, |
| 247 int stream_id, | 257 int stream_id, |
| 248 int associated_stream_id, | 258 int associated_stream_id, |
| 249 const char* url, | 259 const char* url, |
| 250 const char* status, | 260 const char* status, |
| 251 const char* location); | 261 const char* location); |
| 252 SpdyFrame* ConstructSpdyPush(int stream_id, | 262 SpdyFrame* ConstructSpdyPush(int stream_id, |
| 253 int associated_stream_id, | 263 int associated_stream_id, |
| 254 const char* url); | 264 const char* url); |
| 255 | 265 |
| 256 SpdyFrame* ConstructSpdyPushHeaders(int stream_id, | 266 SpdyFrame* ConstructSpdyPushHeaders(int stream_id, |
| 257 const char* const extra_headers[], | 267 const char* const extra_headers[], |
| 258 int extra_header_count); | 268 int extra_header_count); |
| 259 | 269 |
| 260 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. | 270 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. |
| 261 // |extra_headers| are the extra header-value pairs, which typically | 271 // |extra_headers| are the extra header-value pairs, which typically |
| 262 // will vary the most between calls. | 272 // will vary the most between calls. |
| 263 // Returns a SpdyFrame. | 273 // Returns a SpdyFrame. |
| 264 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], | 274 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], |
| 265 int extra_header_count, | 275 int extra_header_count, |
| 266 int stream_id); | 276 int stream_id); |
| 267 | 277 |
| 268 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. | 278 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. |
| 269 // |extra_headers| are the extra header-value pairs, which typically | 279 // |extra_headers| are the extra header-value pairs, which typically |
| 270 // will vary the most between calls. | 280 // will vary the most between calls. |
| 271 // Returns a SpdyFrame. | 281 // Returns a SpdyFrame. |
| 272 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id); | 282 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id); |
| 273 | 283 |
| 274 // Constructs a standard SPDY SYN_REPLY packet with an Internal Server | 284 // Constructs a standard SPDY SYN_REPLY frame with an Internal Server |
| 275 // Error status code. | 285 // Error status code. |
| 276 // Returns a SpdyFrame. | 286 // Returns a SpdyFrame. |
| 277 SpdyFrame* ConstructSpdySynReplyError(int stream_id); | 287 SpdyFrame* ConstructSpdySynReplyError(int stream_id); |
| 278 | 288 |
| 279 // Constructs a standard SPDY SYN_REPLY packet with the specified status code. | 289 // Constructs a standard SPDY SYN_REPLY frame with the specified status code. |
| 280 // Returns a SpdyFrame. | 290 // Returns a SpdyFrame. |
| 281 SpdyFrame* ConstructSpdySynReplyError(const char* const status, | 291 SpdyFrame* ConstructSpdySynReplyError(const char* const status, |
| 282 const char* const* const extra_headers, | 292 const char* const* const extra_headers, |
| 283 int extra_header_count, | 293 int extra_header_count, |
| 284 int stream_id); | 294 int stream_id); |
| 285 | 295 |
| 286 // Constructs a standard SPDY POST SYN packet. | 296 // Constructs a standard SPDY POST SYN frame. |
| 287 // |extra_headers| are the extra header-value pairs, which typically | 297 // |extra_headers| are the extra header-value pairs, which typically |
| 288 // will vary the most between calls. | 298 // will vary the most between calls. |
| 289 // Returns a SpdyFrame. | 299 // Returns a SpdyFrame. |
| 290 SpdyFrame* ConstructSpdyPost(int64 content_length, | 300 SpdyFrame* ConstructSpdyPost(const char* url, |
| 301 int64 content_length, |
| 291 const char* const extra_headers[], | 302 const char* const extra_headers[], |
| 292 int extra_header_count); | 303 int extra_header_count); |
| 293 | 304 |
| 294 // Constructs a chunked transfer SPDY POST SYN packet. | 305 // Constructs a chunked transfer SPDY POST SYN frame. |
| 295 // |extra_headers| are the extra header-value pairs, which typically | 306 // |extra_headers| are the extra header-value pairs, which typically |
| 296 // will vary the most between calls. | 307 // will vary the most between calls. |
| 297 // Returns a SpdyFrame. | 308 // Returns a SpdyFrame. |
| 298 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], | 309 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], |
| 299 int extra_header_count); | 310 int extra_header_count); |
| 300 | 311 |
| 301 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. | 312 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY POST. |
| 302 // |extra_headers| are the extra header-value pairs, which typically | 313 // |extra_headers| are the extra header-value pairs, which typically |
| 303 // will vary the most between calls. | 314 // will vary the most between calls. |
| 304 // Returns a SpdyFrame. | 315 // Returns a SpdyFrame. |
| 305 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], | 316 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], |
| 306 int extra_header_count); | 317 int extra_header_count); |
| 307 | 318 |
| 308 // Constructs a single SPDY data frame with the contents "hello!" | 319 // Constructs a single SPDY data frame with the contents "hello!" |
| 309 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, | 320 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, |
| 310 bool fin); | 321 bool fin); |
| 311 | 322 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 SpdySessionPool* const pool_; | 428 SpdySessionPool* const pool_; |
| 418 | 429 |
| 419 DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); | 430 DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); |
| 420 }; | 431 }; |
| 421 | 432 |
| 422 } // namespace test_spdy2 | 433 } // namespace test_spdy2 |
| 423 | 434 |
| 424 } // namespace net | 435 } // namespace net |
| 425 | 436 |
| 426 #endif // NET_SPDY_SPDY_TEST_UTIL_SPDY2_H_ | 437 #endif // NET_SPDY_SPDY_TEST_UTIL_SPDY2_H_ |
| OLD | NEW |