OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_URL_REQUEST_URL_REQUEST_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 namespace content { | 44 namespace content { |
45 class AppCacheInterceptor; | 45 class AppCacheInterceptor; |
46 } | 46 } |
47 | 47 |
48 namespace net { | 48 namespace net { |
49 | 49 |
50 class CookieOptions; | 50 class CookieOptions; |
51 class HostPortPair; | 51 class HostPortPair; |
52 class IOBuffer; | 52 class IOBuffer; |
53 struct LoadTimingInfo; | 53 struct LoadTimingInfo; |
| 54 struct RedirectInfo; |
54 class SSLCertRequestInfo; | 55 class SSLCertRequestInfo; |
55 class SSLInfo; | 56 class SSLInfo; |
56 class UploadDataStream; | 57 class UploadDataStream; |
57 class URLRequestContext; | 58 class URLRequestContext; |
58 class URLRequestJob; | 59 class URLRequestJob; |
59 class X509Certificate; | 60 class X509Certificate; |
60 | 61 |
61 // This stores the values of the Set-Cookie headers received during the request. | 62 // This stores the values of the Set-Cookie headers received during the request. |
62 // Each item in the vector corresponds to a Set-Cookie: line received, | 63 // Each item in the vector corresponds to a Set-Cookie: line received, |
63 // excluding the "Set-Cookie:" part. | 64 // excluding the "Set-Cookie:" part. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // behavior corresponds to NEVER_CLEAR_REFERRER. Embedders will want to use | 102 // behavior corresponds to NEVER_CLEAR_REFERRER. Embedders will want to use |
102 // NEVER_CLEAR_REFERRER when implementing the meta-referrer support | 103 // NEVER_CLEAR_REFERRER when implementing the meta-referrer support |
103 // (http://wiki.whatwg.org/wiki/Meta_referrer) and sending requests with a | 104 // (http://wiki.whatwg.org/wiki/Meta_referrer) and sending requests with a |
104 // non-default referrer policy. Only the default referrer policy requires | 105 // non-default referrer policy. Only the default referrer policy requires |
105 // the referrer to be cleared on transitions from HTTPS to HTTP. | 106 // the referrer to be cleared on transitions from HTTPS to HTTP. |
106 enum ReferrerPolicy { | 107 enum ReferrerPolicy { |
107 CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 108 CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
108 NEVER_CLEAR_REFERRER, | 109 NEVER_CLEAR_REFERRER, |
109 }; | 110 }; |
110 | 111 |
| 112 // First-party URL redirect policy: During server redirects, the first-party |
| 113 // URL for cookies normally doesn't change. However, if the request is a |
| 114 // top-level first-party request, the first-party URL should be updated to the |
| 115 // URL on every redirect. |
| 116 enum FirstPartyURLPolicy { |
| 117 NEVER_CHANGE_FIRST_PARTY_URL, |
| 118 UPDATE_FIRST_PARTY_URL_ON_REDIRECT, |
| 119 }; |
| 120 |
111 // This class handles network interception. Use with | 121 // This class handles network interception. Use with |
112 // (Un)RegisterRequestInterceptor. | 122 // (Un)RegisterRequestInterceptor. |
113 class NET_EXPORT Interceptor { | 123 class NET_EXPORT Interceptor { |
114 public: | 124 public: |
115 virtual ~Interceptor() {} | 125 virtual ~Interceptor() {} |
116 | 126 |
117 // Called for every request made. Should return a new job to handle the | 127 // Called for every request made. Should return a new job to handle the |
118 // request if it should be intercepted, or NULL to allow the request to | 128 // request if it should be intercepted, or NULL to allow the request to |
119 // be handled in the normal manner. | 129 // be handled in the normal manner. |
120 virtual URLRequestJob* MaybeIntercept( | 130 virtual URLRequestJob* MaybeIntercept( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // - OnReadCompleted* (zero or more calls until all data is read) | 188 // - OnReadCompleted* (zero or more calls until all data is read) |
179 // | 189 // |
180 // Read() must be called at least once. Read() returns true when it completed | 190 // Read() must be called at least once. Read() returns true when it completed |
181 // immediately, and false if an IO is pending or if there is an error. When | 191 // immediately, and false if an IO is pending or if there is an error. When |
182 // Read() returns false, the caller can check the Request's status() to see | 192 // Read() returns false, the caller can check the Request's status() to see |
183 // if an error occurred, or if the IO is just pending. When Read() returns | 193 // if an error occurred, or if the IO is just pending. When Read() returns |
184 // true with zero bytes read, it indicates the end of the response. | 194 // true with zero bytes read, it indicates the end of the response. |
185 // | 195 // |
186 class NET_EXPORT Delegate { | 196 class NET_EXPORT Delegate { |
187 public: | 197 public: |
188 // Called upon a server-initiated redirect. The delegate may call the | 198 // Called upon receiving a redirect. The delegate may call the request's |
189 // request's Cancel method to prevent the redirect from being followed. | 199 // Cancel method to prevent the redirect from being followed. Since there |
190 // Since there may be multiple chained redirects, there may also be more | 200 // may be multiple chained redirects, there may also be more than one |
191 // than one redirect call. | 201 // redirect call. |
192 // | 202 // |
193 // When this function is called, the request will still contain the | 203 // When this function is called, the request will still contain the |
194 // original URL, the destination of the redirect is provided in 'new_url'. | 204 // original URL, the destination of the redirect is provided in 'new_url'. |
195 // If the delegate does not cancel the request and |*defer_redirect| is | 205 // If the delegate does not cancel the request and |*defer_redirect| is |
196 // false, then the redirect will be followed, and the request's URL will be | 206 // false, then the redirect will be followed, and the request's URL will be |
197 // changed to the new URL. Otherwise if the delegate does not cancel the | 207 // changed to the new URL. Otherwise if the delegate does not cancel the |
198 // request and |*defer_redirect| is true, then the redirect will be | 208 // request and |*defer_redirect| is true, then the redirect will be |
199 // followed once FollowDeferredRedirect is called on the URLRequest. | 209 // followed once FollowDeferredRedirect is called on the URLRequest. |
200 // | 210 // |
201 // The caller must set |*defer_redirect| to false, so that delegates do not | 211 // The caller must set |*defer_redirect| to false, so that delegates do not |
202 // need to set it if they are happy with the default behavior of not | 212 // need to set it if they are happy with the default behavior of not |
203 // deferring redirect. | 213 // deferring redirect. |
204 virtual void OnReceivedRedirect(URLRequest* request, | 214 virtual void OnReceivedRedirect(URLRequest* request, |
205 const GURL& new_url, | 215 const RedirectInfo& redirect_info, |
206 bool* defer_redirect); | 216 bool* defer_redirect); |
207 | 217 |
208 // Called when we receive an authentication failure. The delegate should | 218 // Called when we receive an authentication failure. The delegate should |
209 // call request->SetAuth() with the user's credentials once it obtains them, | 219 // call request->SetAuth() with the user's credentials once it obtains them, |
210 // or request->CancelAuth() to cancel the login and display the error page. | 220 // or request->CancelAuth() to cancel the login and display the error page. |
211 // When it does so, the request will be reissued, restarting the sequence | 221 // When it does so, the request will be reissued, restarting the sequence |
212 // of On* callbacks. | 222 // of On* callbacks. |
213 virtual void OnAuthRequired(URLRequest* request, | 223 virtual void OnAuthRequired(URLRequest* request, |
214 AuthChallengeInfo* auth_info); | 224 AuthChallengeInfo* auth_info); |
215 | 225 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 // | 327 // |
318 // For example, if a top-level navigation is redirected, the | 328 // For example, if a top-level navigation is redirected, the |
319 // first-party for cookies will be the URL of the first URL in the | 329 // first-party for cookies will be the URL of the first URL in the |
320 // redirect chain throughout the whole redirect. If it was used for | 330 // redirect chain throughout the whole redirect. If it was used for |
321 // a security check, an attacker might try to get around this check | 331 // a security check, an attacker might try to get around this check |
322 // by starting from some page that redirects to the | 332 // by starting from some page that redirects to the |
323 // host-to-be-attacked. | 333 // host-to-be-attacked. |
324 const GURL& first_party_for_cookies() const { | 334 const GURL& first_party_for_cookies() const { |
325 return first_party_for_cookies_; | 335 return first_party_for_cookies_; |
326 } | 336 } |
327 // This method may be called before Start() or FollowDeferredRedirect() is | 337 // This method may only be called before Start(). |
328 // called. | |
329 void set_first_party_for_cookies(const GURL& first_party_for_cookies); | 338 void set_first_party_for_cookies(const GURL& first_party_for_cookies); |
330 | 339 |
| 340 // The first-party URL policy to apply when updating the first party URL |
| 341 // during redirects. The first-party URL policy may only be changed before |
| 342 // Start() is called. |
| 343 FirstPartyURLPolicy first_party_url_policy() const { |
| 344 return first_party_url_policy_; |
| 345 } |
| 346 void set_first_party_url_policy(FirstPartyURLPolicy first_party_url_policy); |
| 347 |
331 // The request method, as an uppercase string. "GET" is the default value. | 348 // The request method, as an uppercase string. "GET" is the default value. |
332 // The request method may only be changed before Start() is called and | 349 // The request method may only be changed before Start() is called and |
333 // should only be assigned an uppercase value. | 350 // should only be assigned an uppercase value. |
334 const std::string& method() const { return method_; } | 351 const std::string& method() const { return method_; } |
335 void set_method(const std::string& method); | 352 void set_method(const std::string& method); |
336 | 353 |
337 // Determines the new method of the request afer following a redirect. | 354 // Determines the new method of the request afer following a redirect. |
338 // |method| is the method used to arrive at the redirect, | 355 // |method| is the method used to arrive at the redirect, |
339 // |http_status_code| is the status code associated with the redirect. | 356 // |http_status_code| is the status code associated with the redirect. |
340 static std::string ComputeMethodForRedirect(const std::string& method, | 357 static std::string ComputeMethodForRedirect(const std::string& method, |
341 int http_status_code); | 358 int http_status_code); |
342 | 359 |
343 // The referrer URL for the request. This header may actually be suppressed | 360 // The referrer URL for the request. This header may actually be suppressed |
344 // from the underlying network request for security reasons (e.g., a HTTPS | 361 // from the underlying network request for security reasons (e.g., a HTTPS |
345 // URL will not be sent as the referrer for a HTTP request). The referrer | 362 // URL will not be sent as the referrer for a HTTP request). The referrer |
346 // may only be changed before Start() is called. | 363 // may only be changed before Start() is called. |
347 const std::string& referrer() const { return referrer_; } | 364 const std::string& referrer() const { return referrer_; } |
348 // Referrer is sanitized to remove URL fragment, user name and password. | 365 // Referrer is sanitized to remove URL fragment, user name and password. |
349 void SetReferrer(const std::string& referrer); | 366 void SetReferrer(const std::string& referrer); |
350 | 367 |
351 // The referrer policy to apply when updating the referrer during redirects. | 368 // The referrer policy to apply when updating the referrer during redirects. |
352 // The referrer policy may only be changed before Start() is called. | 369 // The referrer policy may only be changed before Start() is called. |
| 370 ReferrerPolicy referrer_policy() const { return referrer_policy_; } |
353 void set_referrer_policy(ReferrerPolicy referrer_policy); | 371 void set_referrer_policy(ReferrerPolicy referrer_policy); |
354 | 372 |
355 // Sets the delegate of the request. This value may be changed at any time, | 373 // Sets the delegate of the request. This value may be changed at any time, |
356 // and it is permissible for it to be null. | 374 // and it is permissible for it to be null. |
357 void set_delegate(Delegate* delegate); | 375 void set_delegate(Delegate* delegate); |
358 | 376 |
359 // Indicates that the request body should be sent using chunked transfer | 377 // Indicates that the request body should be sent using chunked transfer |
360 // encoding. This method may only be called before Start() is called. | 378 // encoding. This method may only be called before Start() is called. |
361 void EnableChunkedUpload(); | 379 void EnableChunkedUpload(); |
362 | 380 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 // Allow the URLRequestJob class to control the is_pending() flag. | 693 // Allow the URLRequestJob class to control the is_pending() flag. |
676 void set_is_pending(bool value) { is_pending_ = value; } | 694 void set_is_pending(bool value) { is_pending_ = value; } |
677 | 695 |
678 // Allow the URLRequestJob class to set our status too | 696 // Allow the URLRequestJob class to set our status too |
679 void set_status(const URLRequestStatus& value) { status_ = value; } | 697 void set_status(const URLRequestStatus& value) { status_ = value; } |
680 | 698 |
681 CookieStore* cookie_store() const { return cookie_store_; } | 699 CookieStore* cookie_store() const { return cookie_store_; } |
682 | 700 |
683 // Allow the URLRequestJob to redirect this request. Returns OK if | 701 // Allow the URLRequestJob to redirect this request. Returns OK if |
684 // successful, otherwise an error code is returned. | 702 // successful, otherwise an error code is returned. |
685 int Redirect(const GURL& location, int http_status_code); | 703 int Redirect(const RedirectInfo& redirect_info); |
686 | 704 |
687 // Called by URLRequestJob to allow interception when a redirect occurs. | 705 // Called by URLRequestJob to allow interception when a redirect occurs. |
688 void NotifyReceivedRedirect(const GURL& location, bool* defer_redirect); | 706 void NotifyReceivedRedirect(const RedirectInfo& redirect_info, |
| 707 bool* defer_redirect); |
689 | 708 |
690 // Called by URLRequestHttpJob (note, only HTTP(S) jobs will call this) to | 709 // Called by URLRequestHttpJob (note, only HTTP(S) jobs will call this) to |
691 // allow deferral of network initialization. | 710 // allow deferral of network initialization. |
692 void NotifyBeforeNetworkStart(bool* defer); | 711 void NotifyBeforeNetworkStart(bool* defer); |
693 | 712 |
694 // Allow an interceptor's URLRequestJob to restart this request. | 713 // Allow an interceptor's URLRequestJob to restart this request. |
695 // Should only be called if the original job has not started a response. | 714 // Should only be called if the original job has not started a response. |
696 void Restart(); | 715 void Restart(); |
697 | 716 |
698 private: | 717 private: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 BoundNetLog net_log_; | 800 BoundNetLog net_log_; |
782 | 801 |
783 scoped_refptr<URLRequestJob> job_; | 802 scoped_refptr<URLRequestJob> job_; |
784 scoped_ptr<UploadDataStream> upload_data_stream_; | 803 scoped_ptr<UploadDataStream> upload_data_stream_; |
785 std::vector<GURL> url_chain_; | 804 std::vector<GURL> url_chain_; |
786 GURL first_party_for_cookies_; | 805 GURL first_party_for_cookies_; |
787 GURL delegate_redirect_url_; | 806 GURL delegate_redirect_url_; |
788 std::string method_; // "GET", "POST", etc. Should be all uppercase. | 807 std::string method_; // "GET", "POST", etc. Should be all uppercase. |
789 std::string referrer_; | 808 std::string referrer_; |
790 ReferrerPolicy referrer_policy_; | 809 ReferrerPolicy referrer_policy_; |
| 810 FirstPartyURLPolicy first_party_url_policy_; |
791 HttpRequestHeaders extra_request_headers_; | 811 HttpRequestHeaders extra_request_headers_; |
792 int load_flags_; // Flags indicating the request type for the load; | 812 int load_flags_; // Flags indicating the request type for the load; |
793 // expected values are LOAD_* enums above. | 813 // expected values are LOAD_* enums above. |
794 | 814 |
795 // Never access methods of the |delegate_| directly. Always use the | 815 // Never access methods of the |delegate_| directly. Always use the |
796 // Notify... methods for this. | 816 // Notify... methods for this. |
797 Delegate* delegate_; | 817 Delegate* delegate_; |
798 | 818 |
799 // Current error status of the job. When no error has been encountered, this | 819 // Current error status of the job. When no error has been encountered, this |
800 // will be SUCCESS. If multiple errors have been encountered, this will be | 820 // will be SUCCESS. If multiple errors have been encountered, this will be |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 | 901 |
882 // The proxy server used for this request, if any. | 902 // The proxy server used for this request, if any. |
883 HostPortPair proxy_server_; | 903 HostPortPair proxy_server_; |
884 | 904 |
885 DISALLOW_COPY_AND_ASSIGN(URLRequest); | 905 DISALLOW_COPY_AND_ASSIGN(URLRequest); |
886 }; | 906 }; |
887 | 907 |
888 } // namespace net | 908 } // namespace net |
889 | 909 |
890 #endif // NET_URL_REQUEST_URL_REQUEST_H_ | 910 #endif // NET_URL_REQUEST_URL_REQUEST_H_ |
OLD | NEW |