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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // | 85 // |
86 // NOTE: All usage of all instances of this class should be on the same thread. | 86 // NOTE: All usage of all instances of this class should be on the same thread. |
87 // | 87 // |
88 class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), | 88 class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), |
89 public base::SupportsUserData { | 89 public base::SupportsUserData { |
90 public: | 90 public: |
91 // Callback function implemented by protocol handlers to create new jobs. | 91 // Callback function implemented by protocol handlers to create new jobs. |
92 // The factory may return NULL to indicate an error, which will cause other | 92 // The factory may return NULL to indicate an error, which will cause other |
93 // factories to be queried. If no factory handles the request, then the | 93 // factories to be queried. If no factory handles the request, then the |
94 // default job will be used. | 94 // default job will be used. |
95 typedef URLRequestJob* (ProtocolFactory)(URLRequest* request, | 95 typedef URLRequestJob*(ProtocolFactory)(URLRequest* request, |
96 NetworkDelegate* network_delegate, | 96 NetworkDelegate* network_delegate, |
97 const std::string& scheme); | 97 const std::string& scheme); |
98 | 98 |
99 // HTTP request/response header IDs (via some preprocessor fun) for use with | 99 // HTTP request/response header IDs (via some preprocessor fun) for use with |
100 // SetRequestHeaderById and GetResponseHeaderById. | 100 // SetRequestHeaderById and GetResponseHeaderById. |
101 enum { | 101 enum { |
102 #define HTTP_ATOM(x) HTTP_ ## x, | 102 #define HTTP_ATOM(x) HTTP_##x, |
103 #include "net/http/http_atom_list.h" | 103 #include "net/http/http_atom_list.h" |
104 #undef HTTP_ATOM | 104 #undef HTTP_ATOM |
105 }; | 105 }; |
106 | 106 |
107 // Referrer policies (see set_referrer_policy): During server redirects, the | 107 // Referrer policies (see set_referrer_policy): During server redirects, the |
108 // referrer header might be cleared, if the protocol changes from HTTPS to | 108 // referrer header might be cleared, if the protocol changes from HTTPS to |
109 // HTTP. This is the default behavior of URLRequest, corresponding to | 109 // HTTP. This is the default behavior of URLRequest, corresponding to |
110 // CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE. Alternatively, the | 110 // CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE. Alternatively, the |
111 // referrer policy can be set to never change the referrer header. This | 111 // referrer policy can be set to never change the referrer header. This |
112 // behavior corresponds to NEVER_CLEAR_REFERRER. Embedders will want to use | 112 // behavior corresponds to NEVER_CLEAR_REFERRER. Embedders will want to use |
113 // NEVER_CLEAR_REFERRER when implementing the meta-referrer support | 113 // NEVER_CLEAR_REFERRER when implementing the meta-referrer support |
114 // (http://wiki.whatwg.org/wiki/Meta_referrer) and sending requests with a | 114 // (http://wiki.whatwg.org/wiki/Meta_referrer) and sending requests with a |
115 // non-default referrer policy. Only the default referrer policy requires | 115 // non-default referrer policy. Only the default referrer policy requires |
116 // the referrer to be cleared on transitions from HTTPS to HTTP. | 116 // the referrer to be cleared on transitions from HTTPS to HTTP. |
117 enum ReferrerPolicy { | 117 enum ReferrerPolicy { |
118 CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 118 CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
119 NEVER_CLEAR_REFERRER, | 119 NEVER_CLEAR_REFERRER, |
120 }; | 120 }; |
121 | 121 |
122 // This class handles network interception. Use with | 122 // This class handles network interception. Use with |
123 // (Un)RegisterRequestInterceptor. | 123 // (Un)RegisterRequestInterceptor. |
124 class NET_EXPORT Interceptor { | 124 class NET_EXPORT Interceptor { |
125 public: | 125 public: |
126 virtual ~Interceptor() {} | 126 virtual ~Interceptor() {} |
127 | 127 |
128 // Called for every request made. Should return a new job to handle the | 128 // Called for every request made. Should return a new job to handle the |
129 // request if it should be intercepted, or NULL to allow the request to | 129 // request if it should be intercepted, or NULL to allow the request to |
130 // be handled in the normal manner. | 130 // be handled in the normal manner. |
131 virtual URLRequestJob* MaybeIntercept( | 131 virtual URLRequestJob* MaybeIntercept( |
132 URLRequest* request, NetworkDelegate* network_delegate) = 0; | 132 URLRequest* request, |
| 133 NetworkDelegate* network_delegate) = 0; |
133 | 134 |
134 // Called after having received a redirect response, but prior to the | 135 // Called after having received a redirect response, but prior to the |
135 // the request delegate being informed of the redirect. Can return a new | 136 // the request delegate being informed of the redirect. Can return a new |
136 // job to replace the existing job if it should be intercepted, or NULL | 137 // job to replace the existing job if it should be intercepted, or NULL |
137 // to allow the normal handling to continue. If a new job is provided, | 138 // to allow the normal handling to continue. If a new job is provided, |
138 // the delegate never sees the original redirect response, instead the | 139 // the delegate never sees the original redirect response, instead the |
139 // response produced by the intercept job will be returned. | 140 // response produced by the intercept job will be returned. |
140 virtual URLRequestJob* MaybeInterceptRedirect( | 141 virtual URLRequestJob* MaybeInterceptRedirect( |
141 URLRequest* request, | 142 URLRequest* request, |
142 NetworkDelegate* network_delegate, | 143 NetworkDelegate* network_delegate, |
143 const GURL& location); | 144 const GURL& location); |
144 | 145 |
145 // Called after having received a final response, but prior to the | 146 // Called after having received a final response, but prior to the |
146 // the request delegate being informed of the response. This is also | 147 // the request delegate being informed of the response. This is also |
147 // called when there is no server response at all to allow interception | 148 // called when there is no server response at all to allow interception |
148 // on dns or network errors. Can return a new job to replace the existing | 149 // on dns or network errors. Can return a new job to replace the existing |
149 // job if it should be intercepted, or NULL to allow the normal handling to | 150 // job if it should be intercepted, or NULL to allow the normal handling to |
150 // continue. If a new job is provided, the delegate never sees the original | 151 // continue. If a new job is provided, the delegate never sees the original |
151 // response, instead the response produced by the intercept job will be | 152 // response, instead the response produced by the intercept job will be |
152 // returned. | 153 // returned. |
153 virtual URLRequestJob* MaybeInterceptResponse( | 154 virtual URLRequestJob* MaybeInterceptResponse( |
154 URLRequest* request, NetworkDelegate* network_delegate); | 155 URLRequest* request, |
| 156 NetworkDelegate* network_delegate); |
155 }; | 157 }; |
156 | 158 |
157 // Deprecated interfaces in net::URLRequest. They have been moved to | 159 // Deprecated interfaces in net::URLRequest. They have been moved to |
158 // URLRequest's private section to prevent new uses. Existing uses are | 160 // URLRequest's private section to prevent new uses. Existing uses are |
159 // explicitly friended here and should be removed over time. | 161 // explicitly friended here and should be removed over time. |
160 class NET_EXPORT Deprecated { | 162 class NET_EXPORT Deprecated { |
161 private: | 163 private: |
162 // TODO(willchan): Kill off these friend declarations. | 164 // TODO(willchan): Kill off these friend declarations. |
163 friend class ::ChildProcessSecurityPolicyTest; | 165 friend class ::ChildProcessSecurityPolicyTest; |
164 friend class TestInterceptor; | 166 friend class TestInterceptor; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // When it does so, the request will be reissued, restarting the sequence | 237 // When it does so, the request will be reissued, restarting the sequence |
236 // of On* callbacks. | 238 // of On* callbacks. |
237 virtual void OnAuthRequired(URLRequest* request, | 239 virtual void OnAuthRequired(URLRequest* request, |
238 AuthChallengeInfo* auth_info); | 240 AuthChallengeInfo* auth_info); |
239 | 241 |
240 // Called when we receive an SSL CertificateRequest message for client | 242 // Called when we receive an SSL CertificateRequest message for client |
241 // authentication. The delegate should call | 243 // authentication. The delegate should call |
242 // request->ContinueWithCertificate() with the client certificate the user | 244 // request->ContinueWithCertificate() with the client certificate the user |
243 // selected, or request->ContinueWithCertificate(NULL) to continue the SSL | 245 // selected, or request->ContinueWithCertificate(NULL) to continue the SSL |
244 // handshake without a client certificate. | 246 // handshake without a client certificate. |
245 virtual void OnCertificateRequested( | 247 virtual void OnCertificateRequested(URLRequest* request, |
246 URLRequest* request, | 248 SSLCertRequestInfo* cert_request_info); |
247 SSLCertRequestInfo* cert_request_info); | |
248 | 249 |
249 // Called when using SSL and the server responds with a certificate with | 250 // 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 // 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 // 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 // safe thing and Cancel() the request or decide to proceed by calling |
253 // ContinueDespiteLastError(). cert_error is a ERR_* error code | 254 // ContinueDespiteLastError(). cert_error is a ERR_* error code |
254 // indicating what's wrong with the certificate. | 255 // indicating what's wrong with the certificate. |
255 // If |fatal| is true then the host in question demands a higher level | 256 // 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 // 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 // preference, or built-in policy). In this case, errors must not be |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 399 |
399 // Gets the upload data. | 400 // Gets the upload data. |
400 const UploadDataStream* get_upload() const; | 401 const UploadDataStream* get_upload() const; |
401 | 402 |
402 // Returns true if the request has a non-empty message body to upload. | 403 // Returns true if the request has a non-empty message body to upload. |
403 bool has_upload() const; | 404 bool has_upload() const; |
404 | 405 |
405 // Set an extra request header by ID or name, or remove one by name. These | 406 // Set an extra request header by ID or name, or remove one by name. These |
406 // methods may only be called before Start() is called, or before a new | 407 // methods may only be called before Start() is called, or before a new |
407 // redirect in the request chain. | 408 // redirect in the request chain. |
408 void SetExtraRequestHeaderById(int header_id, const std::string& value, | 409 void SetExtraRequestHeaderById(int header_id, |
| 410 const std::string& value, |
409 bool overwrite); | 411 bool overwrite); |
410 void SetExtraRequestHeaderByName(const std::string& name, | 412 void SetExtraRequestHeaderByName(const std::string& name, |
411 const std::string& value, bool overwrite); | 413 const std::string& value, |
| 414 bool overwrite); |
412 void RemoveRequestHeaderByName(const std::string& name); | 415 void RemoveRequestHeaderByName(const std::string& name); |
413 | 416 |
414 // Sets all extra request headers. Any extra request headers set by other | 417 // Sets all extra request headers. Any extra request headers set by other |
415 // methods are overwritten by this method. This method may only be called | 418 // methods are overwritten by this method. This method may only be called |
416 // before Start() is called. It is an error to call it later. | 419 // before Start() is called. It is an error to call it later. |
417 void SetExtraRequestHeaders(const HttpRequestHeaders& headers); | 420 void SetExtraRequestHeaders(const HttpRequestHeaders& headers); |
418 | 421 |
419 const HttpRequestHeaders& extra_request_headers() const { | 422 const HttpRequestHeaders& extra_request_headers() const { |
420 return extra_request_headers_; | 423 return extra_request_headers_; |
421 } | 424 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 483 |
481 // Get all response headers, \n-delimited and \n\0-terminated. This includes | 484 // Get all response headers, \n-delimited and \n\0-terminated. This includes |
482 // the response status line. Restrictions on GetResponseHeaders apply. | 485 // the response status line. Restrictions on GetResponseHeaders apply. |
483 void GetAllResponseHeaders(std::string* headers); | 486 void GetAllResponseHeaders(std::string* headers); |
484 | 487 |
485 // The time when |this| was constructed. | 488 // The time when |this| was constructed. |
486 base::TimeTicks creation_time() const { return creation_time_; } | 489 base::TimeTicks creation_time() const { return creation_time_; } |
487 | 490 |
488 // The time at which the returned response was requested. For cached | 491 // The time at which the returned response was requested. For cached |
489 // responses, this is the last time the cache entry was validated. | 492 // responses, this is the last time the cache entry was validated. |
490 const base::Time& request_time() const { | 493 const base::Time& request_time() const { return response_info_.request_time; } |
491 return response_info_.request_time; | |
492 } | |
493 | 494 |
494 // The time at which the returned response was generated. For cached | 495 // The time at which the returned response was generated. For cached |
495 // responses, this is the last time the cache entry was validated. | 496 // responses, this is the last time the cache entry was validated. |
496 const base::Time& response_time() const { | 497 const base::Time& response_time() const { |
497 return response_info_.response_time; | 498 return response_info_.response_time; |
498 } | 499 } |
499 | 500 |
500 // Indicate if this response was fetched from disk cache. | 501 // Indicate if this response was fetched from disk cache. |
501 bool was_cached() const { return response_info_.was_cached; } | 502 bool was_cached() const { return response_info_.was_cached; } |
502 | 503 |
503 // Returns true if the URLRequest was delivered through a proxy. | 504 // Returns true if the URLRequest was delivered through a proxy. |
504 bool was_fetched_via_proxy() const { | 505 bool was_fetched_via_proxy() const { |
505 return response_info_.was_fetched_via_proxy; | 506 return response_info_.was_fetched_via_proxy; |
506 } | 507 } |
507 | 508 |
508 // Returns true if the URLRequest was delivered over SPDY. | 509 // Returns true if the URLRequest was delivered over SPDY. |
509 bool was_fetched_via_spdy() const { | 510 bool was_fetched_via_spdy() const { |
510 return response_info_.was_fetched_via_spdy; | 511 return response_info_.was_fetched_via_spdy; |
511 } | 512 } |
512 | 513 |
513 // Returns the host and port that the content was fetched from. See | 514 // Returns the host and port that the content was fetched from. See |
514 // http_response_info.h for caveats relating to cached content. | 515 // http_response_info.h for caveats relating to cached content. |
515 HostPortPair GetSocketAddress() const; | 516 HostPortPair GetSocketAddress() const; |
516 | 517 |
517 // Get all response headers, as a HttpResponseHeaders object. See comments | 518 // Get all response headers, as a HttpResponseHeaders object. See comments |
518 // in HttpResponseHeaders class as to the format of the data. | 519 // in HttpResponseHeaders class as to the format of the data. |
519 HttpResponseHeaders* response_headers() const; | 520 HttpResponseHeaders* response_headers() const; |
520 | 521 |
521 // Get the SSL connection info. | 522 // Get the SSL connection info. |
522 const SSLInfo& ssl_info() const { | 523 const SSLInfo& ssl_info() const { return response_info_.ssl_info; } |
523 return response_info_.ssl_info; | |
524 } | |
525 | 524 |
526 // Gets timing information related to the request. Events that have not yet | 525 // Gets timing information related to the request. Events that have not yet |
527 // occurred are left uninitialized. After a second request starts, due to | 526 // occurred are left uninitialized. After a second request starts, due to |
528 // a redirect or authentication, values will be reset. | 527 // a redirect or authentication, values will be reset. |
529 // | 528 // |
530 // LoadTimingInfo only contains ConnectTiming information and socket IDs for | 529 // LoadTimingInfo only contains ConnectTiming information and socket IDs for |
531 // non-cached HTTP responses. | 530 // non-cached HTTP responses. |
532 void GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const; | 531 void GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const; |
533 | 532 |
534 // Returns the cookie values included in the response, if the request is one | 533 // Returns the cookie values included in the response, if the request is one |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 | 912 |
914 // The cookie store to be used for this request. | 913 // The cookie store to be used for this request. |
915 scoped_refptr<CookieStore> cookie_store_; | 914 scoped_refptr<CookieStore> cookie_store_; |
916 | 915 |
917 DISALLOW_COPY_AND_ASSIGN(URLRequest); | 916 DISALLOW_COPY_AND_ASSIGN(URLRequest); |
918 }; | 917 }; |
919 | 918 |
920 } // namespace net | 919 } // namespace net |
921 | 920 |
922 #endif // NET_URL_REQUEST_URL_REQUEST_H_ | 921 #endif // NET_URL_REQUEST_URL_REQUEST_H_ |
OLD | NEW |