blob: 18c4e10ed20e0c4ac8fb4bab5d50a0efdc08097c [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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)a1401312014-03-18 10:20:56 +00008#include <string>
9
Torne (Richard Coles)58218062012-11-14 11:43:16 +000010#include "base/memory/weak_ptr.h"
Torne (Richard Coles)5f1c9432014-08-12 13:47:38 +010011#include "base/time/time.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000012#include "net/base/net_export.h"
Torne (Richard Coles)5f1c9432014-08-12 13:47:38 +010013#include "net/http/http_response_info.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000014#include "net/url_request/url_request_job.h"
15
16class GURL;
17
18namespace 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.
23class NET_EXPORT URLRequestRedirectJob : public URLRequestJob {
24 public:
25 // Valid status codes for the redirect job. Other 30x codes are theoretically
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000026 // 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)5f1c9432014-08-12 13:47:38 +010029 enum ResponseCode {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000030 REDIRECT_302_FOUND = 302,
31 REDIRECT_307_TEMPORARY_REDIRECT = 307,
32 };
33
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000034 // 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)58218062012-11-14 11:43:16 +000036 URLRequestRedirectJob(URLRequest* request,
37 NetworkDelegate* network_delegate,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000038 const GURL& redirect_destination,
Torne (Richard Coles)5f1c9432014-08-12 13:47:38 +010039 ResponseCode response_code,
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000040 const std::string& redirect_reason);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000041
Torne (Richard Coles)5f1c9432014-08-12 13:47:38 +010042 // URLRequestJob implementation:
43 virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE;
Ben Murdocheb525c52013-07-10 11:40:50 +010044 virtual void GetLoadTimingInfo(
45 LoadTimingInfo* load_timing_info) const OVERRIDE;
Torne (Richard Coles)5f1c9432014-08-12 13:47:38 +010046 virtual void Start() OVERRIDE;
47 virtual bool CopyFragmentOnRedirect(const GURL& location) const OVERRIDE;
48 virtual int GetResponseCode() const OVERRIDE;
Ben Murdocheb525c52013-07-10 11:40:50 +010049
Torne (Richard Coles)58218062012-11-14 11:43:16 +000050 private:
51 virtual ~URLRequestRedirectJob();
52
53 void StartAsync();
54
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000055 const GURL redirect_destination_;
Torne (Richard Coles)5f1c9432014-08-12 13:47:38 +010056 const ResponseCode response_code_;
Ben Murdocheb525c52013-07-10 11:40:50 +010057 base::TimeTicks receive_headers_end_;
Torne (Richard Coles)5f1c9432014-08-12 13:47:38 +010058 base::Time response_time_;
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000059 std::string redirect_reason_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000060
Torne (Richard Coles)5f1c9432014-08-12 13:47:38 +010061 scoped_refptr<HttpResponseHeaders> fake_headers_;
62
Torne (Richard Coles)58218062012-11-14 11:43:16 +000063 base::WeakPtrFactory<URLRequestRedirectJob> weak_factory_;
64};
65
66} // namespace net
67
68#endif // NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_