1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_URL_REQUEST_URL_REQUEST_H_
6 #define NET_URL_REQUEST_URL_REQUEST_H_
12 #include "base/debug/leak_tracker.h"
13 #include "base/logging.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/string16.h"
16 #include "base/supports_user_data.h"
17 #include "base/time.h"
18 #include "base/threading/non_thread_safe.h"
19 #include "googleurl/src/gurl.h"
20 #include "net/base/auth.h"
21 #include "net/base/completion_callback.h"
22 #include "net/base/load_states.h"
23 #include "net/base/net_export.h"
24 #include "net/base/net_log.h"
25 #include "net/base/network_delegate.h"
26 #include "net/base/request_priority.h"
27 #include "net/http/http_request_headers.h"
28 #include "net/http/http_response_info.h"
29 #include "net/url_request/url_request_status.h"
32 // Temporary layering violation to allow existing users of a deprecated
34 class AutoUpdateInterceptor
;
35 class ChildProcessSecurityPolicyTest
;
36 class ComponentUpdateInterceptor
;
37 class ResourceDispatcherHostTest
;
38 class TestAutomationProvider
;
39 class URLRequestAutomationJob
;
40 class UserScriptListenerTest
;
42 // Temporary layering violation to allow existing users of a deprecated
45 class AppCacheInterceptor
;
46 class AppCacheRequestHandlerTest
;
47 class AppCacheURLRequestJobTest
;
50 // Temporary layering violation to allow existing users of a deprecated
53 class FileSystemDirURLRequestJobTest
;
54 class FileSystemOperationWriteTest
;
55 class FileSystemURLRequestJobTest
;
56 class FileWriterDelegateTest
;
59 // Temporary layering violation to allow existing users of a deprecated
62 class CannedResponseInterceptor
;
65 // Temporary layering violation to allow existing users of a deprecated
67 namespace webkit_blob
{
68 class BlobURLRequestJobTest
;
77 class SSLCertRequestInfo
;
80 class URLRequestContext
;
82 class X509Certificate
;
84 // This stores the values of the Set-Cookie headers received during the request.
85 // Each item in the vector corresponds to a Set-Cookie: line received,
86 // excluding the "Set-Cookie:" part.
87 typedef std::vector
<std::string
> ResponseCookies
;
89 //-----------------------------------------------------------------------------
90 // A class representing the asynchronous load of a data stream from an URL.
92 // The lifetime of an instance of this class is completely controlled by the
93 // consumer, and the instance is not required to live on the heap or be
94 // allocated in any special way. It is also valid to delete an URLRequest
95 // object during the handling of a callback to its delegate. Of course, once
96 // the URLRequest is deleted, no further callbacks to its delegate will occur.
98 // NOTE: All usage of all instances of this class should be on the same thread.
100 class NET_EXPORT URLRequest
: NON_EXPORTED_BASE(public base::NonThreadSafe
),
101 public base::SupportsUserData
{
103 // Callback function implemented by protocol handlers to create new jobs.
104 // The factory may return NULL to indicate an error, which will cause other
105 // factories to be queried. If no factory handles the request, then the
106 // default job will be used.
107 typedef URLRequestJob
* (ProtocolFactory
)(URLRequest
* request
,
108 const std::string
& scheme
);
110 // HTTP request/response header IDs (via some preprocessor fun) for use with
111 // SetRequestHeaderById and GetResponseHeaderById.
113 #define HTTP_ATOM(x) HTTP_ ## x,
114 #include "net/http/http_atom_list.h"
118 // This class handles network interception. Use with
119 // (Un)RegisterRequestInterceptor.
120 class NET_EXPORT Interceptor
{
122 virtual ~Interceptor() {}
124 // Called for every request made. Should return a new job to handle the
125 // request if it should be intercepted, or NULL to allow the request to
126 // be handled in the normal manner.
127 virtual URLRequestJob
* MaybeIntercept(URLRequest
* request
) = 0;
129 // Called after having received a redirect response, but prior to the
130 // the request delegate being informed of the redirect. Can return a new
131 // job to replace the existing job if it should be intercepted, or NULL
132 // to allow the normal handling to continue. If a new job is provided,
133 // the delegate never sees the original redirect response, instead the
134 // response produced by the intercept job will be returned.
135 virtual URLRequestJob
* MaybeInterceptRedirect(URLRequest
* request
,
136 const GURL
& location
);
138 // Called after having received a final response, but prior to the
139 // the request delegate being informed of the response. This is also
140 // called when there is no server response at all to allow interception
141 // on dns or network errors. Can return a new job to replace the existing
142 // job if it should be intercepted, or NULL to allow the normal handling to
143 // continue. If a new job is provided, the delegate never sees the original
144 // response, instead the response produced by the intercept job will be
146 virtual URLRequestJob
* MaybeInterceptResponse(URLRequest
* request
);
149 // Deprecated interfaces in net::URLRequest. They have been moved to
150 // URLRequest's private section to prevent new uses. Existing uses are
151 // explicitly friended here and should be removed over time.
152 class NET_EXPORT Deprecated
{
154 // TODO(willchan): Kill off these friend declarations.
155 friend class ::AutoUpdateInterceptor
;
156 friend class ::ChildProcessSecurityPolicyTest
;
157 friend class ::ComponentUpdateInterceptor
;
158 friend class ::ResourceDispatcherHostTest
;
159 friend class ::TestAutomationProvider
;
160 friend class ::UserScriptListenerTest
;
161 friend class ::URLRequestAutomationJob
;
162 friend class TestInterceptor
;
163 friend class URLRequestFilter
;
164 friend class appcache::AppCacheInterceptor
;
165 friend class appcache::AppCacheRequestHandlerTest
;
166 friend class appcache::AppCacheURLRequestJobTest
;
167 friend class fileapi::FileSystemDirURLRequestJobTest
;
168 friend class fileapi::FileSystemOperationWriteTest
;
169 friend class fileapi::FileSystemURLRequestJobTest
;
170 friend class fileapi::FileWriterDelegateTest
;
171 friend class policy::CannedResponseInterceptor
;
172 friend class webkit_blob::BlobURLRequestJobTest
;
174 // Use URLRequestJobFactory::ProtocolHandler instead.
175 static ProtocolFactory
* RegisterProtocolFactory(const std::string
& scheme
,
176 ProtocolFactory
* factory
);
178 // Use URLRequestJobFactory::Interceptor instead.
179 static void RegisterRequestInterceptor(Interceptor
* interceptor
);
180 static void UnregisterRequestInterceptor(Interceptor
* interceptor
);
182 DISALLOW_IMPLICIT_CONSTRUCTORS(Deprecated
);
185 // The delegate's methods are called from the message loop of the thread
186 // on which the request's Start() method is called. See above for the
187 // ordering of callbacks.
189 // The callbacks will be called in the following order:
191 // - OnCertificateRequested* (zero or more calls, if the SSL server and/or
192 // SSL proxy requests a client certificate for authentication)
193 // - OnSSLCertificateError* (zero or one call, if the SSL server's
194 // certificate has an error)
195 // - OnReceivedRedirect* (zero or more calls, for the number of redirects)
196 // - OnAuthRequired* (zero or more calls, for the number of
197 // authentication failures)
198 // - OnResponseStarted
199 // Read() initiated by delegate
200 // - OnReadCompleted* (zero or more calls until all data is read)
202 // Read() must be called at least once. Read() returns true when it completed
203 // immediately, and false if an IO is pending or if there is an error. When
204 // Read() returns false, the caller can check the Request's status() to see
205 // if an error occurred, or if the IO is just pending. When Read() returns
206 // true with zero bytes read, it indicates the end of the response.
208 class NET_EXPORT Delegate
{
210 virtual ~Delegate() {}
212 // Called upon a server-initiated redirect. The delegate may call the
213 // request's Cancel method to prevent the redirect from being followed.
214 // Since there may be multiple chained redirects, there may also be more
215 // than one redirect call.
217 // When this function is called, the request will still contain the
218 // original URL, the destination of the redirect is provided in 'new_url'.
219 // If the delegate does not cancel the request and |*defer_redirect| is
220 // false, then the redirect will be followed, and the request's URL will be
221 // changed to the new URL. Otherwise if the delegate does not cancel the
222 // request and |*defer_redirect| is true, then the redirect will be
223 // followed once FollowDeferredRedirect is called on the URLRequest.
225 // The caller must set |*defer_redirect| to false, so that delegates do not
226 // need to set it if they are happy with the default behavior of not
227 // deferring redirect.
228 virtual void OnReceivedRedirect(URLRequest
* request
,
230 bool* defer_redirect
);
232 // Called when we receive an authentication failure. The delegate should
233 // call request->SetAuth() with the user's credentials once it obtains them,
234 // or request->CancelAuth() to cancel the login and display the error page.
235 // When it does so, the request will be reissued, restarting the sequence
237 virtual void OnAuthRequired(URLRequest
* request
,
238 AuthChallengeInfo
* auth_info
);
240 // Called when we receive an SSL CertificateRequest message for client
241 // authentication. The delegate should call
242 // request->ContinueWithCertificate() with the client certificate the user
243 // selected, or request->ContinueWithCertificate(NULL) to continue the SSL
244 // handshake without a client certificate.
245 virtual void OnCertificateRequested(
247 SSLCertRequestInfo
* cert_request_info
);
249 // Called when using SSL and the server responds with a certificate with
250 // an error, for example, whose common name does not match the common name
251 // we were expecting for that host. The delegate should either do the
252 // safe thing and Cancel() the request or decide to proceed by calling
253 // ContinueDespiteLastError(). cert_error is a ERR_* error code
254 // indicating what's wrong with the certificate.
255 // If |fatal| is true then the host in question demands a higher level
256 // of security (due e.g. to HTTP Strict Transport Security, user
257 // preference, or built-in policy). In this case, errors must not be
258 // bypassable by the user.
259 virtual void OnSSLCertificateError(URLRequest
* request
,
260 const SSLInfo
& ssl_info
,
263 // Called when reading cookies to allow the delegate to block access to the
264 // cookie. This method will never be invoked when LOAD_DO_NOT_SEND_COOKIES
266 virtual bool CanGetCookies(const URLRequest
* request
,
267 const CookieList
& cookie_list
) const;
269 // Called when a cookie is set to allow the delegate to block access to the
270 // cookie. This method will never be invoked when LOAD_DO_NOT_SAVE_COOKIES
272 virtual bool CanSetCookie(const URLRequest
* request
,
273 const std::string
& cookie_line
,
274 CookieOptions
* options
) const;
276 // After calling Start(), the delegate will receive an OnResponseStarted
277 // callback when the request has completed. If an error occurred, the
278 // request->status() will be set. On success, all redirects have been
279 // followed and the final response is beginning to arrive. At this point,
280 // meta data about the response is available, including for example HTTP
281 // response headers if this is a request for a HTTP resource.
282 virtual void OnResponseStarted(URLRequest
* request
) = 0;
284 // Called when the a Read of the response body is completed after an
285 // IO_PENDING status from a Read() call.
286 // The data read is filled into the buffer which the caller passed
287 // to Read() previously.
289 // If an error occurred, request->status() will contain the error,
290 // and bytes read will be -1.
291 virtual void OnReadCompleted(URLRequest
* request
, int bytes_read
) = 0;
294 // Initialize an URL request.
295 URLRequest(const GURL
& url
, Delegate
* delegate
);
297 // If destroyed after Start() has been called but while IO is pending,
298 // then the request will be effectively canceled and the delegate
299 // will not have any more of its methods called.
300 virtual ~URLRequest();
302 // Returns true if the scheme can be handled by URLRequest. False otherwise.
303 static bool IsHandledProtocol(const std::string
& scheme
);
305 // Returns true if the url can be handled by URLRequest. False otherwise.
306 // The function returns true for invalid urls because URLRequest knows how
308 // NOTE: This will also return true for URLs that are handled by
309 // ProtocolFactories that only work for requests that are scoped to a
311 static bool IsHandledURL(const GURL
& url
);
313 // Allow access to file:// on ChromeOS for tests.
314 static void AllowFileAccess();
315 static bool IsFileAccessAllowed();
317 // See switches::kEnableMacCookies.
318 static void EnableMacCookies();
319 static bool AreMacCookiesEnabled();
321 // The original url is the url used to initialize the request, and it may
322 // differ from the url if the request was redirected.
323 const GURL
& original_url() const { return url_chain_
.front(); }
324 // The chain of urls traversed by this request. If the request had no
325 // redirects, this vector will contain one element.
326 const std::vector
<GURL
>& url_chain() const { return url_chain_
; }
327 const GURL
& url() const { return url_chain_
.back(); }
329 // The URL that should be consulted for the third-party cookie blocking
331 const GURL
& first_party_for_cookies() const {
332 return first_party_for_cookies_
;
334 // This method may be called before Start() or FollowDeferredRedirect() is
336 void set_first_party_for_cookies(const GURL
& first_party_for_cookies
);
338 // The request method, as an uppercase string. "GET" is the default value.
339 // The request method may only be changed before Start() is called and
340 // should only be assigned an uppercase value.
341 const std::string
& method() const { return method_
; }
342 void set_method(const std::string
& method
);
344 // The referrer URL for the request. This header may actually be suppressed
345 // from the underlying network request for security reasons (e.g., a HTTPS
346 // URL will not be sent as the referrer for a HTTP request). The referrer
347 // may only be changed before Start() is called.
348 const std::string
& referrer() const { return referrer_
; }
349 void set_referrer(const std::string
& referrer
);
350 // Returns the referrer header with potential username and password removed.
351 GURL
GetSanitizedReferrer() const;
353 // Sets the delegate of the request. This value may be changed at any time,
354 // and it is permissible for it to be null.
355 void set_delegate(Delegate
* delegate
);
357 // The data comprising the request message body is specified as a sequence of
358 // data segments and/or files containing data to upload. These methods may
359 // be called to construct the data sequence to upload, and they may only be
360 // called before Start() is called. For POST requests, the user must call
361 // SetRequestHeaderBy{Id,Name} to set the Content-Type of the request to the
362 // appropriate value before calling Start().
364 // When uploading data, bytes_len must be non-zero.
365 void AppendBytesToUpload(const char* bytes
, int bytes_len
); // takes a copy
367 // Indicates that the request body should be sent using chunked transfer
368 // encoding. This method may only be called before Start() is called.
369 void EnableChunkedUpload();
371 // Appends the given bytes to the request's upload data to be sent
372 // immediately via chunked transfer encoding. When all data has been sent,
373 // call MarkEndOfChunks() to indicate the end of upload data.
375 // This method may be called only after calling EnableChunkedUpload().
376 void AppendChunkToUpload(const char* bytes
,
380 // Set the upload data directly.
381 void set_upload(UploadData
* upload
);
383 // Get the upload data directly.
384 UploadData
* get_upload();
386 // Returns true if the request has a non-empty message body to upload.
387 bool has_upload() const;
389 // Set an extra request header by ID or name. These methods may only be
390 // called before Start() is called. It is an error to call it later.
391 void SetExtraRequestHeaderById(int header_id
, const std::string
& value
,
393 void SetExtraRequestHeaderByName(const std::string
& name
,
394 const std::string
& value
, bool overwrite
);
396 // Sets all extra request headers. Any extra request headers set by other
397 // methods are overwritten by this method. This method may only be called
398 // before Start() is called. It is an error to call it later.
399 void SetExtraRequestHeaders(const HttpRequestHeaders
& headers
);
401 const HttpRequestHeaders
& extra_request_headers() const {
402 return extra_request_headers_
;
405 // Returns the current load state for the request. |param| is an optional
406 // parameter describing details related to the load state. Not all load states
408 LoadStateWithParam
GetLoadState() const;
409 void SetLoadStateParam(const string16
& param
) {
410 load_state_param_
= param
;
413 // Returns the current upload progress in bytes.
414 uint64
GetUploadProgress() const;
416 // Get response header(s) by ID or name. These methods may only be called
417 // once the delegate's OnResponseStarted method has been called. Headers
418 // that appear more than once in the response are coalesced, with values
419 // separated by commas (per RFC 2616). This will not work with cookies since
420 // comma can be used in cookie values.
421 // TODO(darin): add API to enumerate response headers.
422 void GetResponseHeaderById(int header_id
, std::string
* value
);
423 void GetResponseHeaderByName(const std::string
& name
, std::string
* value
);
425 // Get all response headers, \n-delimited and \n\0-terminated. This includes
426 // the response status line. Restrictions on GetResponseHeaders apply.
427 void GetAllResponseHeaders(std::string
* headers
);
429 // The time when |this| was constructed.
430 base::TimeTicks
creation_time() const { return creation_time_
; }
432 // The time at which the returned response was requested. For cached
433 // responses, this is the last time the cache entry was validated.
434 const base::Time
& request_time() const {
435 return response_info_
.request_time
;
438 // The time at which the returned response was generated. For cached
439 // responses, this is the last time the cache entry was validated.
440 const base::Time
& response_time() const {
441 return response_info_
.response_time
;
444 // Indicate if this response was fetched from disk cache.
445 bool was_cached() const { return response_info_
.was_cached
; }
447 // Returns true if the URLRequest was delivered through a proxy.
448 bool was_fetched_via_proxy() const {
449 return response_info_
.was_fetched_via_proxy
;
452 // Returns the host and port that the content was fetched from. See
453 // http_response_info.h for caveats relating to cached content.
454 HostPortPair
GetSocketAddress() const;
456 // Get all response headers, as a HttpResponseHeaders object. See comments
457 // in HttpResponseHeaders class as to the format of the data.
458 HttpResponseHeaders
* response_headers() const;
460 // Get the SSL connection info.
461 const SSLInfo
& ssl_info() const {
462 return response_info_
.ssl_info
;
465 // Returns the cookie values included in the response, if the request is one
466 // that can have cookies. Returns true if the request is a cookie-bearing
467 // type, false otherwise. This method may only be called once the
468 // delegate's OnResponseStarted method has been called.
469 bool GetResponseCookies(ResponseCookies
* cookies
);
471 // Get the mime type. This method may only be called once the delegate's
472 // OnResponseStarted method has been called.
473 void GetMimeType(std::string
* mime_type
);
475 // Get the charset (character encoding). This method may only be called once
476 // the delegate's OnResponseStarted method has been called.
477 void GetCharset(std::string
* charset
);
479 // Returns the HTTP response code (e.g., 200, 404, and so on). This method
480 // may only be called once the delegate's OnResponseStarted method has been
481 // called. For non-HTTP requests, this method returns -1.
482 int GetResponseCode();
484 // Get the HTTP response info in its entirety.
485 const HttpResponseInfo
& response_info() const { return response_info_
; }
487 // Access the LOAD_* flags modifying this request (see load_flags.h).
488 int load_flags() const { return load_flags_
; }
489 void set_load_flags(int flags
) { load_flags_
= flags
; }
491 // Returns true if the request is "pending" (i.e., if Start() has been called,
492 // and the response has not yet been called).
493 bool is_pending() const { return is_pending_
; }
495 // Returns the error status of the request.
496 const URLRequestStatus
& status() const { return status_
; }
498 // Returns a globally unique identifier for this request.
499 uint64
identifier() const { return identifier_
; }
501 // This method is called to start the request. The delegate will receive
502 // a OnResponseStarted callback when the request is started.
505 // This method may be called at any time after Start() has been called to
506 // cancel the request. This method may be called many times, and it has
507 // no effect once the response has completed. It is guaranteed that no
508 // methods of the delegate will be called after the request has been
509 // cancelled, except that this may call the delegate's OnReadCompleted()
510 // during the call to Cancel itself.
513 // Cancels the request and sets the error to |error| (see net_error_list.h
515 void SimulateError(int error
);
517 // Cancels the request and sets the error to |error| (see net_error_list.h
518 // for values) and attaches |ssl_info| as the SSLInfo for that request. This
519 // is useful to attach a certificate and certificate error to a canceled
521 void SimulateSSLError(int error
, const SSLInfo
& ssl_info
);
523 // Read initiates an asynchronous read from the response, and must only
524 // be called after the OnResponseStarted callback is received with a
525 // successful status.
526 // If data is available, Read will return true, and the data and length will
527 // be returned immediately. If data is not available, Read returns false,
528 // and an asynchronous Read is initiated. The Read is finished when
529 // the caller receives the OnReadComplete callback. Unless the request was
530 // cancelled, OnReadComplete will always be called, even if the read failed.
532 // The buf parameter is a buffer to receive the data. If the operation
533 // completes asynchronously, the implementation will reference the buffer
534 // until OnReadComplete is called. The buffer must be at least max_bytes in
537 // The max_bytes parameter is the maximum number of bytes to read.
539 // The bytes_read parameter is an output parameter containing the
540 // the number of bytes read. A value of 0 indicates that there is no
541 // more data available to read from the stream.
543 // If a read error occurs, Read returns false and the request->status
544 // will be set to an error.
545 bool Read(IOBuffer
* buf
, int max_bytes
, int* bytes_read
);
547 // If this request is being cached by the HTTP cache, stop subsequent caching.
548 // Note that this method has no effect on other (simultaneous or not) requests
549 // for the same resource. The typical example is a request that results in
550 // the data being stored to disk (downloaded instead of rendered) so we don't
551 // want to store it twice.
554 // This method may be called to follow a redirect that was deferred in
555 // response to an OnReceivedRedirect call.
556 void FollowDeferredRedirect();
558 // One of the following two methods should be called in response to an
559 // OnAuthRequired() callback (and only then).
560 // SetAuth will reissue the request with the given credentials.
561 // CancelAuth will give up and display the error page.
562 void SetAuth(const AuthCredentials
& credentials
);
565 // This method can be called after the user selects a client certificate to
566 // instruct this URLRequest to continue with the request with the
567 // certificate. Pass NULL if the user doesn't have a client certificate.
568 void ContinueWithCertificate(X509Certificate
* client_cert
);
570 // This method can be called after some error notifications to instruct this
571 // URLRequest to ignore the current error and continue with the request. To
572 // cancel the request instead, call Cancel().
573 void ContinueDespiteLastError();
575 // Used to specify the context (cookie store, cache) for this request.
576 const URLRequestContext
* context() const;
577 void set_context(const URLRequestContext
* context
);
579 const BoundNetLog
& net_log() const { return net_log_
; }
581 // Returns the expected content size if available
582 int64
GetExpectedContentSize() const;
584 // Returns the priority level for this request.
585 RequestPriority
priority() const { return priority_
; }
586 void set_priority(RequestPriority priority
) {
587 DCHECK_GE(priority
, HIGHEST
);
588 DCHECK_LT(priority
, NUM_PRIORITIES
);
589 priority_
= priority
;
592 // This method is intended only for unit tests, but it is being used by
593 // unit tests outside of net :(.
594 URLRequestJob
* job() { return job_
; }
597 // Allow the URLRequestJob class to control the is_pending() flag.
598 void set_is_pending(bool value
) { is_pending_
= value
; }
600 // Allow the URLRequestJob class to set our status too
601 void set_status(const URLRequestStatus
& value
) { status_
= value
; }
603 // Allow the URLRequestJob to redirect this request. Returns OK if
604 // successful, otherwise an error code is returned.
605 int Redirect(const GURL
& location
, int http_status_code
);
607 // Called by URLRequestJob to allow interception when a redirect occurs.
608 void NotifyReceivedRedirect(const GURL
& location
, bool* defer_redirect
);
610 // Allow an interceptor's URLRequestJob to restart this request.
611 // Should only be called if the original job has not started a response.
615 friend class URLRequestJob
;
617 // Registers a new protocol handler for the given scheme. If the scheme is
618 // already handled, this will overwrite the given factory. To delete the
619 // protocol factory, use NULL for the factory BUT this WILL NOT put back
620 // any previously registered protocol factory. It will have returned
621 // the previously registered factory (or NULL if none is registered) when
622 // the scheme was first registered so that the caller can manually put it
625 // The scheme must be all-lowercase ASCII. See the ProtocolFactory
626 // declaration for its requirements.
628 // The registered protocol factory may return NULL, which will cause the
629 // regular "built-in" protocol factory to be used.
631 static ProtocolFactory
* RegisterProtocolFactory(const std::string
& scheme
,
632 ProtocolFactory
* factory
);
634 // Registers or unregisters a network interception class.
635 static void RegisterRequestInterceptor(Interceptor
* interceptor
);
636 static void UnregisterRequestInterceptor(Interceptor
* interceptor
);
638 // Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest
639 // handler. If |blocked| is true, the request is blocked and an error page is
640 // returned indicating so. This should only be called after Start is called
641 // and OnBeforeRequest returns true (signalling that the request should be
643 void BeforeRequestComplete(int error
);
645 void StartJob(URLRequestJob
* job
);
647 // Restarting involves replacing the current job with a new one such as what
648 // happens when following a HTTP redirect.
649 void RestartWithJob(URLRequestJob
* job
);
650 void PrepareToRestart();
652 // Detaches the job from this request in preparation for this object going
653 // away or the job being replaced. The job will not call us back when it has
657 // Cancels the request and set the error and ssl info for this request to the
659 void DoCancel(int error
, const SSLInfo
& ssl_info
);
661 // Notifies the network delegate that the request has been completed.
662 // This does not imply a successful completion. Also a canceled request is
663 // considered completed.
664 void NotifyRequestCompleted();
666 // Called by URLRequestJob to allow interception when the final response
668 void NotifyResponseStarted();
670 bool has_delegate() const { return delegate_
!= NULL
; }
672 // These functions delegate to |delegate_| and may only be used if
673 // |delegate_| is not NULL. See URLRequest::Delegate for the meaning
674 // of these functions.
675 void NotifyAuthRequired(AuthChallengeInfo
* auth_info
);
676 void NotifyAuthRequiredComplete(NetworkDelegate::AuthRequiredResponse result
);
677 void NotifyCertificateRequested(SSLCertRequestInfo
* cert_request_info
);
678 void NotifySSLCertificateError(const SSLInfo
& ssl_info
, bool fatal
);
679 bool CanGetCookies(const CookieList
& cookie_list
) const;
680 bool CanSetCookie(const std::string
& cookie_line
,
681 CookieOptions
* options
) const;
682 void NotifyReadCompleted(int bytes_read
);
684 // Called when the delegate blocks or unblocks this request when intercepting
686 void SetBlockedOnDelegate();
687 void SetUnblockedOnDelegate();
689 // Contextual information used for this request (can be NULL). This contains
690 // most of the dependencies which are shared between requests (disk cache,
691 // cookie store, socket pool, etc.)
692 scoped_refptr
<const URLRequestContext
> context_
;
694 // Tracks the time spent in various load states throughout this request.
695 BoundNetLog net_log_
;
697 scoped_refptr
<URLRequestJob
> job_
;
698 scoped_refptr
<UploadData
> upload_
;
699 std::vector
<GURL
> url_chain_
;
700 GURL first_party_for_cookies_
;
701 GURL delegate_redirect_url_
;
702 std::string method_
; // "GET", "POST", etc. Should be all uppercase.
703 std::string referrer_
;
704 HttpRequestHeaders extra_request_headers_
;
705 int load_flags_
; // Flags indicating the request type for the load;
706 // expected values are LOAD_* enums above.
708 // Never access methods of the |delegate_| directly. Always use the
709 // Notify... methods for this.
712 // Current error status of the job. When no error has been encountered, this
713 // will be SUCCESS. If multiple errors have been encountered, this will be
714 // the first non-SUCCESS status seen.
715 URLRequestStatus status_
;
717 // The HTTP response info, lazily initialized.
718 HttpResponseInfo response_info_
;
720 // Tells us whether the job is outstanding. This is true from the time
721 // Start() is called to the time we dispatch RequestComplete and indicates
722 // whether the job is active.
725 // Number of times we're willing to redirect. Used to guard against
726 // infinite redirects.
729 // Cached value for use after we've orphaned the job handling the
730 // first transaction in a request involving redirects.
731 uint64 final_upload_progress_
;
733 // The priority level for this request. Objects like ClientSocketPool use
734 // this to determine which URLRequest to allocate sockets to first.
735 RequestPriority priority_
;
737 // TODO(battre): The only consumer of the identifier_ is currently the
738 // web request API. We need to match identifiers of requests between the
739 // web request API and the web navigation API. As the URLRequest does not
740 // exist when the web navigation API is triggered, the tracking probably
741 // needs to be done outside of the URLRequest anyway. Therefore, this
742 // identifier should be deleted here. http://crbug.com/89321
743 // A globally unique identifier for this request.
744 const uint64 identifier_
;
746 // True if this request is blocked waiting for the network delegate to resume
748 bool blocked_on_delegate_
;
750 // An optional parameter that provides additional information about the load
751 // state. Only used with the LOAD_STATE_WAITING_FOR_DELEGATE state.
752 string16 load_state_param_
;
754 base::debug::LeakTracker
<URLRequest
> leak_tracker_
;
756 // Callback passed to the network delegate to notify us when a blocked request
757 // is ready to be resumed or canceled.
758 CompletionCallback before_request_callback_
;
760 // Safe-guard to ensure that we do not send multiple "I am completed"
761 // messages to network delegate.
762 // TODO(battre): Remove this. http://crbug.com/89049
763 bool has_notified_completion_
;
765 // Authentication data used by the NetworkDelegate for this request,
766 // if one is present. |auth_credentials_| may be filled in when calling
767 // |NotifyAuthRequired| on the NetworkDelegate. |auth_info_| holds
768 // the authentication challenge being handled by |NotifyAuthRequired|.
769 AuthCredentials auth_credentials_
;
770 scoped_refptr
<AuthChallengeInfo
> auth_info_
;
772 base::TimeTicks creation_time_
;
774 DISALLOW_COPY_AND_ASSIGN(URLRequest
);
779 #endif // NET_URL_REQUEST_URL_REQUEST_H_