Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: net/spdy/spdy_test_util_common.cc

Issue 2140673002: Remove SPDY/3.1 tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_test_util_common.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_common.h" 5 #include "net/spdy/spdy_test_util_common.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "net/base/host_port_pair.h" 17 #include "net/base/host_port_pair.h"
18 #include "net/cert/ct_policy_enforcer.h" 18 #include "net/cert/ct_policy_enforcer.h"
19 #include "net/cert/mock_cert_verifier.h" 19 #include "net/cert/mock_cert_verifier.h"
20 #include "net/cert/multi_log_ct_verifier.h" 20 #include "net/cert/multi_log_ct_verifier.h"
21 #include "net/http/http_cache.h" 21 #include "net/http/http_cache.h"
22 #include "net/http/http_network_session.h" 22 #include "net/http/http_network_session.h"
23 #include "net/http/http_network_transaction.h" 23 #include "net/http/http_network_transaction.h"
24 #include "net/http/http_server_properties_impl.h" 24 #include "net/http/http_server_properties_impl.h"
25 #include "net/socket/next_proto.h"
25 #include "net/socket/socket_test_util.h" 26 #include "net/socket/socket_test_util.h"
26 #include "net/socket/ssl_client_socket.h" 27 #include "net/socket/ssl_client_socket.h"
27 #include "net/socket/transport_client_socket_pool.h" 28 #include "net/socket/transport_client_socket_pool.h"
28 #include "net/spdy/buffered_spdy_framer.h" 29 #include "net/spdy/buffered_spdy_framer.h"
29 #include "net/spdy/spdy_alt_svc_wire_format.h" 30 #include "net/spdy/spdy_alt_svc_wire_format.h"
30 #include "net/spdy/spdy_framer.h" 31 #include "net/spdy/spdy_framer.h"
31 #include "net/spdy/spdy_http_utils.h" 32 #include "net/spdy/spdy_http_utils.h"
32 #include "net/spdy/spdy_session.h" 33 #include "net/spdy/spdy_session.h"
33 #include "net/spdy/spdy_session_pool.h" 34 #include "net/spdy/spdy_session_pool.h"
34 #include "net/spdy/spdy_stream.h" 35 #include "net/spdy/spdy_stream.h"
35 #include "net/test/gtest_util.h" 36 #include "net/test/gtest_util.h"
36 #include "net/url_request/url_request_job_factory_impl.h" 37 #include "net/url_request/url_request_job_factory_impl.h"
37 #include "testing/gmock/include/gmock/gmock.h" 38 #include "testing/gmock/include/gmock/gmock.h"
38 39
39 using net::test::IsOk; 40 using net::test::IsOk;
40 41
41 namespace net { 42 namespace net {
42 43
43 namespace { 44 namespace {
44 45
45 bool next_proto_is_spdy(NextProto next_proto) {
46 return next_proto >= kProtoSPDYMinimumVersion &&
47 next_proto <= kProtoSPDYMaximumVersion;
48 }
49
50 // Parses a URL into the scheme, host, and path components required for a 46 // Parses a URL into the scheme, host, and path components required for a
51 // SPDY request. 47 // SPDY request.
52 void ParseUrl(base::StringPiece url, std::string* scheme, std::string* host, 48 void ParseUrl(base::StringPiece url, std::string* scheme, std::string* host,
53 std::string* path) { 49 std::string* path) {
54 GURL gurl(url.as_string()); 50 GURL gurl(url.as_string());
55 path->assign(gurl.PathForRequest()); 51 path->assign(gurl.PathForRequest());
56 scheme->assign(gurl.scheme()); 52 scheme->assign(gurl.scheme());
57 host->assign(gurl.host()); 53 host->assign(gurl.host());
58 if (gurl.has_port()) { 54 if (gurl.has_port()) {
59 host->append(":"); 55 host->append(":");
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 bool OnUnknownFrame(SpdyStreamId stream_id, int frame_type) override { 237 bool OnUnknownFrame(SpdyStreamId stream_id, int frame_type) override {
242 return false; 238 return false;
243 } 239 }
244 240
245 private: 241 private:
246 SpdyPriority priority_; 242 SpdyPriority priority_;
247 }; 243 };
248 244
249 } // namespace 245 } // namespace
250 246
251 bool GetSpdyPriority(SpdyMajorVersion version, 247 bool GetSpdyPriority(const SpdySerializedFrame& frame, SpdyPriority* priority) {
252 const SpdySerializedFrame& frame, 248 BufferedSpdyFramer framer(HTTP2);
253 SpdyPriority* priority) {
254 BufferedSpdyFramer framer(version);
255 PriorityGetter priority_getter; 249 PriorityGetter priority_getter;
256 framer.set_visitor(&priority_getter); 250 framer.set_visitor(&priority_getter);
257 size_t frame_size = frame.size(); 251 size_t frame_size = frame.size();
258 if (framer.ProcessInput(frame.data(), frame_size) != frame_size) { 252 if (framer.ProcessInput(frame.data(), frame_size) != frame_size) {
259 return false; 253 return false;
260 } 254 }
261 *priority = priority_getter.priority(); 255 *priority = priority_getter.priority();
262 return true; 256 return true;
263 } 257 }
264 258
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 322
329 MockECSignatureCreatorFactory::~MockECSignatureCreatorFactory() { 323 MockECSignatureCreatorFactory::~MockECSignatureCreatorFactory() {
330 crypto::ECSignatureCreator::SetFactoryForTesting(nullptr); 324 crypto::ECSignatureCreator::SetFactoryForTesting(nullptr);
331 } 325 }
332 326
333 std::unique_ptr<crypto::ECSignatureCreator> 327 std::unique_ptr<crypto::ECSignatureCreator>
334 MockECSignatureCreatorFactory::Create(crypto::ECPrivateKey* key) { 328 MockECSignatureCreatorFactory::Create(crypto::ECPrivateKey* key) {
335 return base::MakeUnique<MockECSignatureCreator>(key); 329 return base::MakeUnique<MockECSignatureCreator>(key);
336 } 330 }
337 331
338 SpdySessionDependencies::SpdySessionDependencies(NextProto protocol) 332 SpdySessionDependencies::SpdySessionDependencies()
339 : SpdySessionDependencies(protocol, ProxyService::CreateDirect()) {} 333 : SpdySessionDependencies(ProxyService::CreateDirect()) {}
340 334
341 SpdySessionDependencies::SpdySessionDependencies( 335 SpdySessionDependencies::SpdySessionDependencies(
342 NextProto protocol,
343 std::unique_ptr<ProxyService> proxy_service) 336 std::unique_ptr<ProxyService> proxy_service)
344 : host_resolver(new MockCachingHostResolver), 337 : host_resolver(new MockCachingHostResolver),
345 cert_verifier(new MockCertVerifier), 338 cert_verifier(new MockCertVerifier),
346 channel_id_service(nullptr), 339 channel_id_service(nullptr),
347 transport_security_state(new TransportSecurityState), 340 transport_security_state(new TransportSecurityState),
348 cert_transparency_verifier(new MultiLogCTVerifier), 341 cert_transparency_verifier(new MultiLogCTVerifier),
349 ct_policy_enforcer(new CTPolicyEnforcer), 342 ct_policy_enforcer(new CTPolicyEnforcer),
350 proxy_service(std::move(proxy_service)), 343 proxy_service(std::move(proxy_service)),
351 ssl_config_service(new SSLConfigServiceDefaults), 344 ssl_config_service(new SSLConfigServiceDefaults),
352 socket_factory(new MockClientSocketFactory), 345 socket_factory(new MockClientSocketFactory),
353 http_auth_handler_factory( 346 http_auth_handler_factory(
354 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), 347 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())),
355 http_server_properties(new HttpServerPropertiesImpl), 348 http_server_properties(new HttpServerPropertiesImpl),
356 enable_ip_pooling(true), 349 enable_ip_pooling(true),
357 enable_ping(false), 350 enable_ping(false),
358 enable_user_alternate_protocol_ports(false), 351 enable_user_alternate_protocol_ports(false),
359 enable_priority_dependencies(true), 352 enable_priority_dependencies(true),
360 enable_quic(false), 353 enable_quic(false),
361 protocol(protocol),
362 session_max_recv_window_size( 354 session_max_recv_window_size(
363 SpdySession::GetDefaultInitialWindowSize(protocol)), 355 SpdySession::GetDefaultInitialWindowSize(kProtoHTTP2)),
364 stream_max_recv_window_size( 356 stream_max_recv_window_size(
365 SpdySession::GetDefaultInitialWindowSize(protocol)), 357 SpdySession::GetDefaultInitialWindowSize(kProtoHTTP2)),
366 time_func(&base::TimeTicks::Now), 358 time_func(&base::TimeTicks::Now),
367 enable_http2_alternative_service_with_different_host(false), 359 enable_http2_alternative_service_with_different_host(false),
368 net_log(NULL) { 360 net_log(NULL) {
369 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol;
370
371 // Note: The CancelledTransaction test does cleanup by running all 361 // Note: The CancelledTransaction test does cleanup by running all
372 // tasks in the message loop (RunAllPending). Unfortunately, that 362 // tasks in the message loop (RunAllPending). Unfortunately, that
373 // doesn't clean up tasks on the host resolver thread; and 363 // doesn't clean up tasks on the host resolver thread; and
374 // TCPConnectJob is currently not cancellable. Using synchronous 364 // TCPConnectJob is currently not cancellable. Using synchronous
375 // lookups allows the test to shutdown cleanly. Until we have 365 // lookups allows the test to shutdown cleanly. Until we have
376 // cancellable TCPConnectJobs, use synchronous lookups. 366 // cancellable TCPConnectJobs, use synchronous lookups.
377 host_resolver->set_synchronous_mode(true); 367 host_resolver->set_synchronous_mode(true);
378 } 368 }
379 369
380 SpdySessionDependencies::~SpdySessionDependencies() {} 370 SpdySessionDependencies::~SpdySessionDependencies() {}
381 371
382 // static 372 // static
383 std::unique_ptr<HttpNetworkSession> SpdySessionDependencies::SpdyCreateSession( 373 std::unique_ptr<HttpNetworkSession> SpdySessionDependencies::SpdyCreateSession(
384 SpdySessionDependencies* session_deps) { 374 SpdySessionDependencies* session_deps) {
385 HttpNetworkSession::Params params = CreateSessionParams(session_deps); 375 HttpNetworkSession::Params params = CreateSessionParams(session_deps);
386 params.client_socket_factory = session_deps->socket_factory.get(); 376 params.client_socket_factory = session_deps->socket_factory.get();
387 std::unique_ptr<HttpNetworkSession> http_session( 377 std::unique_ptr<HttpNetworkSession> http_session(
388 new HttpNetworkSession(params)); 378 new HttpNetworkSession(params));
389 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); 379 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool());
390 pool_peer.SetEnableSendingInitialData(false); 380 pool_peer.SetEnableSendingInitialData(false);
391 return http_session; 381 return http_session;
392 } 382 }
393 383
394 // static 384 // static
395 HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( 385 HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams(
396 SpdySessionDependencies* session_deps) { 386 SpdySessionDependencies* session_deps) {
397 DCHECK(next_proto_is_spdy(session_deps->protocol)) <<
398 "Invalid protocol: " << session_deps->protocol;
399
400 HttpNetworkSession::Params params; 387 HttpNetworkSession::Params params;
401 params.host_resolver = session_deps->host_resolver.get(); 388 params.host_resolver = session_deps->host_resolver.get();
402 params.cert_verifier = session_deps->cert_verifier.get(); 389 params.cert_verifier = session_deps->cert_verifier.get();
403 params.channel_id_service = session_deps->channel_id_service.get(); 390 params.channel_id_service = session_deps->channel_id_service.get();
404 params.transport_security_state = 391 params.transport_security_state =
405 session_deps->transport_security_state.get(); 392 session_deps->transport_security_state.get();
406 params.cert_transparency_verifier = 393 params.cert_transparency_verifier =
407 session_deps->cert_transparency_verifier.get(); 394 session_deps->cert_transparency_verifier.get();
408 params.ct_policy_enforcer = session_deps->ct_policy_enforcer.get(); 395 params.ct_policy_enforcer = session_deps->ct_policy_enforcer.get();
409 params.proxy_service = session_deps->proxy_service.get(); 396 params.proxy_service = session_deps->proxy_service.get();
410 params.ssl_config_service = session_deps->ssl_config_service.get(); 397 params.ssl_config_service = session_deps->ssl_config_service.get();
411 params.http_auth_handler_factory = 398 params.http_auth_handler_factory =
412 session_deps->http_auth_handler_factory.get(); 399 session_deps->http_auth_handler_factory.get();
413 params.http_server_properties = session_deps->http_server_properties.get(); 400 params.http_server_properties = session_deps->http_server_properties.get();
414 params.enable_spdy_ping_based_connection_checking = session_deps->enable_ping; 401 params.enable_spdy_ping_based_connection_checking = session_deps->enable_ping;
415 params.enable_user_alternate_protocol_ports = 402 params.enable_user_alternate_protocol_ports =
416 session_deps->enable_user_alternate_protocol_ports; 403 session_deps->enable_user_alternate_protocol_ports;
417 params.enable_priority_dependencies = 404 params.enable_priority_dependencies =
418 session_deps->enable_priority_dependencies; 405 session_deps->enable_priority_dependencies;
419 params.enable_quic = session_deps->enable_quic; 406 params.enable_quic = session_deps->enable_quic;
420 params.spdy_default_protocol = session_deps->protocol; 407 params.spdy_default_protocol = kProtoHTTP2;
421 params.spdy_session_max_recv_window_size = 408 params.spdy_session_max_recv_window_size =
422 session_deps->session_max_recv_window_size; 409 session_deps->session_max_recv_window_size;
423 params.spdy_stream_max_recv_window_size = 410 params.spdy_stream_max_recv_window_size =
424 session_deps->stream_max_recv_window_size; 411 session_deps->stream_max_recv_window_size;
425 params.time_func = session_deps->time_func; 412 params.time_func = session_deps->time_func;
426 params.proxy_delegate = session_deps->proxy_delegate.get(); 413 params.proxy_delegate = session_deps->proxy_delegate.get();
427 params.enable_http2_alternative_service_with_different_host = 414 params.enable_http2_alternative_service_with_different_host =
428 session_deps->enable_http2_alternative_service_with_different_host; 415 session_deps->enable_http2_alternative_service_with_different_host;
429 params.net_log = session_deps->net_log; 416 params.net_log = session_deps->net_log;
430 return params; 417 return params;
431 } 418 }
432 419
433 SpdyURLRequestContext::SpdyURLRequestContext(NextProto protocol) 420 SpdyURLRequestContext::SpdyURLRequestContext() : storage_(this) {
434 : storage_(this) {
435 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol;
436
437 storage_.set_host_resolver( 421 storage_.set_host_resolver(
438 std::unique_ptr<HostResolver>(new MockHostResolver)); 422 std::unique_ptr<HostResolver>(new MockHostResolver));
439 storage_.set_cert_verifier(base::WrapUnique(new MockCertVerifier)); 423 storage_.set_cert_verifier(base::WrapUnique(new MockCertVerifier));
440 storage_.set_transport_security_state( 424 storage_.set_transport_security_state(
441 base::WrapUnique(new TransportSecurityState)); 425 base::WrapUnique(new TransportSecurityState));
442 storage_.set_proxy_service(ProxyService::CreateDirect()); 426 storage_.set_proxy_service(ProxyService::CreateDirect());
443 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); 427 storage_.set_ssl_config_service(new SSLConfigServiceDefaults);
444 storage_.set_http_auth_handler_factory( 428 storage_.set_http_auth_handler_factory(
445 HttpAuthHandlerFactory::CreateDefault(host_resolver())); 429 HttpAuthHandlerFactory::CreateDefault(host_resolver()));
446 storage_.set_http_server_properties( 430 storage_.set_http_server_properties(
447 std::unique_ptr<HttpServerProperties>(new HttpServerPropertiesImpl())); 431 std::unique_ptr<HttpServerProperties>(new HttpServerPropertiesImpl()));
448 storage_.set_job_factory(base::WrapUnique(new URLRequestJobFactoryImpl())); 432 storage_.set_job_factory(base::WrapUnique(new URLRequestJobFactoryImpl()));
449 HttpNetworkSession::Params params; 433 HttpNetworkSession::Params params;
450 params.client_socket_factory = &socket_factory_; 434 params.client_socket_factory = &socket_factory_;
451 params.host_resolver = host_resolver(); 435 params.host_resolver = host_resolver();
452 params.cert_verifier = cert_verifier(); 436 params.cert_verifier = cert_verifier();
453 params.transport_security_state = transport_security_state(); 437 params.transport_security_state = transport_security_state();
454 params.proxy_service = proxy_service(); 438 params.proxy_service = proxy_service();
455 params.ssl_config_service = ssl_config_service(); 439 params.ssl_config_service = ssl_config_service();
456 params.http_auth_handler_factory = http_auth_handler_factory(); 440 params.http_auth_handler_factory = http_auth_handler_factory();
457 params.enable_spdy_ping_based_connection_checking = false; 441 params.enable_spdy_ping_based_connection_checking = false;
458 params.spdy_default_protocol = protocol; 442 params.spdy_default_protocol = kProtoHTTP2;
459 params.http_server_properties = http_server_properties(); 443 params.http_server_properties = http_server_properties();
460 storage_.set_http_network_session( 444 storage_.set_http_network_session(
461 base::WrapUnique(new HttpNetworkSession(params))); 445 base::WrapUnique(new HttpNetworkSession(params)));
462 SpdySessionPoolPeer pool_peer( 446 SpdySessionPoolPeer pool_peer(
463 storage_.http_network_session()->spdy_session_pool()); 447 storage_.http_network_session()->spdy_session_pool());
464 pool_peer.SetEnableSendingInitialData(false); 448 pool_peer.SetEnableSendingInitialData(false);
465 storage_.set_http_transaction_factory(base::WrapUnique( 449 storage_.set_http_transaction_factory(base::WrapUnique(
466 new HttpCache(storage_.http_network_session(), 450 new HttpCache(storage_.http_network_session(),
467 HttpCache::DefaultBackend::InMemory(0), false))); 451 HttpCache::DefaultBackend::InMemory(0), false)));
468 } 452 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 } 652 }
669 653
670 void SpdySessionPoolPeer::SetSessionMaxRecvWindowSize(size_t window) { 654 void SpdySessionPoolPeer::SetSessionMaxRecvWindowSize(size_t window) {
671 pool_->session_max_recv_window_size_ = window; 655 pool_->session_max_recv_window_size_ = window;
672 } 656 }
673 657
674 void SpdySessionPoolPeer::SetStreamInitialRecvWindowSize(size_t window) { 658 void SpdySessionPoolPeer::SetStreamInitialRecvWindowSize(size_t window) {
675 pool_->stream_max_recv_window_size_ = window; 659 pool_->stream_max_recv_window_size_ = window;
676 } 660 }
677 661
678 SpdyTestUtil::SpdyTestUtil(NextProto protocol, bool dependency_priorities) 662 SpdyTestUtil::SpdyTestUtil(bool dependency_priorities)
679 : protocol_(protocol), 663 : headerless_spdy_framer_(HTTP2),
680 spdy_version_(NextProtoToSpdyMajorVersion(protocol)), 664 request_spdy_framer_(HTTP2),
681 headerless_spdy_framer_(spdy_version_), 665 response_spdy_framer_(HTTP2),
682 request_spdy_framer_(spdy_version_),
683 response_spdy_framer_(spdy_version_),
684 default_url_(GURL(kDefaultUrl)), 666 default_url_(GURL(kDefaultUrl)),
685 dependency_priorities_(dependency_priorities) { 667 dependency_priorities_(dependency_priorities) {}
686 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol;
687 }
688 668
689 SpdyTestUtil::~SpdyTestUtil() {} 669 SpdyTestUtil::~SpdyTestUtil() {}
690 670
691 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url, 671 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url,
692 SpdyHeaderBlock* headers) const { 672 SpdyHeaderBlock* headers) const {
693 std::string scheme, host, path; 673 std::string scheme, host, path;
694 ParseUrl(url, &scheme, &host, &path); 674 ParseUrl(url, &scheme, &host, &path);
695 (*headers)[GetHostKey()] = host; 675 (*headers)[GetHostKey()] = host;
696 (*headers)[GetSchemeKey()] = scheme; 676 (*headers)[GetSchemeKey()] = scheme;
697 (*headers)[GetPathKey()] = path; 677 (*headers)[GetPathKey()] = path;
(...skipping 23 matching lines...) Expand all
721 701
722 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock( 702 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock(
723 base::StringPiece url, 703 base::StringPiece url,
724 int64_t content_length) const { 704 int64_t content_length) const {
725 return ConstructHeaderBlock("PUT", url, &content_length); 705 return ConstructHeaderBlock("PUT", url, &content_length);
726 } 706 }
727 707
728 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame( 708 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame(
729 const SpdyHeaderInfo& header_info, 709 const SpdyHeaderInfo& header_info,
730 SpdyHeaderBlock headers) const { 710 SpdyHeaderBlock headers) const {
731 BufferedSpdyFramer framer(spdy_version_); 711 BufferedSpdyFramer framer(HTTP2);
732 SpdySerializedFrame* frame = NULL; 712 SpdySerializedFrame* frame = NULL;
733 switch (header_info.kind) { 713 switch (header_info.kind) {
734 case DATA: 714 case DATA:
735 frame = framer.CreateDataFrame(header_info.id, header_info.data, 715 frame = framer.CreateDataFrame(header_info.id, header_info.data,
736 header_info.data_length, 716 header_info.data_length,
737 header_info.data_flags); 717 header_info.data_flags);
738 break; 718 break;
739 case SYN_STREAM: 719 case SYN_STREAM:
740 frame = framer.CreateSynStream( 720 frame = framer.CreateSynStream(
741 header_info.id, header_info.assoc_id, header_info.priority, 721 header_info.id, header_info.assoc_id, header_info.priority,
(...skipping 29 matching lines...) Expand all
771 AppendToHeaderBlock(tail_headers, tail_header_count, &headers); 751 AppendToHeaderBlock(tail_headers, tail_header_count, &headers);
772 return ConstructSpdyFrame(header_info, std::move(headers)); 752 return ConstructSpdyFrame(header_info, std::move(headers));
773 } 753 }
774 754
775 std::string SpdyTestUtil::ConstructSpdyReplyString( 755 std::string SpdyTestUtil::ConstructSpdyReplyString(
776 const SpdyHeaderBlock& headers) const { 756 const SpdyHeaderBlock& headers) const {
777 std::string reply_string; 757 std::string reply_string;
778 for (SpdyHeaderBlock::const_iterator it = headers.begin(); 758 for (SpdyHeaderBlock::const_iterator it = headers.begin();
779 it != headers.end(); ++it) { 759 it != headers.end(); ++it) {
780 std::string key = it->first.as_string(); 760 std::string key = it->first.as_string();
781 // Remove leading colon from "special" headers (for SPDY3 and 761 // Remove leading colon from pseudo headers.
782 // above). 762 if (key[0] == ':')
783 if (spdy_version() >= SPDY3 && key[0] == ':')
784 key = key.substr(1); 763 key = key.substr(1);
785 for (const std::string& value : 764 for (const std::string& value :
786 base::SplitString(it->second, base::StringPiece("\0", 1), 765 base::SplitString(it->second, base::StringPiece("\0", 1),
787 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 766 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
788 reply_string += key + ": " + value + "\n"; 767 reply_string += key + ": " + value + "\n";
789 } 768 }
790 } 769 }
791 return reply_string; 770 return reply_string;
792 } 771 }
793 772
794 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer 773 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer
795 // SpdySettingsIR). 774 // SpdySettingsIR).
796 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySettings( 775 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySettings(
797 const SettingsMap& settings) { 776 const SettingsMap& settings) {
798 SpdySettingsIR settings_ir; 777 SpdySettingsIR settings_ir;
799 for (SettingsMap::const_iterator it = settings.begin(); 778 for (SettingsMap::const_iterator it = settings.begin();
800 it != settings.end(); 779 it != settings.end();
801 ++it) { 780 ++it) {
802 settings_ir.AddSetting( 781 settings_ir.AddSetting(
803 it->first, 782 it->first,
804 (it->second.first & SETTINGS_FLAG_PLEASE_PERSIST) != 0, 783 (it->second.first & SETTINGS_FLAG_PLEASE_PERSIST) != 0,
805 (it->second.first & SETTINGS_FLAG_PERSISTED) != 0, 784 (it->second.first & SETTINGS_FLAG_PERSISTED) != 0,
806 it->second.second); 785 it->second.second);
807 } 786 }
808 return new SpdySerializedFrame( 787 return new SpdySerializedFrame(
809 headerless_spdy_framer_.SerializeFrame(settings_ir)); 788 headerless_spdy_framer_.SerializeFrame(settings_ir));
810 } 789 }
811 790
812 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySettingsAck() { 791 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySettingsAck() {
813 char kEmptyWrite[] = ""; 792 SpdySettingsIR settings_ir;
814 793 settings_ir.set_is_ack(true);
815 if (spdy_version() > SPDY3) { 794 return new SpdySerializedFrame(
816 SpdySettingsIR settings_ir; 795 headerless_spdy_framer_.SerializeFrame(settings_ir));
817 settings_ir.set_is_ack(true);
818 return new SpdySerializedFrame(
819 headerless_spdy_framer_.SerializeFrame(settings_ir));
820 }
821 // No settings ACK write occurs. Create an empty placeholder write.
822 return new SpdySerializedFrame(kEmptyWrite, 0, false);
823 } 796 }
824 797
825 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPing(uint32_t ping_id, 798 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPing(uint32_t ping_id,
826 bool is_ack) { 799 bool is_ack) {
827 SpdyPingIR ping_ir(ping_id); 800 SpdyPingIR ping_ir(ping_id);
828 ping_ir.set_is_ack(is_ack); 801 ping_ir.set_is_ack(is_ack);
829 return new SpdySerializedFrame( 802 return new SpdySerializedFrame(
830 headerless_spdy_framer_.SerializeFrame(ping_ir)); 803 headerless_spdy_framer_.SerializeFrame(ping_ir));
831 } 804 }
832 805
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true); 847 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true);
875 } 848 }
876 849
877 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGet( 850 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGet(
878 const char* const extra_headers[], 851 const char* const extra_headers[],
879 int extra_header_count, 852 int extra_header_count,
880 int stream_id, 853 int stream_id,
881 RequestPriority request_priority, 854 RequestPriority request_priority,
882 bool direct) { 855 bool direct) {
883 SpdyHeaderBlock block; 856 SpdyHeaderBlock block;
884 MaybeAddVersionHeader(&block);
885 block[GetMethodKey()] = "GET"; 857 block[GetMethodKey()] = "GET";
886 AddUrlToHeaderBlock(default_url_.spec(), &block); 858 AddUrlToHeaderBlock(default_url_.spec(), &block);
887 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 859 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
888 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true); 860 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true);
889 } 861 }
890 862
891 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyConnect( 863 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyConnect(
892 const char* const extra_headers[], 864 const char* const extra_headers[],
893 int extra_header_count, 865 int extra_header_count,
894 int stream_id, 866 int stream_id,
895 RequestPriority priority, 867 RequestPriority priority,
896 const HostPortPair& host_port_pair) { 868 const HostPortPair& host_port_pair) {
897 SpdyHeaderBlock block; 869 SpdyHeaderBlock block;
898 MaybeAddVersionHeader(&block);
899 block[GetMethodKey()] = "CONNECT"; 870 block[GetMethodKey()] = "CONNECT";
900 if (spdy_version() < HTTP2) { 871 block[GetHostKey()] = host_port_pair.ToString();
901 block[GetHostKey()] = (host_port_pair.port() == 443)
902 ? host_port_pair.host()
903 : host_port_pair.ToString();
904 block[GetPathKey()] = host_port_pair.ToString();
905 } else {
906 block[GetHostKey()] = host_port_pair.ToString();
907 }
908 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 872 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
909 return ConstructSpdySyn(stream_id, std::move(block), priority, false); 873 return ConstructSpdySyn(stream_id, std::move(block), priority, false);
910 } 874 }
911 875
912 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPush( 876 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPush(
913 const char* const extra_headers[], 877 const char* const extra_headers[],
914 int extra_header_count, 878 int extra_header_count,
915 int stream_id, 879 int stream_id,
916 int associated_stream_id, 880 int associated_stream_id,
917 const char* url) { 881 const char* url) {
918 if (spdy_version() < HTTP2) { 882 SpdyHeaderBlock push_promise_header_block;
919 SpdyHeaderBlock header_block; 883 AddUrlToHeaderBlock(url, &push_promise_header_block);
920 header_block["hello"] = "bye"; 884 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id,
921 header_block[GetStatusKey()] = "200"; 885 std::move(push_promise_header_block));
922 header_block[GetVersionKey()] = "HTTP/1.1"; 886 SpdySerializedFrame push_promise_frame(
923 AddUrlToHeaderBlock(url, &header_block); 887 response_spdy_framer_.SerializeFrame(push_promise));
924 AppendToHeaderBlock(extra_headers, extra_header_count, &header_block);
925 SpdySynStreamIR syn_stream(stream_id, std::move(header_block));
926 syn_stream.set_associated_to_stream_id(associated_stream_id);
927 return new SpdySerializedFrame(
928 response_spdy_framer_.SerializeFrame(syn_stream));
929 } else {
930 SpdyHeaderBlock push_promise_header_block;
931 AddUrlToHeaderBlock(url, &push_promise_header_block);
932 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id,
933 std::move(push_promise_header_block));
934 SpdySerializedFrame push_promise_frame(
935 response_spdy_framer_.SerializeFrame(push_promise));
936 888
937 SpdyHeaderBlock headers_header_block; 889 SpdyHeaderBlock headers_header_block;
938 headers_header_block[GetStatusKey()] = "200"; 890 headers_header_block[GetStatusKey()] = "200";
939 headers_header_block["hello"] = "bye"; 891 headers_header_block["hello"] = "bye";
940 AppendToHeaderBlock(extra_headers, extra_header_count, 892 AppendToHeaderBlock(extra_headers, extra_header_count, &headers_header_block);
941 &headers_header_block); 893 SpdyHeadersIR headers(stream_id, std::move(headers_header_block));
942 SpdyHeadersIR headers(stream_id, std::move(headers_header_block)); 894 SpdySerializedFrame headers_frame(
943 SpdySerializedFrame headers_frame( 895 response_spdy_framer_.SerializeFrame(headers));
944 response_spdy_framer_.SerializeFrame(headers));
945 896
946 int joint_data_size = push_promise_frame.size() + headers_frame.size(); 897 int joint_data_size = push_promise_frame.size() + headers_frame.size();
947 std::unique_ptr<char[]> data(new char[joint_data_size]); 898 std::unique_ptr<char[]> data(new char[joint_data_size]);
948 const SpdySerializedFrame* frames[2] = { 899 const SpdySerializedFrame* frames[2] = {
949 &push_promise_frame, &headers_frame, 900 &push_promise_frame, &headers_frame,
950 }; 901 };
951 int combined_size = 902 int combined_size =
952 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); 903 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size);
953 DCHECK_EQ(combined_size, joint_data_size); 904 DCHECK_EQ(combined_size, joint_data_size);
954 return new SpdySerializedFrame(data.release(), joint_data_size, true); 905 return new SpdySerializedFrame(data.release(), joint_data_size, true);
955 }
956 } 906 }
957 907
958 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPush( 908 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPush(
959 const char* const extra_headers[], 909 const char* const extra_headers[],
960 int extra_header_count, 910 int extra_header_count,
961 int stream_id, 911 int stream_id,
962 int associated_stream_id, 912 int associated_stream_id,
963 const char* url, 913 const char* url,
964 const char* status, 914 const char* status,
965 const char* location) { 915 const char* location) {
966 if (spdy_version() < HTTP2) { 916 SpdyHeaderBlock push_promise_header_block;
967 SpdyHeaderBlock header_block; 917 AddUrlToHeaderBlock(url, &push_promise_header_block);
968 header_block["hello"] = "bye"; 918 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id,
969 header_block[GetStatusKey()] = status; 919 std::move(push_promise_header_block));
970 header_block[GetVersionKey()] = "HTTP/1.1"; 920 SpdySerializedFrame push_promise_frame(
971 header_block["location"] = location; 921 response_spdy_framer_.SerializeFrame(push_promise));
972 AddUrlToHeaderBlock(url, &header_block);
973 AppendToHeaderBlock(extra_headers, extra_header_count, &header_block);
974 SpdySynStreamIR syn_stream(stream_id, std::move(header_block));
975 syn_stream.set_associated_to_stream_id(associated_stream_id);
976 return new SpdySerializedFrame(
977 response_spdy_framer_.SerializeFrame(syn_stream));
978 } else {
979 SpdyHeaderBlock push_promise_header_block;
980 AddUrlToHeaderBlock(url, &push_promise_header_block);
981 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id,
982 std::move(push_promise_header_block));
983 SpdySerializedFrame push_promise_frame(
984 response_spdy_framer_.SerializeFrame(push_promise));
985 922
986 SpdyHeaderBlock headers_header_block; 923 SpdyHeaderBlock headers_header_block;
987 headers_header_block["hello"] = "bye"; 924 headers_header_block["hello"] = "bye";
988 headers_header_block[GetStatusKey()] = status; 925 headers_header_block[GetStatusKey()] = status;
989 headers_header_block["location"] = location; 926 headers_header_block["location"] = location;
990 AppendToHeaderBlock(extra_headers, extra_header_count, 927 AppendToHeaderBlock(extra_headers, extra_header_count, &headers_header_block);
991 &headers_header_block); 928 SpdyHeadersIR headers(stream_id, std::move(headers_header_block));
992 SpdyHeadersIR headers(stream_id, std::move(headers_header_block)); 929 SpdySerializedFrame headers_frame(
993 SpdySerializedFrame headers_frame( 930 response_spdy_framer_.SerializeFrame(headers));
994 response_spdy_framer_.SerializeFrame(headers));
995 931
996 int joint_data_size = push_promise_frame.size() + headers_frame.size(); 932 int joint_data_size = push_promise_frame.size() + headers_frame.size();
997 std::unique_ptr<char[]> data(new char[joint_data_size]); 933 std::unique_ptr<char[]> data(new char[joint_data_size]);
998 const SpdySerializedFrame* frames[2] = { 934 const SpdySerializedFrame* frames[2] = {
999 &push_promise_frame, &headers_frame, 935 &push_promise_frame, &headers_frame,
1000 }; 936 };
1001 int combined_size = 937 int combined_size =
1002 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); 938 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size);
1003 DCHECK_EQ(combined_size, joint_data_size); 939 DCHECK_EQ(combined_size, joint_data_size);
1004 return new SpdySerializedFrame(data.release(), joint_data_size, true); 940 return new SpdySerializedFrame(data.release(), joint_data_size, true);
1005 }
1006 } 941 }
1007 942
1008 SpdySerializedFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame( 943 SpdySerializedFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame(
1009 SpdyHeaderBlock headers, 944 SpdyHeaderBlock headers,
1010 int stream_id, 945 int stream_id,
1011 int associated_stream_id) { 946 int associated_stream_id) {
1012 if (spdy_version() < HTTP2) { 947 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id,
1013 SpdySynStreamIR syn_stream(stream_id, std::move(headers)); 948 std::move(headers));
1014 syn_stream.set_associated_to_stream_id(associated_stream_id); 949 return new SpdySerializedFrame(
1015 SetPriority(LOWEST, &syn_stream); 950 response_spdy_framer_.SerializeFrame(push_promise));
1016 return new SpdySerializedFrame(
1017 response_spdy_framer_.SerializeFrame(syn_stream));
1018 } else {
1019 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id,
1020 std::move(headers));
1021 return new SpdySerializedFrame(
1022 response_spdy_framer_.SerializeFrame(push_promise));
1023 }
1024 } 951 }
1025 952
1026 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPushHeaders( 953 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPushHeaders(
1027 int stream_id, 954 int stream_id,
1028 const char* const extra_headers[], 955 const char* const extra_headers[],
1029 int extra_header_count) { 956 int extra_header_count) {
1030 SpdyHeaderBlock header_block; 957 SpdyHeaderBlock header_block;
1031 header_block[GetStatusKey()] = "200"; 958 header_block[GetStatusKey()] = "200";
1032 MaybeAddVersionHeader(&header_block);
1033 AppendToHeaderBlock(extra_headers, extra_header_count, &header_block); 959 AppendToHeaderBlock(extra_headers, extra_header_count, &header_block);
1034 SpdyHeadersIR headers(stream_id, std::move(header_block)); 960 SpdyHeadersIR headers(stream_id, std::move(header_block));
1035 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(headers)); 961 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(headers));
1036 } 962 }
1037 963
1038 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyResponseHeaders( 964 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyResponseHeaders(
1039 int stream_id, 965 int stream_id,
1040 SpdyHeaderBlock headers, 966 SpdyHeaderBlock headers,
1041 bool fin) { 967 bool fin) {
1042 SpdyHeadersIR spdy_headers(stream_id, std::move(headers)); 968 SpdyHeadersIR spdy_headers(stream_id, std::move(headers));
(...skipping 17 matching lines...) Expand all
1060 int parent_stream_id = 0; 986 int parent_stream_id = 0;
1061 for (int q = priority; q <= HIGHEST; ++q) { 987 for (int q = priority; q <= HIGHEST; ++q) {
1062 if (!priority_to_stream_id_list_[q].empty()) { 988 if (!priority_to_stream_id_list_[q].empty()) {
1063 parent_stream_id = priority_to_stream_id_list_[q].back(); 989 parent_stream_id = priority_to_stream_id_list_[q].back();
1064 break; 990 break;
1065 } 991 }
1066 } 992 }
1067 993
1068 priority_to_stream_id_list_[priority].push_back(stream_id); 994 priority_to_stream_id_list_[priority].push_back(stream_id);
1069 995
1070 if (protocol_ < kProtoHTTP2) { 996 SpdyHeadersIR headers(stream_id, std::move(block));
1071 SpdySynStreamIR syn_stream(stream_id, std::move(block)); 997 headers.set_has_priority(true);
1072 syn_stream.set_priority( 998 headers.set_weight(Spdy3PriorityToHttp2Weight(
1073 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); 999 ConvertRequestPriorityToSpdyPriority(priority, HTTP2)));
1074 syn_stream.set_fin(fin); 1000 if (dependency_priorities_) {
1075 return new SpdySerializedFrame( 1001 headers.set_parent_stream_id(parent_stream_id);
1076 request_spdy_framer_.SerializeFrame(syn_stream)); 1002 headers.set_exclusive(true);
1077 } else {
1078 SpdyHeadersIR headers(stream_id, std::move(block));
1079 headers.set_has_priority(true);
1080 headers.set_weight(Spdy3PriorityToHttp2Weight(
1081 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())));
1082 if (dependency_priorities_) {
1083 headers.set_parent_stream_id(parent_stream_id);
1084 headers.set_exclusive(true);
1085 }
1086 headers.set_fin(fin);
1087 return new SpdySerializedFrame(
1088 request_spdy_framer_.SerializeFrame(headers));
1089 } 1003 }
1004 headers.set_fin(fin);
1005 return new SpdySerializedFrame(request_spdy_framer_.SerializeFrame(headers));
1090 } 1006 }
1091 1007
1092 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, 1008 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id,
1093 SpdyHeaderBlock headers) { 1009 SpdyHeaderBlock headers) {
1094 if (protocol_ < kProtoHTTP2) { 1010 SpdyHeadersIR reply(stream_id, std::move(headers));
1095 SpdySynReplyIR syn_reply(stream_id, std::move(headers)); 1011 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply));
1096 return new SpdySerializedFrame(
1097 response_spdy_framer_.SerializeFrame(syn_reply));
1098 } else {
1099 SpdyHeadersIR reply(stream_id, std::move(headers));
1100 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply));
1101 }
1102 } 1012 }
1103 1013
1104 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError( 1014 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError(
1105 const char* const status, 1015 const char* const status,
1106 const char* const* const extra_headers, 1016 const char* const* const extra_headers,
1107 int extra_header_count, 1017 int extra_header_count,
1108 int stream_id) { 1018 int stream_id) {
1109 SpdyHeaderBlock block; 1019 SpdyHeaderBlock block;
1110 block[GetStatusKey()] = status; 1020 block[GetStatusKey()] = status;
1111 MaybeAddVersionHeader(&block);
1112 block["hello"] = "bye"; 1021 block["hello"] = "bye";
1113 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1022 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1114 1023
1115 return ConstructSpdyReply(stream_id, std::move(block)); 1024 return ConstructSpdyReply(stream_id, std::move(block));
1116 } 1025 }
1117 1026
1118 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect( 1027 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect(
1119 int stream_id) { 1028 int stream_id) {
1120 static const char* const kExtraHeaders[] = { 1029 static const char* const kExtraHeaders[] = {
1121 "location", "http://www.foo.com/index.php", 1030 "location", "http://www.foo.com/index.php",
1122 }; 1031 };
1123 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, 1032 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders,
1124 arraysize(kExtraHeaders)/2, stream_id); 1033 arraysize(kExtraHeaders)/2, stream_id);
1125 } 1034 }
1126 1035
1127 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { 1036 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) {
1128 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); 1037 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1);
1129 } 1038 }
1130 1039
1131 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReply( 1040 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReply(
1132 const char* const extra_headers[], 1041 const char* const extra_headers[],
1133 int extra_header_count, 1042 int extra_header_count,
1134 int stream_id) { 1043 int stream_id) {
1135 SpdyHeaderBlock block; 1044 SpdyHeaderBlock block;
1136 block[GetStatusKey()] = "200"; 1045 block[GetStatusKey()] = "200";
1137 MaybeAddVersionHeader(&block);
1138 block["hello"] = "bye"; 1046 block["hello"] = "bye";
1139 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1047 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1140 1048
1141 return ConstructSpdyReply(stream_id, std::move(block)); 1049 return ConstructSpdyReply(stream_id, std::move(block));
1142 } 1050 }
1143 1051
1144 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPost( 1052 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPost(
1145 const char* url, 1053 const char* url,
1146 SpdyStreamId stream_id, 1054 SpdyStreamId stream_id,
1147 int64_t content_length, 1055 int64_t content_length,
1148 RequestPriority priority, 1056 RequestPriority priority,
1149 const char* const extra_headers[], 1057 const char* const extra_headers[],
1150 int extra_header_count) { 1058 int extra_header_count) {
1151 SpdyHeaderBlock block(ConstructPostHeaderBlock(url, content_length)); 1059 SpdyHeaderBlock block(ConstructPostHeaderBlock(url, content_length));
1152 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1060 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1153 return ConstructSpdySyn(stream_id, std::move(block), priority, false); 1061 return ConstructSpdySyn(stream_id, std::move(block), priority, false);
1154 } 1062 }
1155 1063
1156 SpdySerializedFrame* SpdyTestUtil::ConstructChunkedSpdyPost( 1064 SpdySerializedFrame* SpdyTestUtil::ConstructChunkedSpdyPost(
1157 const char* const extra_headers[], 1065 const char* const extra_headers[],
1158 int extra_header_count) { 1066 int extra_header_count) {
1159 SpdyHeaderBlock block; 1067 SpdyHeaderBlock block;
1160 MaybeAddVersionHeader(&block);
1161 block[GetMethodKey()] = "POST"; 1068 block[GetMethodKey()] = "POST";
1162 AddUrlToHeaderBlock(default_url_.spec(), &block); 1069 AddUrlToHeaderBlock(default_url_.spec(), &block);
1163 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1070 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1164 return ConstructSpdySyn(1, std::move(block), LOWEST, false); 1071 return ConstructSpdySyn(1, std::move(block), LOWEST, false);
1165 } 1072 }
1166 1073
1167 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPostSynReply( 1074 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPostSynReply(
1168 const char* const extra_headers[], 1075 const char* const extra_headers[],
1169 int extra_header_count) { 1076 int extra_header_count) {
1170 // TODO(jgraettinger): Remove this method. 1077 // TODO(jgraettinger): Remove this method.
1171 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1); 1078 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1);
1172 } 1079 }
1173 1080
1174 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, 1081 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id,
1175 bool fin) { 1082 bool fin) {
1176 SpdyFramer framer(spdy_version_); 1083 SpdyFramer framer(HTTP2);
1177 SpdyDataIR data_ir(stream_id, 1084 SpdyDataIR data_ir(stream_id,
1178 base::StringPiece(kUploadData, kUploadDataSize)); 1085 base::StringPiece(kUploadData, kUploadDataSize));
1179 data_ir.set_fin(fin); 1086 data_ir.set_fin(fin);
1180 return new SpdySerializedFrame(framer.SerializeData(data_ir)); 1087 return new SpdySerializedFrame(framer.SerializeData(data_ir));
1181 } 1088 }
1182 1089
1183 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, 1090 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id,
1184 const char* data, 1091 const char* data,
1185 uint32_t len, 1092 uint32_t len,
1186 bool fin) { 1093 bool fin) {
1187 SpdyFramer framer(spdy_version_); 1094 SpdyFramer framer(HTTP2);
1188 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); 1095 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len));
1189 data_ir.set_fin(fin); 1096 data_ir.set_fin(fin);
1190 return new SpdySerializedFrame(framer.SerializeData(data_ir)); 1097 return new SpdySerializedFrame(framer.SerializeData(data_ir));
1191 } 1098 }
1192 1099
1193 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, 1100 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id,
1194 const char* data, 1101 const char* data,
1195 uint32_t len, 1102 uint32_t len,
1196 bool fin, 1103 bool fin,
1197 int padding_length) { 1104 int padding_length) {
1198 SpdyFramer framer(spdy_version_); 1105 SpdyFramer framer(HTTP2);
1199 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); 1106 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len));
1200 data_ir.set_fin(fin); 1107 data_ir.set_fin(fin);
1201 data_ir.set_padding_len(padding_length); 1108 data_ir.set_padding_len(padding_length);
1202 return new SpdySerializedFrame(framer.SerializeData(data_ir)); 1109 return new SpdySerializedFrame(framer.SerializeData(data_ir));
1203 } 1110 }
1204 1111
1205 SpdySerializedFrame* SpdyTestUtil::ConstructWrappedSpdyFrame( 1112 SpdySerializedFrame* SpdyTestUtil::ConstructWrappedSpdyFrame(
1206 const std::unique_ptr<SpdySerializedFrame>& frame, 1113 const std::unique_ptr<SpdySerializedFrame>& frame,
1207 int stream_id) { 1114 int stream_id) {
1208 return ConstructSpdyBodyFrame(stream_id, frame->data(), 1115 return ConstructSpdyBodyFrame(stream_id, frame->data(),
(...skipping 20 matching lines...) Expand all
1229 1136
1230 const char* SpdyTestUtil::GetMethodKey() const { 1137 const char* SpdyTestUtil::GetMethodKey() const {
1231 return ":method"; 1138 return ":method";
1232 } 1139 }
1233 1140
1234 const char* SpdyTestUtil::GetStatusKey() const { 1141 const char* SpdyTestUtil::GetStatusKey() const {
1235 return ":status"; 1142 return ":status";
1236 } 1143 }
1237 1144
1238 const char* SpdyTestUtil::GetHostKey() const { 1145 const char* SpdyTestUtil::GetHostKey() const {
1239 if (protocol_ < kProtoHTTP2) 1146 return ":authority";
1240 return ":host";
1241 else
1242 return ":authority";
1243 } 1147 }
1244 1148
1245 const char* SpdyTestUtil::GetSchemeKey() const { 1149 const char* SpdyTestUtil::GetSchemeKey() const {
1246 return ":scheme"; 1150 return ":scheme";
1247 } 1151 }
1248 1152
1249 const char* SpdyTestUtil::GetVersionKey() const {
1250 return ":version";
1251 }
1252
1253 const char* SpdyTestUtil::GetPathKey() const { 1153 const char* SpdyTestUtil::GetPathKey() const {
1254 return ":path"; 1154 return ":path";
1255 } 1155 }
1256 1156
1257 SpdyHeaderBlock SpdyTestUtil::ConstructHeaderBlock( 1157 SpdyHeaderBlock SpdyTestUtil::ConstructHeaderBlock(
1258 base::StringPiece method, 1158 base::StringPiece method,
1259 base::StringPiece url, 1159 base::StringPiece url,
1260 int64_t* content_length) const { 1160 int64_t* content_length) const {
1261 std::string scheme, host, path; 1161 std::string scheme, host, path;
1262 ParseUrl(url.data(), &scheme, &host, &path); 1162 ParseUrl(url.data(), &scheme, &host, &path);
1263 SpdyHeaderBlock headers; 1163 SpdyHeaderBlock headers;
1264 if (include_version_header()) {
1265 headers[GetVersionKey()] = "HTTP/1.1";
1266 }
1267 headers[GetMethodKey()] = method.as_string(); 1164 headers[GetMethodKey()] = method.as_string();
1268 headers[GetHostKey()] = host.c_str(); 1165 headers[GetHostKey()] = host.c_str();
1269 headers[GetSchemeKey()] = scheme.c_str(); 1166 headers[GetSchemeKey()] = scheme.c_str();
1270 headers[GetPathKey()] = path.c_str(); 1167 headers[GetPathKey()] = path.c_str();
1271 if (content_length) { 1168 if (content_length) {
1272 std::string length_str = base::Int64ToString(*content_length); 1169 std::string length_str = base::Int64ToString(*content_length);
1273 headers["content-length"] = length_str; 1170 headers["content-length"] = length_str;
1274 } 1171 }
1275 return headers; 1172 return headers;
1276 } 1173 }
1277 1174
1278 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const {
1279 if (include_version_header()) {
1280 (*block)[GetVersionKey()] = "HTTP/1.1";
1281 }
1282 }
1283
1284 void SpdyTestUtil::SetPriority(RequestPriority priority, 1175 void SpdyTestUtil::SetPriority(RequestPriority priority,
1285 SpdySynStreamIR* ir) const { 1176 SpdySynStreamIR* ir) const {
1286 ir->set_priority(ConvertRequestPriorityToSpdyPriority( 1177 ir->set_priority(ConvertRequestPriorityToSpdyPriority(priority, HTTP2));
1287 priority, spdy_version()));
1288 } 1178 }
1289 1179
1290 } // namespace net 1180 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_test_util_common.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698