| 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/tools/quic/test_tools/quic_test_client.h" | 5 #include "net/tools/quic/test_tools/quic_test_client.h" |
| 6 | 6 |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "net/base/completion_callback.h" | 8 #include "net/base/completion_callback.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/cert/cert_verify_result.h" | 10 #include "net/cert/cert_verify_result.h" |
| 11 #include "net/cert/x509_certificate.h" | 11 #include "net/cert/x509_certificate.h" |
| 12 #include "net/quic/crypto/proof_verifier.h" | 12 #include "net/quic/crypto/proof_verifier.h" |
| 13 #include "net/quic/quic_server_id.h" | 13 #include "net/quic/quic_server_id.h" |
| 14 #include "net/quic/test_tools/quic_connection_peer.h" | 14 #include "net/quic/test_tools/quic_connection_peer.h" |
| 15 #include "net/quic/test_tools/quic_session_peer.h" | 15 #include "net/quic/test_tools/quic_session_peer.h" |
| 16 #include "net/quic/test_tools/quic_test_utils.h" | 16 #include "net/quic/test_tools/quic_test_utils.h" |
| 17 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | 17 #include "net/quic/test_tools/reliable_quic_stream_peer.h" |
| 18 #include "net/tools/balsa/balsa_headers.h" | 18 #include "net/tools/balsa/balsa_headers.h" |
| 19 #include "net/tools/quic/quic_epoll_connection_helper.h" | 19 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 20 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 20 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
| 21 #include "net/tools/quic/quic_spdy_client_stream.h" | 21 #include "net/tools/quic/quic_spdy_client_stream.h" |
| 22 #include "net/tools/quic/spdy_utils.h" |
| 22 #include "net/tools/quic/test_tools/http_message.h" | 23 #include "net/tools/quic/test_tools/http_message.h" |
| 23 #include "net/tools/quic/test_tools/quic_client_peer.h" | 24 #include "net/tools/quic/test_tools/quic_client_peer.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 using base::StringPiece; | 27 using base::StringPiece; |
| 27 using net::QuicServerId; | 28 using net::QuicServerId; |
| 28 using net::test::QuicConnectionPeer; | 29 using net::test::QuicConnectionPeer; |
| 29 using net::test::QuicSessionPeer; | 30 using net::test::QuicSessionPeer; |
| 30 using net::test::ReliableQuicStreamPeer; | 31 using net::test::ReliableQuicStreamPeer; |
| 31 using std::string; | 32 using std::string; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 PRIVACY_MODE_DISABLED)); | 249 PRIVACY_MODE_DISABLED)); |
| 249 } | 250 } |
| 250 } | 251 } |
| 251 | 252 |
| 252 QuicSpdyClientStream* stream = GetOrCreateStream(); | 253 QuicSpdyClientStream* stream = GetOrCreateStream(); |
| 253 if (!stream) { return 0; } | 254 if (!stream) { return 0; } |
| 254 | 255 |
| 255 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(), | 256 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(), |
| 256 secure_)); | 257 secure_)); |
| 257 ssize_t ret = GetOrCreateStream()->SendRequest( | 258 ssize_t ret = GetOrCreateStream()->SendRequest( |
| 258 munged_headers.get() ? *munged_headers : *message.headers(), | 259 SpdyUtils::RequestHeadersToSpdyHeaders( |
| 260 munged_headers.get() ? *munged_headers : *message.headers()), |
| 259 message.body(), message.has_complete_message()); | 261 message.body(), message.has_complete_message()); |
| 260 WaitForWriteToFlush(); | 262 WaitForWriteToFlush(); |
| 261 return ret; | 263 return ret; |
| 262 } | 264 } |
| 263 | 265 |
| 264 ssize_t QuicTestClient::SendData(string data, bool last_data) { | 266 ssize_t QuicTestClient::SendData(string data, bool last_data) { |
| 265 return SendData(data, last_data, nullptr); | 267 return SendData(data, last_data, nullptr); |
| 266 } | 268 } |
| 267 | 269 |
| 268 ssize_t QuicTestClient::SendData(string data, | 270 ssize_t QuicTestClient::SendData(string data, |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 451 } |
| 450 } | 452 } |
| 451 | 453 |
| 452 ssize_t QuicTestClient::Send(const void *buffer, size_t size) { | 454 ssize_t QuicTestClient::Send(const void *buffer, size_t size) { |
| 453 return SendData(string(static_cast<const char*>(buffer), size), false); | 455 return SendData(string(static_cast<const char*>(buffer), size), false); |
| 454 } | 456 } |
| 455 | 457 |
| 456 bool QuicTestClient::response_headers_complete() const { | 458 bool QuicTestClient::response_headers_complete() const { |
| 457 if (stream_ != nullptr) { | 459 if (stream_ != nullptr) { |
| 458 return stream_->headers_decompressed(); | 460 return stream_->headers_decompressed(); |
| 459 } else { | |
| 460 return response_headers_complete_; | |
| 461 } | 461 } |
| 462 return response_headers_complete_; |
| 462 } | 463 } |
| 463 | 464 |
| 464 const BalsaHeaders* QuicTestClient::response_headers() const { | 465 const BalsaHeaders* QuicTestClient::response_headers() const { |
| 465 if (stream_ != nullptr) { | 466 if (stream_ != nullptr) { |
| 466 return &stream_->headers(); | 467 SpdyUtils::SpdyHeadersToResponseHeaders(stream_->headers(), &headers_); |
| 468 return &headers_; |
| 467 } else { | 469 } else { |
| 468 return &headers_; | 470 return &headers_; |
| 469 } | 471 } |
| 470 } | 472 } |
| 471 | 473 |
| 472 int64 QuicTestClient::response_size() const { | 474 int64 QuicTestClient::response_size() const { |
| 473 return bytes_read_; | 475 return bytes_read_; |
| 474 } | 476 } |
| 475 | 477 |
| 476 size_t QuicTestClient::bytes_read() const { | 478 size_t QuicTestClient::bytes_read() const { |
| 477 return bytes_read_; | 479 return bytes_read_; |
| 478 } | 480 } |
| 479 | 481 |
| 480 size_t QuicTestClient::bytes_written() const { | 482 size_t QuicTestClient::bytes_written() const { |
| 481 return bytes_written_; | 483 return bytes_written_; |
| 482 } | 484 } |
| 483 | 485 |
| 484 void QuicTestClient::OnClose(QuicDataStream* stream) { | 486 void QuicTestClient::OnClose(QuicDataStream* stream) { |
| 485 if (stream_ != stream) { | 487 if (stream_ != stream) { |
| 486 return; | 488 return; |
| 487 } | 489 } |
| 488 if (buffer_body()) { | 490 if (buffer_body()) { |
| 489 // TODO(fnk): The stream still buffers the whole thing. Fix that. | 491 // TODO(fnk): The stream still buffers the whole thing. Fix that. |
| 490 response_ = stream_->data(); | 492 response_ = stream_->data(); |
| 491 } | 493 } |
| 492 response_complete_ = true; | 494 response_complete_ = true; |
| 493 response_headers_complete_ = stream_->headers_decompressed(); | 495 response_headers_complete_ = stream_->headers_decompressed(); |
| 494 headers_.CopyFrom(stream_->headers()); | 496 SpdyUtils::SpdyHeadersToResponseHeaders(stream_->headers(), |
| 497 &headers_); |
| 495 stream_error_ = stream_->stream_error(); | 498 stream_error_ = stream_->stream_error(); |
| 496 bytes_read_ = stream_->stream_bytes_read() + stream_->header_bytes_read(); | 499 bytes_read_ = stream_->stream_bytes_read() + stream_->header_bytes_read(); |
| 497 bytes_written_ = | 500 bytes_written_ = |
| 498 stream_->stream_bytes_written() + stream_->header_bytes_written(); | 501 stream_->stream_bytes_written() + stream_->header_bytes_written(); |
| 499 response_header_size_ = headers_.GetSizeForWriteBuffer(); | 502 response_header_size_ = headers_.GetSizeForWriteBuffer(); |
| 500 response_body_size_ = stream_->data().size(); | 503 response_body_size_ = stream_->data().size(); |
| 501 stream_ = nullptr; | 504 stream_ = nullptr; |
| 502 } | 505 } |
| 503 | 506 |
| 504 void QuicTestClient::UseWriter(QuicPacketWriterWrapper* writer) { | 507 void QuicTestClient::UseWriter(QuicPacketWriterWrapper* writer) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 // Set policy for headers and crypto streams. | 557 // Set policy for headers and crypto streams. |
| 555 ReliableQuicStreamPeer::SetFecPolicy( | 558 ReliableQuicStreamPeer::SetFecPolicy( |
| 556 QuicSessionPeer::GetHeadersStream(client()->session()), fec_policy); | 559 QuicSessionPeer::GetHeadersStream(client()->session()), fec_policy); |
| 557 ReliableQuicStreamPeer::SetFecPolicy(client()->session()->GetCryptoStream(), | 560 ReliableQuicStreamPeer::SetFecPolicy(client()->session()->GetCryptoStream(), |
| 558 fec_policy); | 561 fec_policy); |
| 559 } | 562 } |
| 560 | 563 |
| 561 } // namespace test | 564 } // namespace test |
| 562 } // namespace tools | 565 } // namespace tools |
| 563 } // namespace net | 566 } // namespace net |
| OLD | NEW |