| 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/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/metrics/stats_counters.h" | |
| 16 #include "base/profiler/scoped_tracker.h" | 15 #include "base/profiler/scoped_tracker.h" |
| 17 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 20 #include "base/values.h" | 19 #include "base/values.h" |
| 21 #include "net/base/auth.h" | 20 #include "net/base/auth.h" |
| 22 #include "net/base/chunked_upload_data_stream.h" | 21 #include "net/base/chunked_upload_data_stream.h" |
| 23 #include "net/base/host_port_pair.h" | 22 #include "net/base/host_port_pair.h" |
| 24 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| 25 #include "net/base/load_timing_info.h" | 24 #include "net/base/load_timing_info.h" |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 FirstPartyURLPolicy first_party_url_policy) { | 462 FirstPartyURLPolicy first_party_url_policy) { |
| 464 DCHECK(!is_pending_); | 463 DCHECK(!is_pending_); |
| 465 first_party_url_policy_ = first_party_url_policy; | 464 first_party_url_policy_ = first_party_url_policy; |
| 466 } | 465 } |
| 467 | 466 |
| 468 void URLRequest::set_method(const std::string& method) { | 467 void URLRequest::set_method(const std::string& method) { |
| 469 DCHECK(!is_pending_); | 468 DCHECK(!is_pending_); |
| 470 method_ = method; | 469 method_ = method; |
| 471 } | 470 } |
| 472 | 471 |
| 473 // static | |
| 474 std::string URLRequest::ComputeMethodForRedirect( | |
| 475 const std::string& method, | |
| 476 int http_status_code) { | |
| 477 // For 303 redirects, all request methods except HEAD are converted to GET, | |
| 478 // as per the latest httpbis draft. The draft also allows POST requests to | |
| 479 // be converted to GETs when following 301/302 redirects, for historical | |
| 480 // reasons. Most major browsers do this and so shall we. Both RFC 2616 and | |
| 481 // the httpbis draft say to prompt the user to confirm the generation of new | |
| 482 // requests, other than GET and HEAD requests, but IE omits these prompts and | |
| 483 // so shall we. | |
| 484 // See: https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#sectio
n-7.3 | |
| 485 if ((http_status_code == 303 && method != "HEAD") || | |
| 486 ((http_status_code == 301 || http_status_code == 302) && | |
| 487 method == "POST")) { | |
| 488 return "GET"; | |
| 489 } | |
| 490 return method; | |
| 491 } | |
| 492 | |
| 493 void URLRequest::SetReferrer(const std::string& referrer) { | 472 void URLRequest::SetReferrer(const std::string& referrer) { |
| 494 DCHECK(!is_pending_); | 473 DCHECK(!is_pending_); |
| 495 GURL referrer_url(referrer); | 474 GURL referrer_url(referrer); |
| 496 if (referrer_url.is_valid()) { | 475 if (referrer_url.is_valid()) { |
| 497 referrer_ = referrer_url.GetAsReferrer().spec(); | 476 referrer_ = referrer_url.GetAsReferrer().spec(); |
| 498 } else { | 477 } else { |
| 499 referrer_ = referrer; | 478 referrer_ = referrer; |
| 500 } | 479 } |
| 501 } | 480 } |
| 502 | 481 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 identifier_(GenerateURLRequestIdentifier()), | 545 identifier_(GenerateURLRequestIdentifier()), |
| 567 calling_delegate_(false), | 546 calling_delegate_(false), |
| 568 use_blocked_by_as_load_param_(false), | 547 use_blocked_by_as_load_param_(false), |
| 569 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, | 548 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, |
| 570 base::Unretained(this))), | 549 base::Unretained(this))), |
| 571 has_notified_completion_(false), | 550 has_notified_completion_(false), |
| 572 received_response_content_length_(0), | 551 received_response_content_length_(0), |
| 573 creation_time_(base::TimeTicks::Now()), | 552 creation_time_(base::TimeTicks::Now()), |
| 574 notified_before_network_start_(false), | 553 notified_before_network_start_(false), |
| 575 cookie_store_(cookie_store ? cookie_store : context->cookie_store()) { | 554 cookie_store_(cookie_store ? cookie_store : context->cookie_store()) { |
| 576 SIMPLE_STATS_COUNTER("URLRequestCount"); | |
| 577 | |
| 578 // Sanity check out environment. | 555 // Sanity check out environment. |
| 579 DCHECK(base::MessageLoop::current()) | 556 DCHECK(base::MessageLoop::current()) |
| 580 << "The current base::MessageLoop must exist"; | 557 << "The current base::MessageLoop must exist"; |
| 581 | 558 |
| 582 context->url_requests()->insert(this); | 559 context->url_requests()->insert(this); |
| 583 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); | 560 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); |
| 584 } | 561 } |
| 585 | 562 |
| 586 void URLRequest::BeforeRequestComplete(int error) { | 563 void URLRequest::BeforeRequestComplete(int error) { |
| 587 DCHECK(!job_.get()); | 564 DCHECK(!job_.get()); |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 new base::debug::StackTrace(NULL, 0); | 1195 new base::debug::StackTrace(NULL, 0); |
| 1219 *stack_trace_copy = stack_trace; | 1196 *stack_trace_copy = stack_trace; |
| 1220 stack_trace_.reset(stack_trace_copy); | 1197 stack_trace_.reset(stack_trace_copy); |
| 1221 } | 1198 } |
| 1222 | 1199 |
| 1223 const base::debug::StackTrace* URLRequest::stack_trace() const { | 1200 const base::debug::StackTrace* URLRequest::stack_trace() const { |
| 1224 return stack_trace_.get(); | 1201 return stack_trace_.get(); |
| 1225 } | 1202 } |
| 1226 | 1203 |
| 1227 } // namespace net | 1204 } // namespace net |
| OLD | NEW |