Shaka Packager SDK
Loading...
Searching...
No Matches
http_file.h
1// Copyright 2020 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#ifndef PACKAGER_FILE_HTTP_H_
8#define PACKAGER_FILE_HTTP_H_
9
10#include <memory>
11#include <string>
12
13#include <absl/synchronization/notification.h>
14
15#include <packager/file.h>
16#include <packager/file/io_cache.h>
17
18typedef void CURL;
19struct curl_slist;
20
21namespace shaka {
22
23enum class HttpMethod {
24 kGet,
25 kPost,
26 kPut,
27 kDelete,
28};
29
39class HttpFile : public File {
40 public:
41 HttpFile(HttpMethod method, const std::string& url);
42 HttpFile(HttpMethod method,
43 const std::string& url,
44 const std::string& upload_content_type,
45 const std::vector<std::string>& headers,
46 int32_t timeout_in_seconds);
47
48 HttpFile(const HttpFile&) = delete;
49 HttpFile& operator=(const HttpFile&) = delete;
50
51 static bool Delete(const std::string& url);
52
53 Status CloseWithStatus();
54
57 bool Close() override;
58 int64_t Read(void* buffer, uint64_t length) override;
59 int64_t Write(const void* buffer, uint64_t length) override;
60 void CloseForWriting() override;
61 int64_t Size() override;
62 bool Flush() override;
63 bool Seek(uint64_t position) override;
64 bool Tell(uint64_t* position) override;
65 bool Open() override;
67
68 protected:
69 ~HttpFile() override;
70
71 private:
72 struct CurlDelete {
73 void operator()(CURL* curl);
74 void operator()(curl_slist* headers);
75 };
76
77 void SetupRequest();
78 void ThreadMain();
79
80 const std::string url_;
81 const std::string upload_content_type_;
82 const int32_t timeout_in_seconds_;
83 const HttpMethod method_;
84 const bool isUpload_;
85 IoCache download_cache_;
86 IoCache upload_cache_;
87 std::unique_ptr<CURL, CurlDelete> curl_;
88 // The headers need to remain alive for the duration of the request.
89 std::unique_ptr<curl_slist, CurlDelete> request_headers_;
90 Status status_;
91 std::string user_agent_;
92 std::string ca_file_;
93 std::string client_cert_file_;
94 std::string client_cert_private_key_file_;
95 std::string client_cert_private_key_password_;
96
97 // Signaled when the "curl easy perform" task completes.
98 absl::Notification task_exit_event_;
99};
100
101} // namespace shaka
102
103#endif // PACKAGER_FILE_HTTP_H_
Declaration of class which implements a thread-safe circular buffer.
Definition io_cache.h:20
All the methods that are virtual are virtual for mocking.