| 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_spdy3.h" | 5 #include "net/spdy/spdy_test_util_spdy3.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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 int extra_header_count, | 166 int extra_header_count, |
| 167 const char* const tail[], | 167 const char* const tail[], |
| 168 int tail_header_count) { | 168 int tail_header_count) { |
| 169 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 169 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
| 170 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); | 170 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); |
| 171 if (tail && tail_header_count) | 171 if (tail && tail_header_count) |
| 172 AppendToHeaderBlock(tail, tail_header_count, headers.get()); | 172 AppendToHeaderBlock(tail, tail_header_count, headers.get()); |
| 173 return ConstructSpdyFrame(header_info, headers.Pass()); | 173 return ConstructSpdyFrame(header_info, headers.Pass()); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Construct an expected SPDY SETTINGS frame. | |
| 177 // |settings| are the settings to set. | |
| 178 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 179 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) { | 176 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) { |
| 180 BufferedSpdyFramer framer(3, false); | 177 BufferedSpdyFramer framer(3, false); |
| 181 return framer.CreateSettings(settings); | 178 return framer.CreateSettings(settings); |
| 182 } | 179 } |
| 183 | 180 |
| 184 // Construct an expected SPDY CREDENTIAL frame. | |
| 185 // |credential| is the credential to sen. | |
| 186 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 187 SpdyFrame* ConstructSpdyCredential( | 181 SpdyFrame* ConstructSpdyCredential( |
| 188 const SpdyCredential& credential) { | 182 const SpdyCredential& credential) { |
| 189 BufferedSpdyFramer framer(3, false); | 183 BufferedSpdyFramer framer(3, false); |
| 190 return framer.CreateCredentialFrame(credential); | 184 return framer.CreateCredentialFrame(credential); |
| 191 } | 185 } |
| 192 | 186 |
| 193 // Construct a SPDY PING frame. | |
| 194 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 195 SpdyFrame* ConstructSpdyPing(uint32 ping_id) { | 187 SpdyFrame* ConstructSpdyPing(uint32 ping_id) { |
| 196 BufferedSpdyFramer framer(3, false); | 188 BufferedSpdyFramer framer(3, false); |
| 197 return framer.CreatePingFrame(ping_id); | 189 return framer.CreatePingFrame(ping_id); |
| 198 } | 190 } |
| 199 | 191 |
| 200 // Construct a SPDY GOAWAY frame. | |
| 201 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 202 SpdyFrame* ConstructSpdyGoAway() { | 192 SpdyFrame* ConstructSpdyGoAway() { |
| 203 BufferedSpdyFramer framer(3, false); | 193 return ConstructSpdyGoAway(0); |
| 204 return framer.CreateGoAway(0, GOAWAY_OK); | |
| 205 } | 194 } |
| 206 | 195 |
| 207 // Construct a SPDY WINDOW_UPDATE frame. | 196 SpdyFrame* ConstructSpdyGoAway(SpdyStreamId last_good_stream_id) { |
| 208 // Returns the constructed frame. The caller takes ownership of the frame. | 197 BufferedSpdyFramer framer(3, false); |
| 198 return framer.CreateGoAway(last_good_stream_id, GOAWAY_OK); |
| 199 } |
| 200 |
| 209 SpdyFrame* ConstructSpdyWindowUpdate( | 201 SpdyFrame* ConstructSpdyWindowUpdate( |
| 210 const SpdyStreamId stream_id, uint32 delta_window_size) { | 202 const SpdyStreamId stream_id, uint32 delta_window_size) { |
| 211 BufferedSpdyFramer framer(3, false); | 203 BufferedSpdyFramer framer(3, false); |
| 212 return framer.CreateWindowUpdate(stream_id, delta_window_size); | 204 return framer.CreateWindowUpdate(stream_id, delta_window_size); |
| 213 } | 205 } |
| 214 | 206 |
| 215 // Construct a SPDY RST_STREAM frame. | |
| 216 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 217 SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, | 207 SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, |
| 218 SpdyRstStreamStatus status) { | 208 SpdyRstStreamStatus status) { |
| 219 BufferedSpdyFramer framer(3, false); | 209 BufferedSpdyFramer framer(3, false); |
| 220 return framer.CreateRstStream(stream_id, status); | 210 return framer.CreateRstStream(stream_id, status); |
| 221 } | 211 } |
| 222 | 212 |
| 223 // Construct a single SPDY header entry, for validation. | |
| 224 // |extra_headers| are the extra header-value pairs. | |
| 225 // |buffer| is the buffer we're filling in. | |
| 226 // |index| is the index of the header we want. | |
| 227 // Returns the number of bytes written into |buffer|. | |
| 228 int ConstructSpdyHeader(const char* const extra_headers[], | 213 int ConstructSpdyHeader(const char* const extra_headers[], |
| 229 int extra_header_count, | 214 int extra_header_count, |
| 230 char* buffer, | 215 char* buffer, |
| 231 int buffer_length, | 216 int buffer_length, |
| 232 int index) { | 217 int index) { |
| 233 const char* this_header = NULL; | 218 const char* this_header = NULL; |
| 234 const char* this_value = NULL; | 219 const char* this_value = NULL; |
| 235 if (!buffer || !buffer_length) | 220 if (!buffer || !buffer_length) |
| 236 return 0; | 221 return 0; |
| 237 *buffer = '\0'; | 222 *buffer = '\0'; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 compressed, | 320 compressed, |
| 336 stream_id, | 321 stream_id, |
| 337 request_priority, | 322 request_priority, |
| 338 type, | 323 type, |
| 339 flags, | 324 flags, |
| 340 kHeaders, | 325 kHeaders, |
| 341 kHeadersSize, | 326 kHeadersSize, |
| 342 associated_stream_id); | 327 associated_stream_id); |
| 343 } | 328 } |
| 344 | 329 |
| 345 // Constructs a standard SPDY GET SYN frame, optionally compressed | |
| 346 // for the url |url|. | |
| 347 // |extra_headers| are the extra header-value pairs, which typically | |
| 348 // will vary the most between calls. | |
| 349 // Returns a SpdyFrame. | |
| 350 SpdyFrame* ConstructSpdyGet(const char* const url, | 330 SpdyFrame* ConstructSpdyGet(const char* const url, |
| 351 bool compressed, | 331 bool compressed, |
| 352 SpdyStreamId stream_id, | 332 SpdyStreamId stream_id, |
| 353 RequestPriority request_priority) { | 333 RequestPriority request_priority) { |
| 354 const SpdyHeaderInfo kSynStartHeader = { | 334 const SpdyHeaderInfo kSynStartHeader = { |
| 355 SYN_STREAM, // Kind = Syn | 335 SYN_STREAM, // Kind = Syn |
| 356 stream_id, // Stream ID | 336 stream_id, // Stream ID |
| 357 0, // Associated stream ID | 337 0, // Associated stream ID |
| 358 ConvertRequestPriorityToSpdyPriority(request_priority, 3), | 338 ConvertRequestPriorityToSpdyPriority(request_priority, 3), |
| 359 // Priority | 339 // Priority |
| 360 0, // Credential Slot | 340 0, // Credential Slot |
| 361 CONTROL_FLAG_FIN, // Control Flags | 341 CONTROL_FLAG_FIN, // Control Flags |
| 362 compressed, // Compressed | 342 compressed, // Compressed |
| 363 RST_STREAM_INVALID, // Status | 343 RST_STREAM_INVALID, // Status |
| 364 NULL, // Data | 344 NULL, // Data |
| 365 0, // Length | 345 0, // Length |
| 366 DATA_FLAG_NONE // Data Flags | 346 DATA_FLAG_NONE // Data Flags |
| 367 }; | 347 }; |
| 368 return ConstructSpdyFrame(kSynStartHeader, ConstructGetHeaderBlock(url)); | 348 return ConstructSpdyFrame(kSynStartHeader, ConstructGetHeaderBlock(url)); |
| 369 } | 349 } |
| 370 | 350 |
| 371 // Constructs a standard SPDY GET SYN frame, optionally compressed. | |
| 372 // |extra_headers| are the extra header-value pairs, which typically | |
| 373 // will vary the most between calls. | |
| 374 // Returns a SpdyFrame. | |
| 375 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 351 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
| 376 int extra_header_count, | 352 int extra_header_count, |
| 377 bool compressed, | 353 bool compressed, |
| 378 int stream_id, | 354 int stream_id, |
| 379 RequestPriority request_priority) { | 355 RequestPriority request_priority) { |
| 380 return ConstructSpdyGet(extra_headers, extra_header_count, compressed, | 356 return ConstructSpdyGet(extra_headers, extra_header_count, compressed, |
| 381 stream_id, request_priority, true); | 357 stream_id, request_priority, true); |
| 382 } | 358 } |
| 383 | 359 |
| 384 // Constructs a standard SPDY GET SYN frame, optionally compressed. | |
| 385 // |extra_headers| are the extra header-value pairs, which typically | |
| 386 // will vary the most between calls. | |
| 387 // Returns a SpdyFrame. | |
| 388 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 360 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
| 389 int extra_header_count, | 361 int extra_header_count, |
| 390 bool compressed, | 362 bool compressed, |
| 391 int stream_id, | 363 int stream_id, |
| 392 RequestPriority request_priority, | 364 RequestPriority request_priority, |
| 393 bool direct) { | 365 bool direct) { |
| 394 const char* const kStandardGetHeaders[] = { | 366 const char* const kStandardGetHeaders[] = { |
| 395 ":method", "GET", | 367 ":method", "GET", |
| 396 ":host", "www.google.com", | 368 ":host", "www.google.com", |
| 397 ":scheme", "http", | 369 ":scheme", "http", |
| 398 ":version", "HTTP/1.1", | 370 ":version", "HTTP/1.1", |
| 399 ":path", (direct ? "/" : "/") | 371 ":path", (direct ? "/" : "/") |
| 400 }; | 372 }; |
| 401 return ConstructSpdyControlFrame(extra_headers, | 373 return ConstructSpdyControlFrame(extra_headers, |
| 402 extra_header_count, | 374 extra_header_count, |
| 403 compressed, | 375 compressed, |
| 404 stream_id, | 376 stream_id, |
| 405 request_priority, | 377 request_priority, |
| 406 SYN_STREAM, | 378 SYN_STREAM, |
| 407 CONTROL_FLAG_FIN, | 379 CONTROL_FLAG_FIN, |
| 408 kStandardGetHeaders, | 380 kStandardGetHeaders, |
| 409 arraysize(kStandardGetHeaders)); | 381 arraysize(kStandardGetHeaders)); |
| 410 } | 382 } |
| 411 | 383 |
| 412 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. | |
| 413 SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], | 384 SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], |
| 414 int extra_header_count, | 385 int extra_header_count, |
| 415 int stream_id) { | 386 int stream_id) { |
| 416 const char* const kConnectHeaders[] = { | 387 const char* const kConnectHeaders[] = { |
| 417 ":method", "CONNECT", | 388 ":method", "CONNECT", |
| 418 ":path", "www.google.com:443", | 389 ":path", "www.google.com:443", |
| 419 ":host", "www.google.com", | 390 ":host", "www.google.com", |
| 420 ":version", "HTTP/1.1", | 391 ":version", "HTTP/1.1", |
| 421 }; | 392 }; |
| 422 return ConstructSpdyControlFrame(extra_headers, | 393 return ConstructSpdyControlFrame(extra_headers, |
| 423 extra_header_count, | 394 extra_header_count, |
| 424 /*compressed*/ false, | 395 /*compressed*/ false, |
| 425 stream_id, | 396 stream_id, |
| 426 LOWEST, | 397 LOWEST, |
| 427 SYN_STREAM, | 398 SYN_STREAM, |
| 428 CONTROL_FLAG_NONE, | 399 CONTROL_FLAG_NONE, |
| 429 kConnectHeaders, | 400 kConnectHeaders, |
| 430 arraysize(kConnectHeaders)); | 401 arraysize(kConnectHeaders)); |
| 431 } | 402 } |
| 432 | 403 |
| 433 // Constructs a standard SPDY push SYN frame. | |
| 434 // |extra_headers| are the extra header-value pairs, which typically | |
| 435 // will vary the most between calls. | |
| 436 // Returns a SpdyFrame. | |
| 437 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 404 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 438 int extra_header_count, | 405 int extra_header_count, |
| 439 int stream_id, | 406 int stream_id, |
| 440 int associated_stream_id) { | 407 int associated_stream_id) { |
| 441 const char* const kStandardPushHeaders[] = { | 408 const char* const kStandardPushHeaders[] = { |
| 442 "hello", "bye", | 409 "hello", "bye", |
| 443 ":status", "200", | 410 ":status", "200", |
| 444 ":version", "HTTP/1.1" | 411 ":version", "HTTP/1.1" |
| 445 }; | 412 }; |
| 446 return ConstructSpdyControlFrame(extra_headers, | 413 return ConstructSpdyControlFrame(extra_headers, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 extra_header_count, | 490 extra_header_count, |
| 524 false, | 491 false, |
| 525 stream_id, | 492 stream_id, |
| 526 LOWEST, | 493 LOWEST, |
| 527 HEADERS, | 494 HEADERS, |
| 528 CONTROL_FLAG_NONE, | 495 CONTROL_FLAG_NONE, |
| 529 kStandardGetHeaders, | 496 kStandardGetHeaders, |
| 530 arraysize(kStandardGetHeaders)); | 497 arraysize(kStandardGetHeaders)); |
| 531 } | 498 } |
| 532 | 499 |
| 533 // Constructs a standard SPDY SYN_REPLY frame with the specified status code. | |
| 534 // Returns a SpdyFrame. | |
| 535 SpdyFrame* ConstructSpdySynReplyError(const char* const status, | 500 SpdyFrame* ConstructSpdySynReplyError(const char* const status, |
| 536 const char* const* const extra_headers, | 501 const char* const* const extra_headers, |
| 537 int extra_header_count, | 502 int extra_header_count, |
| 538 int stream_id) { | 503 int stream_id) { |
| 539 const char* const kStandardGetHeaders[] = { | 504 const char* const kStandardGetHeaders[] = { |
| 540 "hello", "bye", | 505 "hello", "bye", |
| 541 ":status", status, | 506 ":status", status, |
| 542 ":version", "HTTP/1.1" | 507 ":version", "HTTP/1.1" |
| 543 }; | 508 }; |
| 544 return ConstructSpdyControlFrame(extra_headers, | 509 return ConstructSpdyControlFrame(extra_headers, |
| 545 extra_header_count, | 510 extra_header_count, |
| 546 false, | 511 false, |
| 547 stream_id, | 512 stream_id, |
| 548 LOWEST, | 513 LOWEST, |
| 549 SYN_REPLY, | 514 SYN_REPLY, |
| 550 CONTROL_FLAG_NONE, | 515 CONTROL_FLAG_NONE, |
| 551 kStandardGetHeaders, | 516 kStandardGetHeaders, |
| 552 arraysize(kStandardGetHeaders)); | 517 arraysize(kStandardGetHeaders)); |
| 553 } | 518 } |
| 554 | 519 |
| 555 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. | |
| 556 // |extra_headers| are the extra header-value pairs, which typically | |
| 557 // will vary the most between calls. | |
| 558 // Returns a SpdyFrame. | |
| 559 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) { | 520 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) { |
| 560 static const char* const kExtraHeaders[] = { | 521 static const char* const kExtraHeaders[] = { |
| 561 "location", "http://www.foo.com/index.php", | 522 "location", "http://www.foo.com/index.php", |
| 562 }; | 523 }; |
| 563 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, | 524 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, |
| 564 arraysize(kExtraHeaders)/2, stream_id); | 525 arraysize(kExtraHeaders)/2, stream_id); |
| 565 } | 526 } |
| 566 | 527 |
| 567 // Constructs a standard SPDY SYN_REPLY frame with an Internal Server | |
| 568 // Error status code. | |
| 569 // Returns a SpdyFrame. | |
| 570 SpdyFrame* ConstructSpdySynReplyError(int stream_id) { | 528 SpdyFrame* ConstructSpdySynReplyError(int stream_id) { |
| 571 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); | 529 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); |
| 572 } | 530 } |
| 573 | 531 |
| 574 | |
| 575 | |
| 576 | |
| 577 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. | |
| 578 // |extra_headers| are the extra header-value pairs, which typically | |
| 579 // will vary the most between calls. | |
| 580 // Returns a SpdyFrame. | |
| 581 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], | 532 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], |
| 582 int extra_header_count, | 533 int extra_header_count, |
| 583 int stream_id) { | 534 int stream_id) { |
| 584 static const char* const kStandardGetHeaders[] = { | 535 static const char* const kStandardGetHeaders[] = { |
| 585 "hello", "bye", | 536 "hello", "bye", |
| 586 ":status", "200", | 537 ":status", "200", |
| 587 ":version", "HTTP/1.1" | 538 ":version", "HTTP/1.1" |
| 588 }; | 539 }; |
| 589 return ConstructSpdyControlFrame(extra_headers, | 540 return ConstructSpdyControlFrame(extra_headers, |
| 590 extra_header_count, | 541 extra_header_count, |
| 591 false, | 542 false, |
| 592 stream_id, | 543 stream_id, |
| 593 LOWEST, | 544 LOWEST, |
| 594 SYN_REPLY, | 545 SYN_REPLY, |
| 595 CONTROL_FLAG_NONE, | 546 CONTROL_FLAG_NONE, |
| 596 kStandardGetHeaders, | 547 kStandardGetHeaders, |
| 597 arraysize(kStandardGetHeaders)); | 548 arraysize(kStandardGetHeaders)); |
| 598 } | 549 } |
| 599 | 550 |
| 600 // Constructs a standard SPDY POST SYN frame. | |
| 601 // |content_length| is the size of post data. | |
| 602 // |extra_headers| are the extra header-value pairs, which typically | |
| 603 // will vary the most between calls. | |
| 604 // Returns a SpdyFrame. | |
| 605 SpdyFrame* ConstructSpdyPost(const char* url, | 551 SpdyFrame* ConstructSpdyPost(const char* url, |
| 606 SpdyStreamId stream_id, | 552 SpdyStreamId stream_id, |
| 607 int64 content_length, | 553 int64 content_length, |
| 608 RequestPriority priority, | 554 RequestPriority priority, |
| 609 const char* const extra_headers[], | 555 const char* const extra_headers[], |
| 610 int extra_header_count) { | 556 int extra_header_count) { |
| 611 const SpdyHeaderInfo kSynStartHeader = { | 557 const SpdyHeaderInfo kSynStartHeader = { |
| 612 SYN_STREAM, // Kind = Syn | 558 SYN_STREAM, // Kind = Syn |
| 613 stream_id, // Stream ID | 559 stream_id, // Stream ID |
| 614 0, // Associated stream ID | 560 0, // Associated stream ID |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 } | 651 } |
| 706 | 652 |
| 707 // Wraps |frame| in the payload of a data frame in stream |stream_id|. | 653 // Wraps |frame| in the payload of a data frame in stream |stream_id|. |
| 708 SpdyFrame* ConstructWrappedSpdyFrame(const scoped_ptr<SpdyFrame>& frame, | 654 SpdyFrame* ConstructWrappedSpdyFrame(const scoped_ptr<SpdyFrame>& frame, |
| 709 int stream_id) { | 655 int stream_id) { |
| 710 return ConstructSpdyBodyFrame(stream_id, frame->data(), | 656 return ConstructSpdyBodyFrame(stream_id, frame->data(), |
| 711 frame->size(), | 657 frame->size(), |
| 712 false); | 658 false); |
| 713 } | 659 } |
| 714 | 660 |
| 715 // Construct an expected SPDY reply string. | |
| 716 // |extra_headers| are the extra header-value pairs, which typically | |
| 717 // will vary the most between calls. | |
| 718 // |buffer| is the buffer we're filling in. | |
| 719 // Returns the number of bytes written into |buffer|. | |
| 720 int ConstructSpdyReplyString(const char* const extra_headers[], | 661 int ConstructSpdyReplyString(const char* const extra_headers[], |
| 721 int extra_header_count, | 662 int extra_header_count, |
| 722 char* buffer, | 663 char* buffer, |
| 723 int buffer_length) { | 664 int buffer_length) { |
| 724 int frame_size = 0; | 665 int frame_size = 0; |
| 725 char* buffer_write = buffer; | 666 char* buffer_write = buffer; |
| 726 int buffer_left = buffer_length; | 667 int buffer_left = buffer_length; |
| 727 SpdyHeaderBlock headers; | 668 SpdyHeaderBlock headers; |
| 728 if (!buffer || !buffer_length) | 669 if (!buffer || !buffer_length) |
| 729 return 0; | 670 return 0; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 NULL, // Data | 874 NULL, // Data |
| 934 0, // Length | 875 0, // Length |
| 935 DATA_FLAG_NONE // Data Flags | 876 DATA_FLAG_NONE // Data Flags |
| 936 }; | 877 }; |
| 937 return kHeader; | 878 return kHeader; |
| 938 } | 879 } |
| 939 | 880 |
| 940 } // namespace test_spdy3 | 881 } // namespace test_spdy3 |
| 941 | 882 |
| 942 } // namespace net | 883 } // namespace net |
| OLD | NEW |