Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / net / url_request / url_request_redirect_job.h
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
8 #include <string>
9
10 #include "base/memory/weak_ptr.h"
11 #include "base/time/time.h"
12 #include "net/base/net_export.h"
13 #include "net/http/http_response_info.h"
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 URL. This is
21 // useful to restart a request at a different URL based on the result of another
22 // job. The redirect URL could be visible to scripts if the redirect points to
23 // a same-origin URL, or if the redirection target is served with CORS response
24 // headers.
25 class NET_EXPORT URLRequestRedirectJob : public URLRequestJob {
26  public:
27   // Valid status codes for the redirect job. Other 30x codes are theoretically
28   // valid, but unused so far.  Both 302 and 307 are temporary redirects, with
29   // the difference being that 302 converts POSTs to GETs and removes upload
30   // data.
31   enum ResponseCode {
32     REDIRECT_302_FOUND = 302,
33     REDIRECT_307_TEMPORARY_REDIRECT = 307,
34   };
35
36   // Constructs a job that redirects to the specified URL.  |redirect_reason| is
37   // logged for debugging purposes, and must not be an empty string.
38   URLRequestRedirectJob(URLRequest* request,
39                         NetworkDelegate* network_delegate,
40                         const GURL& redirect_destination,
41                         ResponseCode response_code,
42                         const std::string& redirect_reason);
43
44   // URLRequestJob implementation:
45   virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE;
46   virtual void GetLoadTimingInfo(
47       LoadTimingInfo* load_timing_info) const OVERRIDE;
48   virtual void Start() OVERRIDE;
49   virtual bool CopyFragmentOnRedirect(const GURL& location) const OVERRIDE;
50   virtual int GetResponseCode() const OVERRIDE;
51
52  private:
53   virtual ~URLRequestRedirectJob();
54
55   void StartAsync();
56
57   const GURL redirect_destination_;
58   const ResponseCode response_code_;
59   base::TimeTicks receive_headers_end_;
60   base::Time response_time_;
61   std::string redirect_reason_;
62
63   scoped_refptr<HttpResponseHeaders> fake_headers_;
64
65   base::WeakPtrFactory<URLRequestRedirectJob> weak_factory_;
66 };
67
68 }  // namespace net
69
70 #endif  // NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_