Chromium Code Reviews| 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/url_request/url_request.h" | 5 #include "net/url_request/url_request.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/debug/stack_trace.h" | 11 #include "base/debug/stack_trace.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/metrics/stats_counters.h" | 15 #include "base/metrics/stats_counters.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "net/base/auth.h" | 18 #include "net/base/auth.h" |
| 19 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
| 20 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
| 21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 #include "net/base/net_log.h" | 22 #include "net/base/net_log.h" |
| 23 #include "net/base/network_change_notifier.h" | 23 #include "net/base/network_change_notifier.h" |
| 24 #include "net/base/network_delegate.h" | 24 #include "net/base/network_delegate.h" |
| 25 #include "net/base/ssl_cert_request_info.h" | 25 #include "net/base/ssl_cert_request_info.h" |
| 26 #include "net/base/upload_data.h" | 26 #include "net/base/upload_data.h" |
| 27 #include "net/base/upload_data_stream.h" | |
| 27 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
| 28 #include "net/http/http_util.h" | 29 #include "net/http/http_util.h" |
| 29 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| 30 #include "net/url_request/url_request_error_job.h" | 31 #include "net/url_request/url_request_error_job.h" |
| 31 #include "net/url_request/url_request_job.h" | 32 #include "net/url_request/url_request_job.h" |
| 32 #include "net/url_request/url_request_job_manager.h" | 33 #include "net/url_request/url_request_job_manager.h" |
| 33 #include "net/url_request/url_request_netlog_params.h" | 34 #include "net/url_request/url_request_netlog_params.h" |
| 34 #include "net/url_request/url_request_redirect_job.h" | 35 #include "net/url_request/url_request_redirect_job.h" |
| 35 | 36 |
| 36 using base::Time; | 37 using base::Time; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 // URLRequest | 136 // URLRequest |
| 136 | 137 |
| 137 // TODO(shalev): Get rid of this constructor in favour of the one below it. | 138 // TODO(shalev): Get rid of this constructor in favour of the one below it. |
| 138 URLRequest::URLRequest(const GURL& url, | 139 URLRequest::URLRequest(const GURL& url, |
| 139 Delegate* delegate, | 140 Delegate* delegate, |
| 140 const URLRequestContext* context) | 141 const URLRequestContext* context) |
| 141 : context_(context), | 142 : context_(context), |
| 142 network_delegate_(context->network_delegate()), | 143 network_delegate_(context->network_delegate()), |
| 143 net_log_(BoundNetLog::Make(context->net_log(), | 144 net_log_(BoundNetLog::Make(context->net_log(), |
| 144 NetLog::SOURCE_URL_REQUEST)), | 145 NetLog::SOURCE_URL_REQUEST)), |
| 146 disable_upload_(false), | |
| 145 url_chain_(1, url), | 147 url_chain_(1, url), |
| 146 method_("GET"), | 148 method_("GET"), |
| 147 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), | 149 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), |
| 148 load_flags_(LOAD_NORMAL), | 150 load_flags_(LOAD_NORMAL), |
| 149 delegate_(delegate), | 151 delegate_(delegate), |
| 150 is_pending_(false), | 152 is_pending_(false), |
| 151 is_redirecting_(false), | 153 is_redirecting_(false), |
| 152 redirect_limit_(kMaxRedirects), | 154 redirect_limit_(kMaxRedirects), |
| 153 priority_(LOWEST), | 155 priority_(LOWEST), |
| 154 identifier_(GenerateURLRequestIdentifier()), | 156 identifier_(GenerateURLRequestIdentifier()), |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 174 } | 176 } |
| 175 | 177 |
| 176 URLRequest::URLRequest(const GURL& url, | 178 URLRequest::URLRequest(const GURL& url, |
| 177 Delegate* delegate, | 179 Delegate* delegate, |
| 178 const URLRequestContext* context, | 180 const URLRequestContext* context, |
| 179 NetworkDelegate* network_delegate) | 181 NetworkDelegate* network_delegate) |
| 180 : context_(context), | 182 : context_(context), |
| 181 network_delegate_(network_delegate), | 183 network_delegate_(network_delegate), |
| 182 net_log_(BoundNetLog::Make(context->net_log(), | 184 net_log_(BoundNetLog::Make(context->net_log(), |
| 183 NetLog::SOURCE_URL_REQUEST)), | 185 NetLog::SOURCE_URL_REQUEST)), |
| 186 disable_upload_(false), | |
| 184 url_chain_(1, url), | 187 url_chain_(1, url), |
| 185 method_("GET"), | 188 method_("GET"), |
| 186 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), | 189 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), |
| 187 load_flags_(LOAD_NORMAL), | 190 load_flags_(LOAD_NORMAL), |
| 188 delegate_(delegate), | 191 delegate_(delegate), |
| 189 is_pending_(false), | 192 is_pending_(false), |
| 190 is_redirecting_(false), | 193 is_redirecting_(false), |
| 191 redirect_limit_(kMaxRedirects), | 194 redirect_limit_(kMaxRedirects), |
| 192 priority_(LOWEST), | 195 priority_(LOWEST), |
| 193 identifier_(GenerateURLRequestIdentifier()), | 196 identifier_(GenerateURLRequestIdentifier()), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { | 249 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { |
| 247 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); | 250 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); |
| 248 } | 251 } |
| 249 | 252 |
| 250 // static | 253 // static |
| 251 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { | 254 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { |
| 252 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( | 255 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( |
| 253 interceptor); | 256 interceptor); |
| 254 } | 257 } |
| 255 | 258 |
| 256 void URLRequest::AppendBytesToUpload(const char* bytes, int bytes_len) { | |
| 257 DCHECK(bytes_len > 0 && bytes); | |
| 258 if (!upload_) | |
| 259 upload_ = new UploadData(); | |
| 260 upload_->AppendBytes(bytes, bytes_len); | |
| 261 } | |
| 262 | |
| 263 void URLRequest::EnableChunkedUpload() { | 259 void URLRequest::EnableChunkedUpload() { |
| 264 DCHECK(!upload_ || upload_->is_chunked()); | 260 DCHECK(!upload_ || upload_->is_chunked()); |
| 265 if (!upload_) { | 261 if (!upload_) { |
| 266 upload_ = new UploadData(); | 262 upload_ = new UploadData(); |
| 267 upload_->set_is_chunked(true); | 263 upload_->set_is_chunked(true); |
| 264 upload_data_stream_.reset(new UploadDataStream(upload_)); | |
| 268 } | 265 } |
| 269 } | 266 } |
| 270 | 267 |
| 271 void URLRequest::AppendChunkToUpload(const char* bytes, | 268 void URLRequest::AppendChunkToUpload(const char* bytes, |
| 272 int bytes_len, | 269 int bytes_len, |
| 273 bool is_last_chunk) { | 270 bool is_last_chunk) { |
| 274 DCHECK(upload_); | 271 DCHECK(upload_); |
| 275 DCHECK(upload_->is_chunked()); | 272 DCHECK(upload_->is_chunked()); |
| 276 DCHECK_GT(bytes_len, 0); | 273 DCHECK_GT(bytes_len, 0); |
| 277 upload_->AppendChunk(bytes, bytes_len, is_last_chunk); | 274 upload_->AppendChunk(bytes, bytes_len, is_last_chunk); |
| 278 } | 275 } |
| 279 | 276 |
| 280 void URLRequest::set_upload(UploadData* upload) { | 277 void URLRequest::set_upload(UploadData* upload) { |
| 281 upload_ = upload; | 278 upload_ = upload; |
| 279 upload_data_stream_.reset(new UploadDataStream(upload_)); | |
| 282 } | 280 } |
| 283 | 281 |
| 284 // Get the upload data directly. | 282 const UploadDataStream* URLRequest::get_upload() const { |
|
mmenke
2012/11/19 17:21:21
For this function and the next, what if disable_up
hashimoto
2012/11/20 07:48:46
Removed disable_upload_.
| |
| 285 const UploadData* URLRequest::get_upload() const { | 283 return upload_data_stream_.get(); |
| 286 return upload_.get(); | |
| 287 } | |
| 288 | |
| 289 UploadData* URLRequest::get_upload_mutable() { | |
| 290 return upload_.get(); | |
| 291 } | 284 } |
| 292 | 285 |
| 293 bool URLRequest::has_upload() const { | 286 bool URLRequest::has_upload() const { |
| 294 return upload_ != NULL; | 287 return upload_data_stream_.get() != NULL; |
| 295 } | 288 } |
| 296 | 289 |
| 297 void URLRequest::SetExtraRequestHeaderById(int id, const string& value, | 290 void URLRequest::SetExtraRequestHeaderById(int id, const string& value, |
| 298 bool overwrite) { | 291 bool overwrite) { |
| 299 DCHECK(!is_pending_ || is_redirecting_); | 292 DCHECK(!is_pending_ || is_redirecting_); |
| 300 NOTREACHED() << "implement me!"; | 293 NOTREACHED() << "implement me!"; |
| 301 } | 294 } |
| 302 | 295 |
| 303 void URLRequest::SetExtraRequestHeaderByName(const string& name, | 296 void URLRequest::SetExtraRequestHeaderByName(const string& name, |
| 304 const string& value, | 297 const string& value, |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 | 516 |
| 524 net_log_.BeginEvent( | 517 net_log_.BeginEvent( |
| 525 NetLog::TYPE_URL_REQUEST_START_JOB, | 518 NetLog::TYPE_URL_REQUEST_START_JOB, |
| 526 base::Bind(&NetLogURLRequestStartCallback, | 519 base::Bind(&NetLogURLRequestStartCallback, |
| 527 &url(), &method_, load_flags_, priority_, | 520 &url(), &method_, load_flags_, priority_, |
| 528 upload_.get() ? upload_->identifier() : -1)); | 521 upload_.get() ? upload_->identifier() : -1)); |
| 529 | 522 |
| 530 job_ = job; | 523 job_ = job; |
| 531 job_->SetExtraRequestHeaders(extra_request_headers_); | 524 job_->SetExtraRequestHeaders(extra_request_headers_); |
| 532 | 525 |
| 533 if (upload_.get()) | 526 if (upload_data_stream_.get() && !disable_upload_) |
| 534 job_->SetUpload(upload_.get()); | 527 job_->SetUpload(upload_data_stream_.get()); |
| 535 | 528 |
| 536 is_pending_ = true; | 529 is_pending_ = true; |
| 537 is_redirecting_ = false; | 530 is_redirecting_ = false; |
| 538 | 531 |
| 539 response_info_.was_cached = false; | 532 response_info_.was_cached = false; |
| 540 | 533 |
| 541 // Don't allow errors to be sent from within Start(). | 534 // Don't allow errors to be sent from within Start(). |
| 542 // TODO(brettw) this may cause NotifyDone to be sent synchronously, | 535 // TODO(brettw) this may cause NotifyDone to be sent synchronously, |
| 543 // we probably don't want this: they should be sent asynchronously so | 536 // we probably don't want this: they should be sent asynchronously so |
| 544 // the caller does not get reentered. | 537 // the caller does not get reentered. |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 // be converted to GETs when following 301/302 redirects, for historical | 771 // be converted to GETs when following 301/302 redirects, for historical |
| 779 // reasons. Most major browsers do this and so shall we. Both RFC 2616 and | 772 // reasons. Most major browsers do this and so shall we. Both RFC 2616 and |
| 780 // the httpbis draft say to prompt the user to confirm the generation of new | 773 // the httpbis draft say to prompt the user to confirm the generation of new |
| 781 // requests, other than GET and HEAD requests, but IE omits these prompts and | 774 // requests, other than GET and HEAD requests, but IE omits these prompts and |
| 782 // so shall we. | 775 // so shall we. |
| 783 // See: https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#sectio n-7.3 | 776 // See: https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#sectio n-7.3 |
| 784 bool was_post = method_ == "POST"; | 777 bool was_post = method_ == "POST"; |
| 785 if ((http_status_code == 303 && method_ != "HEAD") || | 778 if ((http_status_code == 303 && method_ != "HEAD") || |
| 786 ((http_status_code == 301 || http_status_code == 302) && was_post)) { | 779 ((http_status_code == 301 || http_status_code == 302) && was_post)) { |
| 787 method_ = "GET"; | 780 method_ = "GET"; |
| 788 upload_ = NULL; | 781 disable_upload_ = true; |
|
mmenke
2012/11/19 17:21:21
Why do we need to keep the stream around? Since w
hashimoto
2012/11/20 07:48:46
I thought it's good to disable the stream instead
| |
| 789 if (was_post) { | 782 if (was_post) { |
| 790 // If being switched from POST to GET, must remove headers that were | 783 // If being switched from POST to GET, must remove headers that were |
| 791 // specific to the POST and don't have meaning in GET. For example | 784 // specific to the POST and don't have meaning in GET. For example |
| 792 // the inclusion of a multipart Content-Type header in GET can cause | 785 // the inclusion of a multipart Content-Type header in GET can cause |
| 793 // problems with some servers: | 786 // problems with some servers: |
| 794 // http://code.google.com/p/chromium/issues/detail?id=843 | 787 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 795 StripPostSpecificHeaders(&extra_request_headers_); | 788 StripPostSpecificHeaders(&extra_request_headers_); |
| 796 } | 789 } |
| 797 } | 790 } |
| 798 | 791 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 987 new base::debug::StackTrace(NULL, 0); | 980 new base::debug::StackTrace(NULL, 0); |
| 988 *stack_trace_copy = stack_trace; | 981 *stack_trace_copy = stack_trace; |
| 989 stack_trace_.reset(stack_trace_copy); | 982 stack_trace_.reset(stack_trace_copy); |
| 990 } | 983 } |
| 991 | 984 |
| 992 const base::debug::StackTrace* URLRequest::stack_trace() const { | 985 const base::debug::StackTrace* URLRequest::stack_trace() const { |
| 993 return stack_trace_.get(); | 986 return stack_trace_.get(); |
| 994 } | 987 } |
| 995 | 988 |
| 996 } // namespace net | 989 } // namespace net |
| OLD | NEW |