| 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" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 stream_ = NULL; // Always force creation of a stream for SendMessage. | 208 stream_ = NULL; // Always force creation of a stream for SendMessage. |
| 209 | 209 |
| 210 // If we're not connected, try to find an sni hostname. | 210 // If we're not connected, try to find an sni hostname. |
| 211 if (!connected()) { | 211 if (!connected()) { |
| 212 GURL url(message.headers()->request_uri().as_string()); | 212 GURL url(message.headers()->request_uri().as_string()); |
| 213 if (!url.host().empty()) { | 213 if (!url.host().empty()) { |
| 214 client_->set_server_hostname(url.host()); | 214 client_->set_server_hostname(url.host()); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 QuicReliableClientStream* stream = GetOrCreateStream(); | 218 QuicSpdyClientStream* stream = GetOrCreateStream(); |
| 219 if (!stream) { return 0; } | 219 if (!stream) { return 0; } |
| 220 | 220 |
| 221 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(), | 221 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(), |
| 222 secure_)); | 222 secure_)); |
| 223 ssize_t ret = GetOrCreateStream()->SendRequest( | 223 ssize_t ret = GetOrCreateStream()->SendRequest( |
| 224 munged_headers.get() ? *munged_headers.get() : *message.headers(), | 224 munged_headers.get() ? *munged_headers.get() : *message.headers(), |
| 225 message.body(), | 225 message.body(), |
| 226 message.has_complete_message()); | 226 message.has_complete_message()); |
| 227 WaitForWriteToFlush(); | 227 WaitForWriteToFlush(); |
| 228 return ret; | 228 return ret; |
| 229 } | 229 } |
| 230 | 230 |
| 231 ssize_t QuicTestClient::SendData(string data, bool last_data) { | 231 ssize_t QuicTestClient::SendData(string data, bool last_data) { |
| 232 QuicReliableClientStream* stream = GetOrCreateStream(); | 232 QuicSpdyClientStream* stream = GetOrCreateStream(); |
| 233 if (!stream) { return 0; } | 233 if (!stream) { return 0; } |
| 234 GetOrCreateStream()->SendBody(data, last_data); | 234 GetOrCreateStream()->SendBody(data, last_data); |
| 235 WaitForWriteToFlush(); | 235 WaitForWriteToFlush(); |
| 236 return data.length(); | 236 return data.length(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 string QuicTestClient::SendCustomSynchronousRequest( | 239 string QuicTestClient::SendCustomSynchronousRequest( |
| 240 const HTTPMessage& message) { | 240 const HTTPMessage& message) { |
| 241 SendMessage(message); | 241 SendMessage(message); |
| 242 WaitForResponse(); | 242 WaitForResponse(); |
| 243 return response_; | 243 return response_; |
| 244 } | 244 } |
| 245 | 245 |
| 246 string QuicTestClient::SendSynchronousRequest(const string& uri) { | 246 string QuicTestClient::SendSynchronousRequest(const string& uri) { |
| 247 if (SendRequest(uri) == 0) { | 247 if (SendRequest(uri) == 0) { |
| 248 DLOG(ERROR) << "Failed the request for uri:" << uri; | 248 DLOG(ERROR) << "Failed the request for uri:" << uri; |
| 249 return ""; | 249 return ""; |
| 250 } | 250 } |
| 251 WaitForResponse(); | 251 WaitForResponse(); |
| 252 return response_; | 252 return response_; |
| 253 } | 253 } |
| 254 | 254 |
| 255 QuicReliableClientStream* QuicTestClient::GetOrCreateStream() { | 255 QuicSpdyClientStream* QuicTestClient::GetOrCreateStream() { |
| 256 if (!connect_attempted_ || auto_reconnect_) { | 256 if (!connect_attempted_ || auto_reconnect_) { |
| 257 if (!connected()) { | 257 if (!connected()) { |
| 258 Connect(); | 258 Connect(); |
| 259 } | 259 } |
| 260 if (!connected()) { | 260 if (!connected()) { |
| 261 return NULL; | 261 return NULL; |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 if (!stream_) { | 264 if (!stream_) { |
| 265 stream_ = client_->CreateReliableClientStream(); | 265 stream_ = client_->CreateReliableClientStream(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 431 |
| 432 void QuicTestClient::WaitForWriteToFlush() { | 432 void QuicTestClient::WaitForWriteToFlush() { |
| 433 while (connected() && client()->session()->HasQueuedData()) { | 433 while (connected() && client()->session()->HasQueuedData()) { |
| 434 client_->WaitForEvents(); | 434 client_->WaitForEvents(); |
| 435 } | 435 } |
| 436 } | 436 } |
| 437 | 437 |
| 438 } // namespace test | 438 } // namespace test |
| 439 } // namespace tools | 439 } // namespace tools |
| 440 } // namespace net | 440 } // namespace net |
| OLD | NEW |