| 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_test_util_spdy2.h" | 5 #include "net/spdy/spdy_test_util_spdy2.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 int extra_header_count, | 112 int extra_header_count, |
| 113 const char* const tail[], | 113 const char* const tail[], |
| 114 int tail_header_count) { | 114 int tail_header_count) { |
| 115 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 115 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
| 116 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); | 116 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); |
| 117 if (tail && tail_header_count) | 117 if (tail && tail_header_count) |
| 118 AppendToHeaderBlock(tail, tail_header_count, headers.get()); | 118 AppendToHeaderBlock(tail, tail_header_count, headers.get()); |
| 119 return ConstructSpdyFrame(header_info, headers.Pass()); | 119 return ConstructSpdyFrame(header_info, headers.Pass()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Construct an expected SPDY SETTINGS frame. | |
| 123 // |settings| are the settings to set. | |
| 124 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 125 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) { | 122 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) { |
| 126 BufferedSpdyFramer framer(2, false); | 123 BufferedSpdyFramer framer(2, false); |
| 127 return framer.CreateSettings(settings); | 124 return framer.CreateSettings(settings); |
| 128 } | 125 } |
| 129 | 126 |
| 130 // Construct an expected SPDY CREDENTIAL frame. | |
| 131 // |credential| is the credential to sen. | |
| 132 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 133 SpdyFrame* ConstructSpdyCredential( | 127 SpdyFrame* ConstructSpdyCredential( |
| 134 const SpdyCredential& credential) { | 128 const SpdyCredential& credential) { |
| 135 BufferedSpdyFramer framer(2, false); | 129 BufferedSpdyFramer framer(2, false); |
| 136 return framer.CreateCredentialFrame(credential); | 130 return framer.CreateCredentialFrame(credential); |
| 137 } | 131 } |
| 138 | 132 |
| 139 // Construct a SPDY PING frame. | |
| 140 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 141 SpdyFrame* ConstructSpdyPing(uint32 ping_id) { | 133 SpdyFrame* ConstructSpdyPing(uint32 ping_id) { |
| 142 BufferedSpdyFramer framer(2, false); | 134 BufferedSpdyFramer framer(2, false); |
| 143 return framer.CreatePingFrame(ping_id); | 135 return framer.CreatePingFrame(ping_id); |
| 144 } | 136 } |
| 145 | 137 |
| 146 // Construct a SPDY GOAWAY frame. | |
| 147 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 148 SpdyFrame* ConstructSpdyGoAway() { | 138 SpdyFrame* ConstructSpdyGoAway() { |
| 149 BufferedSpdyFramer framer(2, false); | 139 return ConstructSpdyGoAway(0); |
| 150 return framer.CreateGoAway(0, GOAWAY_OK); | |
| 151 } | 140 } |
| 152 | 141 |
| 153 // Construct a SPDY WINDOW_UPDATE frame. | 142 SpdyFrame* ConstructSpdyGoAway(SpdyStreamId last_good_stream_id) { |
| 154 // Returns the constructed frame. The caller takes ownership of the frame. | 143 BufferedSpdyFramer framer(2, false); |
| 144 return framer.CreateGoAway(last_good_stream_id, GOAWAY_OK); |
| 145 } |
| 146 |
| 155 SpdyFrame* ConstructSpdyWindowUpdate( | 147 SpdyFrame* ConstructSpdyWindowUpdate( |
| 156 const SpdyStreamId stream_id, uint32 delta_window_size) { | 148 const SpdyStreamId stream_id, uint32 delta_window_size) { |
| 157 BufferedSpdyFramer framer(2, false); | 149 BufferedSpdyFramer framer(2, false); |
| 158 return framer.CreateWindowUpdate(stream_id, delta_window_size); | 150 return framer.CreateWindowUpdate(stream_id, delta_window_size); |
| 159 } | 151 } |
| 160 | 152 |
| 161 // Construct a SPDY RST_STREAM frame. | |
| 162 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 163 SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, | 153 SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, |
| 164 SpdyRstStreamStatus status) { | 154 SpdyRstStreamStatus status) { |
| 165 BufferedSpdyFramer framer(2, false); | 155 BufferedSpdyFramer framer(2, false); |
| 166 return framer.CreateRstStream(stream_id, status); | 156 return framer.CreateRstStream(stream_id, status); |
| 167 } | 157 } |
| 168 | 158 |
| 169 // Construct a single SPDY header entry, for validation. | |
| 170 // |extra_headers| are the extra header-value pairs. | |
| 171 // |buffer| is the buffer we're filling in. | |
| 172 // |index| is the index of the header we want. | |
| 173 // Returns the number of bytes written into |buffer|. | |
| 174 int ConstructSpdyHeader(const char* const extra_headers[], | 159 int ConstructSpdyHeader(const char* const extra_headers[], |
| 175 int extra_header_count, | 160 int extra_header_count, |
| 176 char* buffer, | 161 char* buffer, |
| 177 int buffer_length, | 162 int buffer_length, |
| 178 int index) { | 163 int index) { |
| 179 const char* this_header = NULL; | 164 const char* this_header = NULL; |
| 180 const char* this_value = NULL; | 165 const char* this_value = NULL; |
| 181 if (!buffer || !buffer_length) | 166 if (!buffer || !buffer_length) |
| 182 return 0; | 167 return 0; |
| 183 *buffer = '\0'; | 168 *buffer = '\0'; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 0, // Length | 239 0, // Length |
| 255 DATA_FLAG_NONE // Data Flags | 240 DATA_FLAG_NONE // Data Flags |
| 256 }; | 241 }; |
| 257 return ConstructSpdyFrame(kSynStartHeader, | 242 return ConstructSpdyFrame(kSynStartHeader, |
| 258 extra_headers, | 243 extra_headers, |
| 259 extra_header_count, | 244 extra_header_count, |
| 260 kHeaders, | 245 kHeaders, |
| 261 kHeadersSize / 2); | 246 kHeadersSize / 2); |
| 262 } | 247 } |
| 263 | 248 |
| 264 // Constructs a standard SPDY GET SYN frame, optionally compressed | |
| 265 // for the url |url|. | |
| 266 // |extra_headers| are the extra header-value pairs, which typically | |
| 267 // will vary the most between calls. | |
| 268 // Returns a SpdyFrame. | |
| 269 SpdyFrame* ConstructSpdyGet(const char* const url, | 249 SpdyFrame* ConstructSpdyGet(const char* const url, |
| 270 bool compressed, | 250 bool compressed, |
| 271 SpdyStreamId stream_id, | 251 SpdyStreamId stream_id, |
| 272 RequestPriority request_priority) { | 252 RequestPriority request_priority) { |
| 273 const SpdyHeaderInfo kSynStartHeader = { | 253 const SpdyHeaderInfo kSynStartHeader = { |
| 274 SYN_STREAM, // Kind = Syn | 254 SYN_STREAM, // Kind = Syn |
| 275 stream_id, // Stream ID | 255 stream_id, // Stream ID |
| 276 0, // Associated stream ID | 256 0, // Associated stream ID |
| 277 ConvertRequestPriorityToSpdyPriority(request_priority, 2), | 257 ConvertRequestPriorityToSpdyPriority(request_priority, 2), |
| 278 // Priority | 258 // Priority |
| 279 CONTROL_FLAG_FIN, // Control Flags | 259 CONTROL_FLAG_FIN, // Control Flags |
| 280 compressed, // Compressed | 260 compressed, // Compressed |
| 281 RST_STREAM_INVALID, // Status | 261 RST_STREAM_INVALID, // Status |
| 282 NULL, // Data | 262 NULL, // Data |
| 283 0, // Length | 263 0, // Length |
| 284 DATA_FLAG_NONE // Data Flags | 264 DATA_FLAG_NONE // Data Flags |
| 285 }; | 265 }; |
| 286 return ConstructSpdyFrame(kSynStartHeader, ConstructGetHeaderBlock(url)); | 266 return ConstructSpdyFrame(kSynStartHeader, ConstructGetHeaderBlock(url)); |
| 287 } | 267 } |
| 288 | 268 |
| 289 // Constructs a standard SPDY GET SYN frame, optionally compressed. | |
| 290 // |extra_headers| are the extra header-value pairs, which typically | |
| 291 // will vary the most between calls. | |
| 292 // Returns a SpdyFrame. | |
| 293 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 269 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
| 294 int extra_header_count, | 270 int extra_header_count, |
| 295 bool compressed, | 271 bool compressed, |
| 296 int stream_id, | 272 int stream_id, |
| 297 RequestPriority request_priority) { | 273 RequestPriority request_priority) { |
| 298 return ConstructSpdyGet(extra_headers, extra_header_count, compressed, | 274 return ConstructSpdyGet(extra_headers, extra_header_count, compressed, |
| 299 stream_id, request_priority, true); | 275 stream_id, request_priority, true); |
| 300 } | 276 } |
| 301 | 277 |
| 302 // Constructs a standard SPDY GET SYN frame, optionally compressed. | |
| 303 // |extra_headers| are the extra header-value pairs, which typically | |
| 304 // will vary the most between calls. | |
| 305 // Returns a SpdyFrame. | |
| 306 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 278 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
| 307 int extra_header_count, | 279 int extra_header_count, |
| 308 bool compressed, | 280 bool compressed, |
| 309 int stream_id, | 281 int stream_id, |
| 310 RequestPriority request_priority, | 282 RequestPriority request_priority, |
| 311 bool direct) { | 283 bool direct) { |
| 312 const char* const kStandardGetHeaders[] = { | 284 const char* const kStandardGetHeaders[] = { |
| 313 "method", "GET", | 285 "method", "GET", |
| 314 "url", (direct ? "/" : "http://www.google.com/"), | 286 "url", (direct ? "/" : "http://www.google.com/"), |
| 315 "host", "www.google.com", | 287 "host", "www.google.com", |
| 316 "scheme", "http", | 288 "scheme", "http", |
| 317 "version", "HTTP/1.1" | 289 "version", "HTTP/1.1" |
| 318 }; | 290 }; |
| 319 return ConstructSpdyControlFrame(extra_headers, | 291 return ConstructSpdyControlFrame(extra_headers, |
| 320 extra_header_count, | 292 extra_header_count, |
| 321 compressed, | 293 compressed, |
| 322 stream_id, | 294 stream_id, |
| 323 request_priority, | 295 request_priority, |
| 324 SYN_STREAM, | 296 SYN_STREAM, |
| 325 CONTROL_FLAG_FIN, | 297 CONTROL_FLAG_FIN, |
| 326 kStandardGetHeaders, | 298 kStandardGetHeaders, |
| 327 arraysize(kStandardGetHeaders)); | 299 arraysize(kStandardGetHeaders)); |
| 328 } | 300 } |
| 329 | 301 |
| 330 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. | |
| 331 SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], | 302 SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], |
| 332 int extra_header_count, | 303 int extra_header_count, |
| 333 int stream_id) { | 304 int stream_id) { |
| 334 const char* const kConnectHeaders[] = { | 305 const char* const kConnectHeaders[] = { |
| 335 "method", "CONNECT", | 306 "method", "CONNECT", |
| 336 "url", "www.google.com:443", | 307 "url", "www.google.com:443", |
| 337 "host", "www.google.com", | 308 "host", "www.google.com", |
| 338 "version", "HTTP/1.1", | 309 "version", "HTTP/1.1", |
| 339 }; | 310 }; |
| 340 return ConstructSpdyControlFrame(extra_headers, | 311 return ConstructSpdyControlFrame(extra_headers, |
| 341 extra_header_count, | 312 extra_header_count, |
| 342 /*compressed*/ false, | 313 /*compressed*/ false, |
| 343 stream_id, | 314 stream_id, |
| 344 LOWEST, | 315 LOWEST, |
| 345 SYN_STREAM, | 316 SYN_STREAM, |
| 346 CONTROL_FLAG_NONE, | 317 CONTROL_FLAG_NONE, |
| 347 kConnectHeaders, | 318 kConnectHeaders, |
| 348 arraysize(kConnectHeaders)); | 319 arraysize(kConnectHeaders)); |
| 349 } | 320 } |
| 350 | 321 |
| 351 // Constructs a standard SPDY push SYN frame. | |
| 352 // |extra_headers| are the extra header-value pairs, which typically | |
| 353 // will vary the most between calls. | |
| 354 // Returns a SpdyFrame. | |
| 355 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 322 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 356 int extra_header_count, | 323 int extra_header_count, |
| 357 int stream_id, | 324 int stream_id, |
| 358 int associated_stream_id) { | 325 int associated_stream_id) { |
| 359 const char* const kStandardGetHeaders[] = { | 326 const char* const kStandardGetHeaders[] = { |
| 360 "hello", "bye", | 327 "hello", "bye", |
| 361 "status", "200", | 328 "status", "200", |
| 362 "version", "HTTP/1.1" | 329 "version", "HTTP/1.1" |
| 363 }; | 330 }; |
| 364 return ConstructSpdyControlFrame(extra_headers, | 331 return ConstructSpdyControlFrame(extra_headers, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 extra_header_count, | 418 extra_header_count, |
| 452 false, | 419 false, |
| 453 stream_id, | 420 stream_id, |
| 454 LOWEST, | 421 LOWEST, |
| 455 HEADERS, | 422 HEADERS, |
| 456 CONTROL_FLAG_NONE, | 423 CONTROL_FLAG_NONE, |
| 457 kStandardGetHeaders, | 424 kStandardGetHeaders, |
| 458 arraysize(kStandardGetHeaders)); | 425 arraysize(kStandardGetHeaders)); |
| 459 } | 426 } |
| 460 | 427 |
| 461 // Constructs a standard SPDY SYN_REPLY frame with the specified status code. | |
| 462 // Returns a SpdyFrame. | |
| 463 SpdyFrame* ConstructSpdySynReplyError(const char* const status, | 428 SpdyFrame* ConstructSpdySynReplyError(const char* const status, |
| 464 const char* const* const extra_headers, | 429 const char* const* const extra_headers, |
| 465 int extra_header_count, | 430 int extra_header_count, |
| 466 int stream_id) { | 431 int stream_id) { |
| 467 const char* const kStandardGetHeaders[] = { | 432 const char* const kStandardGetHeaders[] = { |
| 468 "hello", "bye", | 433 "hello", "bye", |
| 469 "status", status, | 434 "status", status, |
| 470 "version", "HTTP/1.1" | 435 "version", "HTTP/1.1" |
| 471 }; | 436 }; |
| 472 return ConstructSpdyControlFrame(extra_headers, | 437 return ConstructSpdyControlFrame(extra_headers, |
| 473 extra_header_count, | 438 extra_header_count, |
| 474 false, | 439 false, |
| 475 stream_id, | 440 stream_id, |
| 476 LOWEST, | 441 LOWEST, |
| 477 SYN_REPLY, | 442 SYN_REPLY, |
| 478 CONTROL_FLAG_NONE, | 443 CONTROL_FLAG_NONE, |
| 479 kStandardGetHeaders, | 444 kStandardGetHeaders, |
| 480 arraysize(kStandardGetHeaders)); | 445 arraysize(kStandardGetHeaders)); |
| 481 } | 446 } |
| 482 | 447 |
| 483 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. | |
| 484 // |extra_headers| are the extra header-value pairs, which typically | |
| 485 // will vary the most between calls. | |
| 486 // Returns a SpdyFrame. | |
| 487 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) { | 448 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) { |
| 488 static const char* const kExtraHeaders[] = { | 449 static const char* const kExtraHeaders[] = { |
| 489 "location", "http://www.foo.com/index.php", | 450 "location", "http://www.foo.com/index.php", |
| 490 }; | 451 }; |
| 491 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, | 452 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, |
| 492 arraysize(kExtraHeaders)/2, stream_id); | 453 arraysize(kExtraHeaders)/2, stream_id); |
| 493 } | 454 } |
| 494 | 455 |
| 495 // Constructs a standard SPDY SYN_REPLY frame with an Internal Server | |
| 496 // Error status code. | |
| 497 // Returns a SpdyFrame. | |
| 498 SpdyFrame* ConstructSpdySynReplyError(int stream_id) { | 456 SpdyFrame* ConstructSpdySynReplyError(int stream_id) { |
| 499 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); | 457 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); |
| 500 } | 458 } |
| 501 | 459 |
| 502 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. | |
| 503 // |extra_headers| are the extra header-value pairs, which typically | |
| 504 // will vary the most between calls. | |
| 505 // Returns a SpdyFrame. | |
| 506 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], | 460 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], |
| 507 int extra_header_count, | 461 int extra_header_count, |
| 508 int stream_id) { | 462 int stream_id) { |
| 509 static const char* const kStandardGetHeaders[] = { | 463 static const char* const kStandardGetHeaders[] = { |
| 510 "hello", "bye", | 464 "hello", "bye", |
| 511 "status", "200", | 465 "status", "200", |
| 512 "version", "HTTP/1.1" | 466 "version", "HTTP/1.1" |
| 513 }; | 467 }; |
| 514 return ConstructSpdyControlFrame(extra_headers, | 468 return ConstructSpdyControlFrame(extra_headers, |
| 515 extra_header_count, | 469 extra_header_count, |
| 516 false, | 470 false, |
| 517 stream_id, | 471 stream_id, |
| 518 LOWEST, | 472 LOWEST, |
| 519 SYN_REPLY, | 473 SYN_REPLY, |
| 520 CONTROL_FLAG_NONE, | 474 CONTROL_FLAG_NONE, |
| 521 kStandardGetHeaders, | 475 kStandardGetHeaders, |
| 522 arraysize(kStandardGetHeaders)); | 476 arraysize(kStandardGetHeaders)); |
| 523 } | 477 } |
| 524 | 478 |
| 525 // Constructs a standard SPDY POST SYN frame. | |
| 526 // |content_length| is the size of post data. | |
| 527 // |extra_headers| are the extra header-value pairs, which typically | |
| 528 // will vary the most between calls. | |
| 529 // Returns a SpdyFrame. | |
| 530 SpdyFrame* ConstructSpdyPost(const char* url, | 479 SpdyFrame* ConstructSpdyPost(const char* url, |
| 531 int64 content_length, | 480 int64 content_length, |
| 532 const char* const extra_headers[], | 481 const char* const extra_headers[], |
| 533 int extra_header_count) { | 482 int extra_header_count) { |
| 534 const SpdyHeaderInfo kSynStartHeader = { | 483 const SpdyHeaderInfo kSynStartHeader = { |
| 535 SYN_STREAM, // Kind = Syn | 484 SYN_STREAM, // Kind = Syn |
| 536 1, // Stream ID | 485 1, // Stream ID |
| 537 0, // Associated stream ID | 486 0, // Associated stream ID |
| 538 ConvertRequestPriorityToSpdyPriority(LOWEST, 2), | 487 ConvertRequestPriorityToSpdyPriority(LOWEST, 2), |
| 539 // Priority | 488 // Priority |
| 540 CONTROL_FLAG_NONE, // Control Flags | 489 CONTROL_FLAG_NONE, // Control Flags |
| 541 false, // Compressed | 490 false, // Compressed |
| 542 RST_STREAM_INVALID, // Status | 491 RST_STREAM_INVALID, // Status |
| 543 NULL, // Data | 492 NULL, // Data |
| 544 0, // Length | 493 0, // Length |
| 545 DATA_FLAG_NONE // Data Flags | 494 DATA_FLAG_NONE // Data Flags |
| 546 }; | 495 }; |
| 547 return ConstructSpdyFrame( | 496 return ConstructSpdyFrame( |
| 548 kSynStartHeader, ConstructPostHeaderBlock(url, content_length)); | 497 kSynStartHeader, ConstructPostHeaderBlock(url, content_length)); |
| 549 } | 498 } |
| 550 | 499 |
| 551 // Constructs a chunked transfer SPDY POST SYN frame. | |
| 552 // |extra_headers| are the extra header-value pairs, which typically | |
| 553 // will vary the most between calls. | |
| 554 // Returns a SpdyFrame. | |
| 555 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], | 500 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], |
| 556 int extra_header_count) { | 501 int extra_header_count) { |
| 557 const char* post_headers[] = { | 502 const char* post_headers[] = { |
| 558 "method", "POST", | 503 "method", "POST", |
| 559 "url", "/", | 504 "url", "/", |
| 560 "host", "www.google.com", | 505 "host", "www.google.com", |
| 561 "scheme", "http", | 506 "scheme", "http", |
| 562 "version", "HTTP/1.1" | 507 "version", "HTTP/1.1" |
| 563 }; | 508 }; |
| 564 return ConstructSpdyControlFrame(extra_headers, | 509 return ConstructSpdyControlFrame(extra_headers, |
| 565 extra_header_count, | 510 extra_header_count, |
| 566 false, | 511 false, |
| 567 1, | 512 1, |
| 568 LOWEST, | 513 LOWEST, |
| 569 SYN_STREAM, | 514 SYN_STREAM, |
| 570 CONTROL_FLAG_NONE, | 515 CONTROL_FLAG_NONE, |
| 571 post_headers, | 516 post_headers, |
| 572 arraysize(post_headers)); | 517 arraysize(post_headers)); |
| 573 } | 518 } |
| 574 | 519 |
| 575 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY POST. | |
| 576 // |extra_headers| are the extra header-value pairs, which typically | |
| 577 // will vary the most between calls. | |
| 578 // Returns a SpdyFrame. | |
| 579 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], | 520 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], |
| 580 int extra_header_count) { | 521 int extra_header_count) { |
| 581 static const char* const kStandardGetHeaders[] = { | 522 static const char* const kStandardGetHeaders[] = { |
| 582 "hello", "bye", | 523 "hello", "bye", |
| 583 "status", "200", | 524 "status", "200", |
| 584 "url", "/index.php", | 525 "url", "/index.php", |
| 585 "version", "HTTP/1.1" | 526 "version", "HTTP/1.1" |
| 586 }; | 527 }; |
| 587 return ConstructSpdyControlFrame(extra_headers, | 528 return ConstructSpdyControlFrame(extra_headers, |
| 588 extra_header_count, | 529 extra_header_count, |
| 589 false, | 530 false, |
| 590 1, | 531 1, |
| 591 LOWEST, | 532 LOWEST, |
| 592 SYN_REPLY, | 533 SYN_REPLY, |
| 593 CONTROL_FLAG_NONE, | 534 CONTROL_FLAG_NONE, |
| 594 kStandardGetHeaders, | 535 kStandardGetHeaders, |
| 595 arraysize(kStandardGetHeaders)); | 536 arraysize(kStandardGetHeaders)); |
| 596 } | 537 } |
| 597 | 538 |
| 598 // Constructs a single SPDY data frame with the default contents. | |
| 599 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, bool fin) { | 539 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, bool fin) { |
| 600 BufferedSpdyFramer framer(2, false); | 540 BufferedSpdyFramer framer(2, false); |
| 601 return framer.CreateDataFrame( | 541 return framer.CreateDataFrame( |
| 602 stream_id, kUploadData, kUploadDataSize, | 542 stream_id, kUploadData, kUploadDataSize, |
| 603 fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); | 543 fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); |
| 604 } | 544 } |
| 605 | 545 |
| 606 // Constructs a single SPDY data frame with the given content. | |
| 607 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, | 546 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, |
| 608 uint32 len, bool fin) { | 547 uint32 len, bool fin) { |
| 609 BufferedSpdyFramer framer(2, false); | 548 BufferedSpdyFramer framer(2, false); |
| 610 return framer.CreateDataFrame( | 549 return framer.CreateDataFrame( |
| 611 stream_id, data, len, fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); | 550 stream_id, data, len, fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); |
| 612 } | 551 } |
| 613 | 552 |
| 614 // Wraps |frame| in the payload of a data frame in stream |stream_id|. | |
| 615 SpdyFrame* ConstructWrappedSpdyFrame(const scoped_ptr<SpdyFrame>& frame, | 553 SpdyFrame* ConstructWrappedSpdyFrame(const scoped_ptr<SpdyFrame>& frame, |
| 616 int stream_id) { | 554 int stream_id) { |
| 617 return ConstructSpdyBodyFrame(stream_id, frame->data(), | 555 return ConstructSpdyBodyFrame(stream_id, frame->data(), |
| 618 frame->size(), false); | 556 frame->size(), false); |
| 619 } | 557 } |
| 620 | 558 |
| 621 // Construct an expected SPDY reply string. | |
| 622 // |extra_headers| are the extra header-value pairs, which typically | |
| 623 // will vary the most between calls. | |
| 624 // |buffer| is the buffer we're filling in. | |
| 625 // Returns the number of bytes written into |buffer|. | |
| 626 int ConstructSpdyReplyString(const char* const extra_headers[], | 559 int ConstructSpdyReplyString(const char* const extra_headers[], |
| 627 int extra_header_count, | 560 int extra_header_count, |
| 628 char* buffer, | 561 char* buffer, |
| 629 int buffer_length) { | 562 int buffer_length) { |
| 630 int frame_size = 0; | 563 int frame_size = 0; |
| 631 char* buffer_write = buffer; | 564 char* buffer_write = buffer; |
| 632 int buffer_left = buffer_length; | 565 int buffer_left = buffer_length; |
| 633 SpdyHeaderBlock headers; | 566 SpdyHeaderBlock headers; |
| 634 if (!buffer || !buffer_length) | 567 if (!buffer || !buffer_length) |
| 635 return 0; | 568 return 0; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 RST_STREAM_INVALID, // Status | 759 RST_STREAM_INVALID, // Status |
| 827 NULL, // Data | 760 NULL, // Data |
| 828 0, // Length | 761 0, // Length |
| 829 DATA_FLAG_NONE // Data Flags | 762 DATA_FLAG_NONE // Data Flags |
| 830 }; | 763 }; |
| 831 return kHeader; | 764 return kHeader; |
| 832 } | 765 } |
| 833 | 766 |
| 834 } // namespace test_spdy2 | 767 } // namespace test_spdy2 |
| 835 } // namespace net | 768 } // namespace net |
| OLD | NEW |