Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2011 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. |
| 4 | |
| 5 | #ifndef NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ |
| 6 | #define NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ |
| 7 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 10 | #include "base/memory/weak_ptr.h" |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 11 | #include "base/time/time.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 12 | #include "net/base/net_export.h" |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 13 | #include "net/http/http_response_info.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 14 | #include "net/url_request/url_request_job.h" |
| 15 | |
| 16 | class GURL; |
| 17 | |
| 18 | namespace net { |
| 19 | |
| 20 | // A URLRequestJob that will redirect the request to the specified |
| 21 | // URL. This is useful to restart a request at a different URL based |
| 22 | // on the result of another job. |
| 23 | class NET_EXPORT URLRequestRedirectJob : public URLRequestJob { |
| 24 | public: |
| 25 | // Valid status codes for the redirect job. Other 30x codes are theoretically |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 26 | // valid, but unused so far. Both 302 and 307 are temporary redirects, with |
| 27 | // the difference being that 302 converts POSTs to GETs and removes upload |
| 28 | // data. |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 29 | enum ResponseCode { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 30 | REDIRECT_302_FOUND = 302, |
| 31 | REDIRECT_307_TEMPORARY_REDIRECT = 307, |
| 32 | }; |
| 33 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 34 | // Constructs a job that redirects to the specified URL. |redirect_reason| is |
| 35 | // logged for debugging purposes, and must not be an empty string. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 36 | URLRequestRedirectJob(URLRequest* request, |
| 37 | NetworkDelegate* network_delegate, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 38 | const GURL& redirect_destination, |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 39 | ResponseCode response_code, |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 40 | const std::string& redirect_reason); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 41 | |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 42 | // URLRequestJob implementation: |
| 43 | virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 44 | virtual void GetLoadTimingInfo( |
| 45 | LoadTimingInfo* load_timing_info) const OVERRIDE; |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 46 | virtual void Start() OVERRIDE; |
| 47 | virtual bool CopyFragmentOnRedirect(const GURL& location) const OVERRIDE; |
| 48 | virtual int GetResponseCode() const OVERRIDE; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 49 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 50 | private: |
| 51 | virtual ~URLRequestRedirectJob(); |
| 52 | |
| 53 | void StartAsync(); |
| 54 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 55 | const GURL redirect_destination_; |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 56 | const ResponseCode response_code_; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 57 | base::TimeTicks receive_headers_end_; |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 58 | base::Time response_time_; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 59 | std::string redirect_reason_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 60 | |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 61 | scoped_refptr<HttpResponseHeaders> fake_headers_; |
| 62 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 63 | base::WeakPtrFactory<URLRequestRedirectJob> weak_factory_; |
| 64 | }; |
| 65 | |
| 66 | } // namespace net |
| 67 | |
| 68 | #endif // NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ |