OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_REDIRECT_JOB_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "net/base/net_export.h" | 9 #include "net/base/net_export.h" |
10 #include "net/url_request/url_request_job.h" | 10 #include "net/url_request/url_request_job.h" |
11 | 11 |
12 class GURL; | 12 class GURL; |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 | 15 |
16 // A URLRequestJob that will redirect the request to the specified | 16 // A URLRequestJob that will redirect the request to the specified |
17 // URL. This is useful to restart a request at a different URL based | 17 // URL. This is useful to restart a request at a different URL based |
18 // on the result of another job. | 18 // on the result of another job. |
19 class NET_EXPORT URLRequestRedirectJob : public URLRequestJob { | 19 class NET_EXPORT URLRequestRedirectJob : public URLRequestJob { |
20 public: | 20 public: |
21 // Valid status codes for the redirect job. Other 30x codes are theoretically | 21 // Valid status codes for the redirect job. Other 30x codes are theoretically |
22 // valid, but unused so far. | 22 // valid, but unused so far. Both 302 and 307 are temporary redirects, with |
| 23 // the difference being that 302 converts POSTs to GETs and removes upload |
| 24 // data. |
23 enum StatusCode { | 25 enum StatusCode { |
24 REDIRECT_302_FOUND = 302, | 26 REDIRECT_302_FOUND = 302, |
25 REDIRECT_307_TEMPORARY_REDIRECT = 307, | 27 REDIRECT_307_TEMPORARY_REDIRECT = 307, |
26 }; | 28 }; |
27 | 29 |
28 // Constructs a job that redirects to the specified URL. | 30 // Constructs a job that redirects to the specified URL. |
29 URLRequestRedirectJob(URLRequest* request, | 31 URLRequestRedirectJob(URLRequest* request, |
30 NetworkDelegate* network_delegate, | 32 NetworkDelegate* network_delegate, |
31 const GURL& redirect_destination); | 33 const GURL& redirect_destination, |
32 | 34 StatusCode http_status_code); |
33 // Change the HTTP status code to use for the redirect. Default is | |
34 // REDIRECT_302_FOUND. | |
35 void set_redirect_code(StatusCode code) { | |
36 http_status_code_ = static_cast<int>(code); | |
37 } | |
38 | 35 |
39 virtual void Start() OVERRIDE; | 36 virtual void Start() OVERRIDE; |
40 virtual bool IsRedirectResponse(GURL* location, | 37 virtual bool IsRedirectResponse(GURL* location, |
41 int* http_status_code) OVERRIDE; | 38 int* http_status_code) OVERRIDE; |
42 | 39 |
43 private: | 40 private: |
44 virtual ~URLRequestRedirectJob(); | 41 virtual ~URLRequestRedirectJob(); |
45 | 42 |
46 void StartAsync(); | 43 void StartAsync(); |
47 | 44 |
48 GURL redirect_destination_; | 45 const GURL redirect_destination_; |
49 int http_status_code_; | 46 const int http_status_code_; |
50 | 47 |
51 base::WeakPtrFactory<URLRequestRedirectJob> weak_factory_; | 48 base::WeakPtrFactory<URLRequestRedirectJob> weak_factory_; |
52 }; | 49 }; |
53 | 50 |
54 } // namespace net | 51 } // namespace net |
55 | 52 |
56 #endif // NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ | 53 #endif // NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ |
OLD | NEW |