Home | History | Annotate | Download | only in url_request
      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 "net/base/net_export.h"
     12 #include "net/url_request/url_request_job.h"
     13 
     14 class GURL;
     15 
     16 namespace net {
     17 
     18 // A URLRequestJob that will redirect the request to the specified
     19 // URL.  This is useful to restart a request at a different URL based
     20 // on the result of another job.
     21 class NET_EXPORT URLRequestRedirectJob : public URLRequestJob {
     22  public:
     23   // Valid status codes for the redirect job. Other 30x codes are theoretically
     24   // valid, but unused so far.  Both 302 and 307 are temporary redirects, with
     25   // the difference being that 302 converts POSTs to GETs and removes upload
     26   // data.
     27   enum StatusCode {
     28     REDIRECT_302_FOUND = 302,
     29     REDIRECT_307_TEMPORARY_REDIRECT = 307,
     30   };
     31 
     32   // Constructs a job that redirects to the specified URL.  |redirect_reason| is
     33   // logged for debugging purposes, and must not be an empty string.
     34   URLRequestRedirectJob(URLRequest* request,
     35                         NetworkDelegate* network_delegate,
     36                         const GURL& redirect_destination,
     37                         StatusCode http_status_code,
     38                         const std::string& redirect_reason);
     39 
     40   virtual void Start() OVERRIDE;
     41   virtual bool IsRedirectResponse(GURL* location,
     42                                   int* http_status_code) OVERRIDE;
     43   virtual bool CopyFragmentOnRedirect(const GURL& location) const OVERRIDE;
     44 
     45   virtual void GetLoadTimingInfo(
     46       LoadTimingInfo* load_timing_info) const OVERRIDE;
     47 
     48  private:
     49   virtual ~URLRequestRedirectJob();
     50 
     51   void StartAsync();
     52 
     53   const GURL redirect_destination_;
     54   const int http_status_code_;
     55   base::TimeTicks receive_headers_end_;
     56   std::string redirect_reason_;
     57 
     58   base::WeakPtrFactory<URLRequestRedirectJob> weak_factory_;
     59 };
     60 
     61 }  // namespace net
     62 
     63 #endif  // NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_
     64