1 // Copyright 2011 The Chromium Authors 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_raw_request_headers.h" 14 #include "net/http/http_response_info.h" 15 #include "net/url_request/redirect_util.h" 16 #include "net/url_request/url_request_job.h" 17 18 class GURL; 19 20 namespace net { 21 22 // A URLRequestJob that will redirect the request to the specified URL. This is 23 // useful to restart a request at a different URL based on the result of another 24 // job. The redirect URL could be visible to scripts if the redirect points to 25 // a same-origin URL, or if the redirection target is served with CORS response 26 // headers. 27 class NET_EXPORT URLRequestRedirectJob : public URLRequestJob { 28 public: 29 // Constructs a job that redirects to the specified URL. |redirect_reason| is 30 // logged for debugging purposes, and must not be an empty string. 31 URLRequestRedirectJob(URLRequest* request, 32 const GURL& redirect_destination, 33 RedirectUtil::ResponseCode response_code, 34 const std::string& redirect_reason); 35 36 ~URLRequestRedirectJob() override; 37 38 // URLRequestJob implementation: 39 void GetResponseInfo(HttpResponseInfo* info) override; 40 void GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override; 41 void Start() override; 42 void Kill() override; 43 bool CopyFragmentOnRedirect(const GURL& location) const override; 44 void SetRequestHeadersCallback(RequestHeadersCallback callback) override; 45 46 private: 47 void StartAsync(); 48 49 const GURL redirect_destination_; 50 const RedirectUtil::ResponseCode response_code_; 51 base::TimeTicks receive_headers_end_; 52 base::Time response_time_; 53 std::string redirect_reason_; 54 55 scoped_refptr<HttpResponseHeaders> fake_headers_; 56 57 RequestHeadersCallback request_headers_callback_; 58 59 base::WeakPtrFactory<URLRequestRedirectJob> weak_factory_{this}; 60 }; 61 62 } // namespace net 63 64 #endif // NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ 65