| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "url_request_peer.h" | 5 #include "url_request_peer.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "net/base/load_flags.h" | 8 #include "net/base/load_flags.h" |
| 9 #include "net/http/http_status_code.h" | 9 #include "net/http/http_status_code.h" |
| 10 | 10 |
| 11 namespace cronet { | 11 namespace cronet { |
| 12 | 12 |
| 13 static const size_t kBufferSizeIncrement = 8192; | 13 static const size_t kBufferSizeIncrement = 8192; |
| 14 | 14 |
| 15 // Fragment automatically inserted in the User-Agent header to indicate | |
| 16 // that the request is coming from this network stack. | |
| 17 static const char kUserAgentFragment[] = "; ChromiumJNI/"; | |
| 18 | |
| 19 URLRequestPeer::URLRequestPeer(URLRequestContextPeer* context, | 15 URLRequestPeer::URLRequestPeer(URLRequestContextPeer* context, |
| 20 URLRequestPeerDelegate* delegate, | 16 URLRequestPeerDelegate* delegate, |
| 21 GURL url, | 17 GURL url, |
| 22 net::RequestPriority priority) | 18 net::RequestPriority priority) |
| 23 : method_("GET"), | 19 : method_("GET"), |
| 24 url_request_(NULL), | 20 url_request_(NULL), |
| 25 read_buffer_(new net::GrowableIOBuffer()), | 21 read_buffer_(new net::GrowableIOBuffer()), |
| 26 bytes_read_(0), | 22 bytes_read_(0), |
| 27 total_bytes_read_(0), | 23 total_bytes_read_(0), |
| 28 error_code_(0), | 24 error_code_(0), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 VLOG(context_->logging_level()) | 99 VLOG(context_->logging_level()) |
| 104 << "Starting chromium request: " << url_.possibly_invalid_spec().c_str() | 100 << "Starting chromium request: " << url_.possibly_invalid_spec().c_str() |
| 105 << " priority: " << RequestPriorityToString(priority_); | 101 << " priority: " << RequestPriorityToString(priority_); |
| 106 url_request_ = new net::URLRequest( | 102 url_request_ = new net::URLRequest( |
| 107 url_, net::DEFAULT_PRIORITY, this, context_->GetURLRequestContext()); | 103 url_, net::DEFAULT_PRIORITY, this, context_->GetURLRequestContext()); |
| 108 url_request_->SetLoadFlags(net::LOAD_DISABLE_CACHE | | 104 url_request_->SetLoadFlags(net::LOAD_DISABLE_CACHE | |
| 109 net::LOAD_DO_NOT_SAVE_COOKIES | | 105 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 110 net::LOAD_DO_NOT_SEND_COOKIES); | 106 net::LOAD_DO_NOT_SEND_COOKIES); |
| 111 url_request_->set_method(method_); | 107 url_request_->set_method(method_); |
| 112 url_request_->SetExtraRequestHeaders(headers_); | 108 url_request_->SetExtraRequestHeaders(headers_); |
| 113 std::string user_agent; | 109 if (!headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) { |
| 114 if (headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) { | 110 std::string user_agent; |
| 115 headers_.GetHeader(net::HttpRequestHeaders::kUserAgent, &user_agent); | |
| 116 } else { | |
| 117 user_agent = context_->GetUserAgent(url_); | 111 user_agent = context_->GetUserAgent(url_); |
| 112 url_request_->SetExtraRequestHeaderByName( |
| 113 net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */); |
| 118 } | 114 } |
| 119 size_t pos = user_agent.find(')'); | |
| 120 if (pos != std::string::npos) { | |
| 121 user_agent.insert(pos, context_->version()); | |
| 122 user_agent.insert(pos, kUserAgentFragment); | |
| 123 } | |
| 124 url_request_->SetExtraRequestHeaderByName( | |
| 125 net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */); | |
| 126 | |
| 127 VLOG(context_->logging_level()) << "User agent: " << user_agent; | |
| 128 | 115 |
| 129 if (upload_data_stream_) { | 116 if (upload_data_stream_) { |
| 130 url_request_->set_upload(make_scoped_ptr(upload_data_stream_.release())); | 117 url_request_->set_upload(make_scoped_ptr(upload_data_stream_.release())); |
| 131 } else if (streaming_upload_) { | 118 } else if (streaming_upload_) { |
| 132 url_request_->EnableChunkedUpload(); | 119 url_request_->EnableChunkedUpload(); |
| 133 } | 120 } |
| 134 | 121 |
| 135 url_request_->SetPriority(priority_); | 122 url_request_->SetPriority(priority_); |
| 136 | 123 |
| 137 url_request_->Start(); | 124 url_request_->Start(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 271 |
| 285 delegate_->OnBytesRead(this); | 272 delegate_->OnBytesRead(this); |
| 286 delegate_->OnRequestFinished(this); | 273 delegate_->OnRequestFinished(this); |
| 287 } | 274 } |
| 288 | 275 |
| 289 unsigned char* URLRequestPeer::Data() const { | 276 unsigned char* URLRequestPeer::Data() const { |
| 290 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); | 277 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); |
| 291 } | 278 } |
| 292 | 279 |
| 293 } // namespace cronet | 280 } // namespace cronet |
| OLD | NEW |