url_request.h revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_URL_REQUEST_URL_REQUEST_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_URL_REQUEST_URL_REQUEST_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/debug/leak_tracker.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/supports_user_data.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/non_thread_safe.h"
17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/auth.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/completion_callback.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/load_states.h"
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/load_timing_info.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_export.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_log.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/network_delegate.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/request_priority.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/upload_progress.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/canonical_cookie.h"
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "net/cookies/cookie_store.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_request_headers.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_response_info.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_status.h"
327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface.
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ChildProcessSecurityPolicyTest;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class Value;
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace debug {
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class StackTrace;
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace debug
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace base
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface.
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace appcache {
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AppCacheRequestHandlerTest;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AppCacheURLRequestJobTest;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
56e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochclass AppCacheInterceptor;
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class BlobURLRequestJobTest;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileSystemDirURLRequestJobTest;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileSystemURLRequestJobTest;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileWriterDelegateTest;
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ResourceDispatcherHostTest;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CookieOptions;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HostPortPair;
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class IOBuffer;
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct LoadTimingInfo;
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SSLCertRequestInfo;
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SSLInfo;
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class UploadDataStream;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestContext;
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestJob;
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class X509Certificate;
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This stores the values of the Set-Cookie headers received during the request.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Each item in the vector corresponds to a Set-Cookie: line received,
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// excluding the "Set-Cookie:" part.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef std::vector<std::string> ResponseCookies;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//-----------------------------------------------------------------------------
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A class  representing the asynchronous load of a data stream from an URL.
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The lifetime of an instance of this class is completely controlled by the
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// consumer, and the instance is not required to live on the heap or be
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// allocated in any special way.  It is also valid to delete an URLRequest
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// object during the handling of a callback to its delegate.  Of course, once
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the URLRequest is deleted, no further callbacks to its delegate will occur.
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: All usage of all instances of this class should be on the same thread.
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              public base::SupportsUserData {
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Callback function implemented by protocol handlers to create new jobs.
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The factory may return NULL to indicate an error, which will cause other
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // factories to be queried.  If no factory handles the request, then the
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // default job will be used.
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef URLRequestJob* (ProtocolFactory)(URLRequest* request,
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           NetworkDelegate* network_delegate,
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           const std::string& scheme);
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HTTP request/response header IDs (via some preprocessor fun) for use with
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // SetRequestHeaderById and GetResponseHeaderById.
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum {
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define HTTP_ATOM(x) HTTP_ ## x,
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_atom_list.h"
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#undef HTTP_ATOM
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Referrer policies (see set_referrer_policy): During server redirects, the
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // referrer header might be cleared, if the protocol changes from HTTPS to
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HTTP. This is the default behavior of URLRequest, corresponding to
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE. Alternatively, the
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // referrer policy can be set to never change the referrer header. This
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // behavior corresponds to NEVER_CLEAR_REFERRER. Embedders will want to use
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NEVER_CLEAR_REFERRER when implementing the meta-referrer support
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (http://wiki.whatwg.org/wiki/Meta_referrer) and sending requests with a
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // non-default referrer policy. Only the default referrer policy requires
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the referrer to be cleared on transitions from HTTPS to HTTP.
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum ReferrerPolicy {
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE,
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NEVER_CLEAR_REFERRER,
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This class handles network interception.  Use with
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (Un)RegisterRequestInterceptor.
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class NET_EXPORT Interceptor {
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  public:
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual ~Interceptor() {}
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called for every request made.  Should return a new job to handle the
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // request if it should be intercepted, or NULL to allow the request to
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // be handled in the normal manner.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual URLRequestJob* MaybeIntercept(
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        URLRequest* request, NetworkDelegate* network_delegate) = 0;
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called after having received a redirect response, but prior to the
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the request delegate being informed of the redirect. Can return a new
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // job to replace the existing job if it should be intercepted, or NULL
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // to allow the normal handling to continue. If a new job is provided,
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the delegate never sees the original redirect response, instead the
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // response produced by the intercept job will be returned.
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual URLRequestJob* MaybeInterceptRedirect(
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        URLRequest* request,
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        NetworkDelegate* network_delegate,
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        const GURL& location);
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called after having received a final response, but prior to the
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the request delegate being informed of the response. This is also
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // called when there is no server response at all to allow interception
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // on dns or network errors. Can return a new job to replace the existing
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // job if it should be intercepted, or NULL to allow the normal handling to
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // continue. If a new job is provided, the delegate never sees the original
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // response, instead the response produced by the intercept job will be
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // returned.
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual URLRequestJob* MaybeInterceptResponse(
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        URLRequest* request, NetworkDelegate* network_delegate);
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deprecated interfaces in net::URLRequest. They have been moved to
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URLRequest's private section to prevent new uses. Existing uses are
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // explicitly friended here and should be removed over time.
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class NET_EXPORT Deprecated {
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   private:
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // TODO(willchan): Kill off these friend declarations.
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class ::ChildProcessSecurityPolicyTest;
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class TestInterceptor;
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class URLRequestFilter;
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class appcache::AppCacheRequestHandlerTest;
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class appcache::AppCacheURLRequestJobTest;
173e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch    friend class content::AppCacheInterceptor;
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    friend class content::BlobURLRequestJobTest;
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    friend class content::FileSystemDirURLRequestJobTest;
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    friend class content::FileSystemURLRequestJobTest;
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    friend class content::FileWriterDelegateTest;
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class content::ResourceDispatcherHostTest;
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Use URLRequestJobFactory::ProtocolHandler instead.
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme,
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    ProtocolFactory* factory);
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // TODO(pauljensen): Remove this when AppCacheInterceptor is a
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // ProtocolHandler, see crbug.com/161547.
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    static void RegisterRequestInterceptor(Interceptor* interceptor);
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    static void UnregisterRequestInterceptor(Interceptor* interceptor);
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DISALLOW_IMPLICIT_CONSTRUCTORS(Deprecated);
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The delegate's methods are called from the message loop of the thread
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // on which the request's Start() method is called. See above for the
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ordering of callbacks.
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The callbacks will be called in the following order:
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //   Start()
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnCertificateRequested* (zero or more calls, if the SSL server and/or
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      SSL proxy requests a client certificate for authentication)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnSSLCertificateError* (zero or one call, if the SSL server's
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      certificate has an error)
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnReceivedRedirect* (zero or more calls, for the number of redirects)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnAuthRequired* (zero or more calls, for the number of
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      authentication failures)
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnResponseStarted
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //   Read() initiated by delegate
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnReadCompleted* (zero or more calls until all data is read)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Read() must be called at least once. Read() returns true when it completed
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // immediately, and false if an IO is pending or if there is an error.  When
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Read() returns false, the caller can check the Request's status() to see
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if an error occurred, or if the IO is just pending.  When Read() returns
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // true with zero bytes read, it indicates the end of the response.
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class NET_EXPORT Delegate {
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called upon a server-initiated redirect.  The delegate may call the
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // request's Cancel method to prevent the redirect from being followed.
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Since there may be multiple chained redirects, there may also be more
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // than one redirect call.
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    //
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // When this function is called, the request will still contain the
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // original URL, the destination of the redirect is provided in 'new_url'.
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // If the delegate does not cancel the request and |*defer_redirect| is
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // false, then the redirect will be followed, and the request's URL will be
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // changed to the new URL.  Otherwise if the delegate does not cancel the
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // request and |*defer_redirect| is true, then the redirect will be
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // followed once FollowDeferredRedirect is called on the URLRequest.
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    //
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The caller must set |*defer_redirect| to false, so that delegates do not
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // need to set it if they are happy with the default behavior of not
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // deferring redirect.
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnReceivedRedirect(URLRequest* request,
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    const GURL& new_url,
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    bool* defer_redirect);
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called when we receive an authentication failure.  The delegate should
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // call request->SetAuth() with the user's credentials once it obtains them,
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // or request->CancelAuth() to cancel the login and display the error page.
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // When it does so, the request will be reissued, restarting the sequence
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // of On* callbacks.
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnAuthRequired(URLRequest* request,
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                AuthChallengeInfo* auth_info);
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called when we receive an SSL CertificateRequest message for client
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // authentication.  The delegate should call
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // request->ContinueWithCertificate() with the client certificate the user
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // selected, or request->ContinueWithCertificate(NULL) to continue the SSL
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // handshake without a client certificate.
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnCertificateRequested(
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        URLRequest* request,
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        SSLCertRequestInfo* cert_request_info);
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called when using SSL and the server responds with a certificate with
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // an error, for example, whose common name does not match the common name
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // we were expecting for that host.  The delegate should either do the
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // safe thing and Cancel() the request or decide to proceed by calling
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // ContinueDespiteLastError().  cert_error is a ERR_* error code
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // indicating what's wrong with the certificate.
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // If |fatal| is true then the host in question demands a higher level
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // of security (due e.g. to HTTP Strict Transport Security, user
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // preference, or built-in policy). In this case, errors must not be
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // bypassable by the user.
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnSSLCertificateError(URLRequest* request,
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       const SSLInfo& ssl_info,
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       bool fatal);
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Called to notify that the request must use the network to complete the
2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // request and is about to do so. This is called at most once per
2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // URLRequest, and by default does not defer. If deferred, call
2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // ResumeNetworkStart() to continue or Cancel() to cancel.
2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    virtual void OnBeforeNetworkStart(URLRequest* request, bool* defer);
2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // After calling Start(), the delegate will receive an OnResponseStarted
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // callback when the request has completed.  If an error occurred, the
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // request->status() will be set.  On success, all redirects have been
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // followed and the final response is beginning to arrive.  At this point,
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // meta data about the response is available, including for example HTTP
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // response headers if this is a request for a HTTP resource.
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnResponseStarted(URLRequest* request) = 0;
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called when the a Read of the response body is completed after an
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // IO_PENDING status from a Read() call.
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The data read is filled into the buffer which the caller passed
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // to Read() previously.
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    //
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // If an error occurred, request->status() will contain the error,
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // and bytes read will be -1.
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0;
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   protected:
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual ~Delegate() {}
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // TODO(tburkard): we should get rid of this constructor, and have each
296a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // creator of a URLRequest specifically list the cookie store to be used.
297a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // For now, this constructor will use the cookie store in |context|.
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  URLRequest(const GURL& url,
2990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)             RequestPriority priority,
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)             Delegate* delegate,
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)             const URLRequestContext* context);
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
303a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  URLRequest(const GURL& url,
304a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)             RequestPriority priority,
305a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)             Delegate* delegate,
306a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)             const URLRequestContext* context,
307a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)             CookieStore* cookie_store);
308a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If destroyed after Start() has been called but while IO is pending,
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // then the request will be effectively canceled and the delegate
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will not have any more of its methods called.
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~URLRequest();
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Changes the default cookie policy from allowing all cookies to blocking all
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cookies. Embedders that want to implement a more flexible policy should
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // change the default to blocking all cookies, and provide a NetworkDelegate
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // with the URLRequestContext that maintains the CookieStore.
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The cookie policy default has to be set before the first URLRequest is
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // started. Once it was set to block all cookies, it cannot be changed back.
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void SetDefaultCookiePolicyToBlock();
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the scheme can be handled by URLRequest. False otherwise.
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool IsHandledProtocol(const std::string& scheme);
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the url can be handled by URLRequest. False otherwise.
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The function returns true for invalid urls because URLRequest knows how
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to handle those.
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NOTE: This will also return true for URLs that are handled by
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ProtocolFactories that only work for requests that are scoped to a
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Profile.
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool IsHandledURL(const GURL& url);
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The original url is the url used to initialize the request, and it may
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // differ from the url if the request was redirected.
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const GURL& original_url() const { return url_chain_.front(); }
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The chain of urls traversed by this request.  If the request had no
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // redirects, this vector will contain one element.
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::vector<GURL>& url_chain() const { return url_chain_; }
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const GURL& url() const { return url_chain_.back(); }
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The URL that should be consulted for the third-party cookie blocking
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // policy.
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // WARNING: This URL must only be used for the third-party cookie blocking
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          policy. It MUST NEVER be used for any kind of SECURITY check.
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          For example, if a top-level navigation is redirected, the
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          first-party for cookies will be the URL of the first URL in the
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          redirect chain throughout the whole redirect. If it was used for
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          a security check, an attacker might try to get around this check
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          by starting from some page that redirects to the
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          host-to-be-attacked.
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const GURL& first_party_for_cookies() const {
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return first_party_for_cookies_;
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method may be called before Start() or FollowDeferredRedirect() is
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // called.
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_first_party_for_cookies(const GURL& first_party_for_cookies);
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The request method, as an uppercase string.  "GET" is the default value.
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The request method may only be changed before Start() is called and
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // should only be assigned an uppercase value.
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::string& method() const { return method_; }
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_method(const std::string& method);
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3669ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  // Determines the new method of the request afer following a redirect.
3679ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  // |method| is the method used to arrive at the redirect,
3689ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  // |http_status_code| is the status code associated with the redirect.
3699ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  static std::string ComputeMethodForRedirect(const std::string& method,
3709ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch                                              int http_status_code);
3719ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The referrer URL for the request.  This header may actually be suppressed
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // from the underlying network request for security reasons (e.g., a HTTPS
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URL will not be sent as the referrer for a HTTP request).  The referrer
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // may only be changed before Start() is called.
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::string& referrer() const { return referrer_; }
377c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Referrer is sanitized to remove URL fragment, user name and password.
378c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SetReferrer(const std::string& referrer);
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The referrer policy to apply when updating the referrer during redirects.
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The referrer policy may only be changed before Start() is called.
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_referrer_policy(ReferrerPolicy referrer_policy);
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the delegate of the request.  This value may be changed at any time,
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and it is permissible for it to be null.
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_delegate(Delegate* delegate);
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates that the request body should be sent using chunked transfer
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // encoding. This method may only be called before Start() is called.
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void EnableChunkedUpload();
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Appends the given bytes to the request's upload data to be sent
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // immediately via chunked transfer encoding. When all data has been sent,
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // call MarkEndOfChunks() to indicate the end of upload data.
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method may be called only after calling EnableChunkedUpload().
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AppendChunkToUpload(const char* bytes,
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           int bytes_len,
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           bool is_last_chunk);
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets the upload data.
4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_upload(scoped_ptr<UploadDataStream> upload);
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets the upload data.
4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const UploadDataStream* get_upload() const;
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the request has a non-empty message body to upload.
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool has_upload() const;
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Set an extra request header by ID or name, or remove one by name.  These
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // methods may only be called before Start() is called, or before a new
4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // redirect in the request chain.
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetExtraRequestHeaderById(int header_id, const std::string& value,
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 bool overwrite);
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetExtraRequestHeaderByName(const std::string& name,
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const std::string& value, bool overwrite);
4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void RemoveRequestHeaderByName(const std::string& name);
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets all extra request headers.  Any extra request headers set by other
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // methods are overwritten by this method.  This method may only be called
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // before Start() is called.  It is an error to call it later.
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetExtraRequestHeaders(const HttpRequestHeaders& headers);
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const HttpRequestHeaders& extra_request_headers() const {
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return extra_request_headers_;
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
428eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Gets the full request headers sent to the server.
429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  //
430eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Return true and overwrites headers if it can get the request headers;
431eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // otherwise, returns false and does not modify headers.  (Always returns
432eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // false for request types that don't have headers, like file requests.)
433eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  //
434eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // This is guaranteed to succeed if:
435eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  //
436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // 1. A redirect or auth callback is currently running.  Once it ends, the
437eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  //    headers may become unavailable as a new request with the new address
438eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  //    or credentials is made.
439eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  //
440eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // 2. The OnResponseStarted callback is currently running or has run.
441eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool GetFullRequestHeaders(HttpRequestHeaders* headers) const;
442eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
4435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Gets the total amount of data received from network after SSL decoding and
4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // proxy handling.
4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int64 GetTotalReceivedBytes() const;
4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
447a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Returns the current load state for the request. The returned value's
448a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // |param| field is an optional parameter describing details related to the
449a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // load state. Not all load states have a parameter.
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LoadStateWithParam GetLoadState() const;
4511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Returns a partial representation of the request's state as a value, for
4531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // debugging.  Caller takes ownership of returned value.
4541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  base::Value* GetStateAsValue() const;
4551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
456a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Logs information about the what external object currently blocking the
457a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // request.  LogUnblocked must be called before resuming the request.  This
458a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // can be called multiple times in a row either with or without calling
459a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // LogUnblocked between calls.  |blocked_by| must not be NULL or have length
460a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // 0.
461a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void LogBlockedBy(const char* blocked_by);
462a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
463a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Just like LogBlockedBy, but also makes GetLoadState return source as the
464a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // |param| in the value returned by GetLoadState.  Calling LogUnblocked or
465a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // LogBlockedBy will clear the load param.  |blocked_by| must not be NULL or
466a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // have length 0.
467a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void LogAndReportBlockedBy(const char* blocked_by);
468a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
469a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Logs that the request is no longer blocked by the last caller to
470a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // LogBlockedBy.
471a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void LogUnblocked();
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the current upload progress in bytes. When the upload data is
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // chunked, size is set to zero, but position will not be.
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UploadProgress GetUploadProgress() const;
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get response header(s) by ID or name.  These methods may only be called
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // once the delegate's OnResponseStarted method has been called.  Headers
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that appear more than once in the response are coalesced, with values
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // separated by commas (per RFC 2616). This will not work with cookies since
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // comma can be used in cookie values.
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(darin): add API to enumerate response headers.
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetResponseHeaderById(int header_id, std::string* value);
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetResponseHeaderByName(const std::string& name, std::string* value);
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get all response headers, \n-delimited and \n\0-terminated.  This includes
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the response status line.  Restrictions on GetResponseHeaders apply.
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetAllResponseHeaders(std::string* headers);
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The time when |this| was constructed.
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeTicks creation_time() const { return creation_time_; }
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The time at which the returned response was requested.  For cached
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // responses, this is the last time the cache entry was validated.
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::Time& request_time() const {
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return response_info_.request_time;
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The time at which the returned response was generated.  For cached
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // responses, this is the last time the cache entry was validated.
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::Time& response_time() const {
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return response_info_.response_time;
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicate if this response was fetched from disk cache.
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool was_cached() const { return response_info_.was_cached; }
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the URLRequest was delivered through a proxy.
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool was_fetched_via_proxy() const {
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return response_info_.was_fetched_via_proxy;
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns true if the URLRequest was delivered over SPDY.
5145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool was_fetched_via_spdy() const {
5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return response_info_.was_fetched_via_spdy;
5165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the host and port that the content was fetched from.  See
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // http_response_info.h for caveats relating to cached content.
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HostPortPair GetSocketAddress() const;
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get all response headers, as a HttpResponseHeaders object.  See comments
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in HttpResponseHeaders class as to the format of the data.
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpResponseHeaders* response_headers() const;
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the SSL connection info.
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const SSLInfo& ssl_info() const {
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return response_info_.ssl_info;
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets timing information related to the request.  Events that have not yet
5322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // occurred are left uninitialized.  After a second request starts, due to
5332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // a redirect or authentication, values will be reset.
5342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
5352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // LoadTimingInfo only contains ConnectTiming information and socket IDs for
5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // non-cached HTTP responses.
5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const;
5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the cookie values included in the response, if the request is one
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that can have cookies.  Returns true if the request is a cookie-bearing
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // type, false otherwise.  This method may only be called once the
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // delegate's OnResponseStarted method has been called.
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetResponseCookies(ResponseCookies* cookies);
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the mime type.  This method may only be called once the delegate's
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // OnResponseStarted method has been called.
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetMimeType(std::string* mime_type);
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the charset (character encoding).  This method may only be called once
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the delegate's OnResponseStarted method has been called.
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetCharset(std::string* charset);
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the HTTP response code (e.g., 200, 404, and so on).  This method
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // may only be called once the delegate's OnResponseStarted method has been
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // called.  For non-HTTP requests, this method returns -1.
55658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  int GetResponseCode() const;
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the HTTP response info in its entirety.
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const HttpResponseInfo& response_info() const { return response_info_; }
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Access the LOAD_* flags modifying this request (see load_flags.h).
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int load_flags() const { return load_flags_; }
563f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
564f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The new flags may change the IGNORE_LIMITS flag only when called
565f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // before Start() is called, it must only set the flag, and if set,
566f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // the priority of this request must already be MAXIMUM_PRIORITY.
567f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void SetLoadFlags(int flags);
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the request is "pending" (i.e., if Start() has been called,
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and the response has not yet been called).
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool is_pending() const { return is_pending_; }
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the request is in the process of redirecting to a new
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URL but has not yet initiated the new request.
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool is_redirecting() const { return is_redirecting_; }
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the error status of the request.
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const URLRequestStatus& status() const { return status_; }
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a globally unique identifier for this request.
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  uint64 identifier() const { return identifier_; }
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method is called to start the request.  The delegate will receive
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a OnResponseStarted callback when the request is started.
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Start();
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method may be called at any time after Start() has been called to
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cancel the request.  This method may be called many times, and it has
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // no effect once the response has completed.  It is guaranteed that no
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // methods of the delegate will be called after the request has been
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cancelled, except that this may call the delegate's OnReadCompleted()
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // during the call to Cancel itself.
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Cancel();
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cancels the request and sets the error to |error| (see net_error_list.h
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for values).
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CancelWithError(int error);
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cancels the request and sets the error to |error| (see net_error_list.h
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for values) and attaches |ssl_info| as the SSLInfo for that request.  This
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is useful to attach a certificate and certificate error to a canceled
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // request.
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CancelWithSSLError(int error, const SSLInfo& ssl_info);
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Read initiates an asynchronous read from the response, and must only
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // be called after the OnResponseStarted callback is received with a
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // successful status.
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If data is available, Read will return true, and the data and length will
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // be returned immediately.  If data is not available, Read returns false,
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and an asynchronous Read is initiated.  The Read is finished when
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the caller receives the OnReadComplete callback.  Unless the request was
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cancelled, OnReadComplete will always be called, even if the read failed.
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The buf parameter is a buffer to receive the data.  If the operation
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // completes asynchronously, the implementation will reference the buffer
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // until OnReadComplete is called.  The buffer must be at least max_bytes in
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // length.
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The max_bytes parameter is the maximum number of bytes to read.
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The bytes_read parameter is an output parameter containing the
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the number of bytes read.  A value of 0 indicates that there is no
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // more data available to read from the stream.
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If a read error occurs, Read returns false and the request->status
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be set to an error.
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Read(IOBuffer* buf, int max_bytes, int* bytes_read);
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If this request is being cached by the HTTP cache, stop subsequent caching.
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note that this method has no effect on other (simultaneous or not) requests
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for the same resource. The typical example is a request that results in
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the data being stored to disk (downloaded instead of rendered) so we don't
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // want to store it twice.
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StopCaching();
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method may be called to follow a redirect that was deferred in
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // response to an OnReceivedRedirect call.
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void FollowDeferredRedirect();
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This method must be called to resume network communications that were
6415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // deferred in response to an OnBeforeNetworkStart call.
6425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void ResumeNetworkStart();
6435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // One of the following two methods should be called in response to an
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // OnAuthRequired() callback (and only then).
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // SetAuth will reissue the request with the given credentials.
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // CancelAuth will give up and display the error page.
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetAuth(const AuthCredentials& credentials);
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CancelAuth();
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method can be called after the user selects a client certificate to
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // instruct this URLRequest to continue with the request with the
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // certificate.  Pass NULL if the user doesn't have a client certificate.
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ContinueWithCertificate(X509Certificate* client_cert);
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method can be called after some error notifications to instruct this
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URLRequest to ignore the current error and continue with the request.  To
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cancel the request instead, call Cancel().
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ContinueDespiteLastError();
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used to specify the context (cookie store, cache) for this request.
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const URLRequestContext* context() const;
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const BoundNetLog& net_log() const { return net_log_; }
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the expected content size if available
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int64 GetExpectedContentSize() const;
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the priority level for this request.
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RequestPriority priority() const { return priority_; }
6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
672f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Sets the priority level for this request and any related
673f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // jobs. Must not change the priority to anything other than
674f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // MAXIMUM_PRIORITY if the IGNORE_LIMITS load flag is set.
6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetPriority(RequestPriority priority);
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true iff this request would be internally redirected to HTTPS
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // due to HSTS. If so, |redirect_url| is rewritten to the new HTTPS URL.
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetHSTSRedirect(GURL* redirect_url) const;
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(willchan): Undo this. Only temporarily public.
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool has_delegate() const { return delegate_ != NULL; }
6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NOTE(willchan): This is just temporary for debugging
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // http://crbug.com/90971.
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allows to setting debug info into the URLRequest.
6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_stack_trace(const base::debug::StackTrace& stack_trace);
6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::debug::StackTrace* stack_trace() const;
6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_received_response_content_length(int64 received_content_length) {
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    received_response_content_length_ = received_content_length;
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int64 received_response_content_length() {
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return received_response_content_length_;
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allow the URLRequestJob class to control the is_pending() flag.
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_is_pending(bool value) { is_pending_ = value; }
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allow the URLRequestJob class to set our status too
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_status(const URLRequestStatus& value) { status_ = value; }
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
704a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  CookieStore* cookie_store() const { return cookie_store_; }
705a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allow the URLRequestJob to redirect this request.  Returns OK if
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // successful, otherwise an error code is returned.
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int Redirect(const GURL& location, int http_status_code);
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by URLRequestJob to allow interception when a redirect occurs.
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyReceivedRedirect(const GURL& location, bool* defer_redirect);
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called by URLRequestHttpJob (note, only HTTP(S) jobs will call this) to
7145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // allow deferral of network initialization.
7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void NotifyBeforeNetworkStart(bool* defer);
7165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allow an interceptor's URLRequestJob to restart this request.
7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Should only be called if the original job has not started a response.
7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Restart();
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class URLRequestJob;
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Registers a new protocol handler for the given scheme. If the scheme is
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // already handled, this will overwrite the given factory. To delete the
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // protocol factory, use NULL for the factory BUT this WILL NOT put back
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // any previously registered protocol factory. It will have returned
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the previously registered factory (or NULL if none is registered) when
7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the scheme was first registered so that the caller can manually put it
7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // back if desired.
7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The scheme must be all-lowercase ASCII. See the ProtocolFactory
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // declaration for its requirements.
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The registered protocol factory may return NULL, which will cause the
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // regular "built-in" protocol factory to be used.
7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme,
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                  ProtocolFactory* factory);
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Registers or unregisters a network interception class.
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void RegisterRequestInterceptor(Interceptor* interceptor);
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void UnregisterRequestInterceptor(Interceptor* interceptor);
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Initializes the URLRequest. Code shared between the two constructors.
746a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // TODO(tburkard): This can ultimately be folded into a single constructor
747a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // again.
748a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void Init(const GURL& url,
749a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)            RequestPriority priotity,
750a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)            Delegate* delegate,
751a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)            const URLRequestContext* context,
752a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)            CookieStore* cookie_store);
753a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // handler. If |blocked| is true, the request is blocked and an error page is
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // returned indicating so. This should only be called after Start is called
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and OnBeforeRequest returns true (signalling that the request should be
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // paused).
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void BeforeRequestComplete(int error);
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StartJob(URLRequestJob* job);
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Restarting involves replacing the current job with a new one such as what
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // happens when following a HTTP redirect.
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RestartWithJob(URLRequestJob* job);
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void PrepareToRestart();
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Detaches the job from this request in preparation for this object going
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // away or the job being replaced. The job will not call us back when it has
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // been orphaned.
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OrphanJob();
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cancels the request and set the error and ssl info for this request to the
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // passed values.
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DoCancel(int error, const SSLInfo& ssl_info);
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Called by the URLRequestJob when the headers are received, before any other
7782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // method, to allow caching of load timing information.
7792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void OnHeadersComplete();
7802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notifies the network delegate that the request has been completed.
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This does not imply a successful completion. Also a canceled request is
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // considered completed.
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyRequestCompleted();
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by URLRequestJob to allow interception when the final response
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // occurs.
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyResponseStarted();
7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // These functions delegate to |delegate_| and may only be used if
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |delegate_| is not NULL. See URLRequest::Delegate for the meaning
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // of these functions.
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyAuthRequired(AuthChallengeInfo* auth_info);
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyAuthRequiredComplete(NetworkDelegate::AuthRequiredResponse result);
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyCertificateRequested(SSLCertRequestInfo* cert_request_info);
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifySSLCertificateError(const SSLInfo& ssl_info, bool fatal);
7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void NotifyReadCompleted(int bytes_read);
7982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // These functions delegate to |network_delegate_| if it is not NULL.
8002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If |network_delegate_| is NULL, cookies can be used unless
8012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // SetDefaultCookiePolicyToBlock() has been called.
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanGetCookies(const CookieList& cookie_list) const;
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanSetCookie(const std::string& cookie_line,
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    CookieOptions* options) const;
80590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool CanEnablePrivacyMode() const;
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Called just before calling a delegate that may block a request.
8081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void OnCallToDelegate();
8091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Called when the delegate lets a request continue.  Also called on
8101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // cancellation.
8111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void OnCallToDelegateComplete();
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Contextual information used for this request. Cannot be NULL. This contains
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // most of the dependencies which are shared between requests (disk cache,
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cookie store, socket pool, etc.)
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const URLRequestContext* context_;
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NetworkDelegate* network_delegate_;
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tracks the time spent in various load states throughout this request.
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BoundNetLog net_log_;
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<URLRequestJob> job_;
8242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<UploadDataStream> upload_data_stream_;
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> url_chain_;
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL first_party_for_cookies_;
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL delegate_redirect_url_;
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string method_;  // "GET", "POST", etc. Should be all uppercase.
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string referrer_;
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ReferrerPolicy referrer_policy_;
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpRequestHeaders extra_request_headers_;
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int load_flags_;  // Flags indicating the request type for the load;
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    // expected values are LOAD_* enums above.
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Never access methods of the |delegate_| directly. Always use the
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notify... methods for this.
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Delegate* delegate_;
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Current error status of the job. When no error has been encountered, this
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be SUCCESS. If multiple errors have been encountered, this will be
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the first non-SUCCESS status seen.
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  URLRequestStatus status_;
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The HTTP response info, lazily initialized.
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpResponseInfo response_info_;
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tells us whether the job is outstanding. This is true from the time
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Start() is called to the time we dispatch RequestComplete and indicates
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // whether the job is active.
8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool is_pending_;
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates if the request is in the process of redirecting to a new
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // location.  It is true from the time the headers complete until a
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // new request begins.
8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool is_redirecting_;
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Number of times we're willing to redirect.  Used to guard against
8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // infinite redirects.
8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int redirect_limit_;
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cached value for use after we've orphaned the job handling the
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // first transaction in a request involving redirects.
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UploadProgress final_upload_progress_;
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The priority level for this request.  Objects like
866f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // ClientSocketPool use this to determine which URLRequest to
867f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // allocate sockets to first.
8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RequestPriority priority_;
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(battre): The only consumer of the identifier_ is currently the
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // web request API. We need to match identifiers of requests between the
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // web request API and the web navigation API. As the URLRequest does not
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // exist when the web navigation API is triggered, the tracking probably
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // needs to be done outside of the URLRequest anyway. Therefore, this
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // identifier should be deleted here. http://crbug.com/89321
8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A globally unique identifier for this request.
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const uint64 identifier_;
8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // True if this request is currently calling a delegate, or is blocked waiting
8801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // for the URL request or network delegate to resume it.
8811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool calling_delegate_;
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
883a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // An optional parameter that provides additional information about what
884a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // |this| is currently being blocked by.
885a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  std::string blocked_by_;
886a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  bool use_blocked_by_as_load_param_;
8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::debug::LeakTracker<URLRequest> leak_tracker_;
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Callback passed to the network delegate to notify us when a blocked request
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is ready to be resumed or canceled.
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CompletionCallback before_request_callback_;
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Safe-guard to ensure that we do not send multiple "I am completed"
8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // messages to network delegate.
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(battre): Remove this. http://crbug.com/89049
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool has_notified_completion_;
8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Authentication data used by the NetworkDelegate for this request,
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if one is present. |auth_credentials_| may be filled in when calling
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |NotifyAuthRequired| on the NetworkDelegate. |auth_info_| holds
9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the authentication challenge being handled by |NotifyAuthRequired|.
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  AuthCredentials auth_credentials_;
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<AuthChallengeInfo> auth_info_;
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int64 received_response_content_length_;
9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeTicks creation_time_;
9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Timing information for the most recent request.  Its start times are
9112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // populated during Start(), and the rest are populated in OnResponseReceived.
9122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  LoadTimingInfo load_timing_info_;
9132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<const base::debug::StackTrace> stack_trace_;
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Keeps track of whether or not OnBeforeNetworkStart has been called yet.
9175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool notified_before_network_start_;
9185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
919a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // The cookie store to be used for this request.
920a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  scoped_refptr<CookieStore> cookie_store_;
921a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(URLRequest);
9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_URL_REQUEST_URL_REQUEST_H_
928