ipfs-chromium
ipfs_url_loader.h
1 #ifndef COMPONENTS_IPFS_URL_LOADER_H_
2 #define COMPONENTS_IPFS_URL_LOADER_H_ 1
3 
4 #include "virtual_optional.h"
5 
6 #include "base/debug/debugging_buildflags.h"
7 #include "base/timer/timer.h"
8 #include "mojo/public/cpp/bindings/receiver_set.h"
9 #include "mojo/public/cpp/system/data_pipe.h"
10 #include "net/http/http_request_headers.h"
11 #include "services/network/public/cpp/resolve_host_client_base.h"
12 #include "services/network/public/cpp/resource_request.h"
13 #include "services/network/public/mojom/url_loader.mojom.h"
14 
15 #include <list>
16 
17 namespace ipfs {
18 class Client;
19 class IpfsRequest;
20 namespace ipld {
21 class DagHeaders;
22 }
23 } // namespace ipfs
24 
25 namespace network::mojom {
26 class URLLoaderFactory;
27 class HostResolver;
28 class NetworkContext;
29 } // namespace network::mojom
30 namespace network {
31 class SimpleURLLoader;
32 }
33 
34 namespace ipfs {
35 class InterRequestState;
36 
38  void FollowRedirect(
39  std::vector<std::string> const& removed_headers,
40  net::HttpRequestHeaders const& modified_headers,
41  net::HttpRequestHeaders const& modified_cors_exempt_headers,
42  VirtualOptional<::GURL> const& new_url) override;
43  void SetPriority(net::RequestPriority priority,
44  int32_t intra_priority_value) override;
45  void PauseReadingBodyFromNet() override;
46  void ResumeReadingBodyFromNet() override;
47 
48  public:
49  explicit IpfsUrlLoader(network::mojom::URLLoaderFactory& handles_http,
50  InterRequestState& state);
51  ~IpfsUrlLoader() noexcept override;
52 
53  using ptr = std::shared_ptr<IpfsUrlLoader>;
54 
55  // Passed as the RequestHandler for
56  // Interceptor::MaybeCreateLoader.
57  static void StartRequest(
58  ptr,
59  network::ResourceRequest const& resource_request,
60  mojo::PendingReceiver<network::mojom::URLLoader> receiver,
61  mojo::PendingRemote<network::mojom::URLLoaderClient> client);
62 
63  void OverrideUrl(GURL);
64  void AddHeader(std::string_view,std::string_view);
65  void extra(std::shared_ptr<network::mojom::URLLoader> xtra) { extra_ = xtra; }
66 
67  private:
68  using RequestHandle = std::unique_ptr<network::SimpleURLLoader>;
69 
70  raw_ref<InterRequestState> state_;
71  mojo::Receiver<network::mojom::URLLoader> receiver_{this};
72  mojo::Remote<network::mojom::URLLoaderClient> client_;
73  raw_ref<network::mojom::URLLoaderFactory> lower_loader_factory_;
74  mojo::ScopedDataPipeProducerHandle pipe_prod_ = {};
75  mojo::ScopedDataPipeConsumerHandle pipe_cons_ = {};
76  bool complete_ = false;
77  std::shared_ptr<Client> api_;
78  std::string original_url_;
79  std::string partial_block_;
80  std::shared_ptr<network::mojom::URLLoader> extra_;
81  std::unique_ptr<base::RepeatingTimer> stepper_;
82  std::string root_;
83  int status_ = 200;
84  std::string resp_loc_;
85  std::shared_ptr<IpfsRequest> ipfs_request_;
86 
87  void ReceiveBlockBytes(std::string_view);
88  void BlocksComplete(std::string mime_type, ipld::DagHeaders const&);
89  void DoesNotExist(std::string_view cid, std::string_view path);
90  void TakeStep();
91 };
92 
93 } // namespace ipfs
94 
95 #endif
Definition: ipfs_url_loader.h:37
Definition: dag_headers.h:13