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 <cstdint>
11#include <memory>
12#include <string>
13#include <vector>
14
15#include <absl/synchronization/notification.h>
16
17#include <packager/file.h>
18#include <packager/file/io_cache.h>
19#include <packager/status.h>
20
21typedef void CURL;
22struct curl_slist;
23
24namespace shaka {
25
26enum class HttpMethod {
27 kGet,
28 kPost,
29 kPut,
30 kDelete,
31};
32
42class HttpFile : public File {
43 public:
44 HttpFile(HttpMethod method, const std::string& url);
45 HttpFile(HttpMethod method,
46 const std::string& url,
47 const std::string& upload_content_type,
48 const std::vector<std::string>& headers,
49 int32_t timeout_in_seconds);
50
51 HttpFile(const HttpFile&) = delete;
52 HttpFile& operator=(const HttpFile&) = delete;
53
54 static bool Delete(const std::string& url);
55
56 Status CloseWithStatus();
57
60 bool Close() override;
61 int64_t Read(void* buffer, uint64_t length) override;
62 int64_t Write(const void* buffer, uint64_t length) override;
63 void CloseForWriting() override;
64 int64_t Size() override;
65 bool Flush() override;
66 bool Seek(uint64_t position) override;
67 bool Tell(uint64_t* position) override;
68 bool Open() override;
70
71 protected:
72 ~HttpFile() override;
73
74 private:
75 struct CurlDelete {
76 void operator()(CURL* curl);
77 void operator()(curl_slist* headers);
78 };
79
80 void SetupRequest();
81 void ThreadMain();
82
83 const std::string url_;
84 const std::string upload_content_type_;
85 const int32_t timeout_in_seconds_;
86 const HttpMethod method_;
87 const bool isUpload_;
88 IoCache download_cache_;
89 IoCache upload_cache_;
90 std::unique_ptr<CURL, CurlDelete> curl_;
91 // The headers need to remain alive for the duration of the request.
92 std::unique_ptr<curl_slist, CurlDelete> request_headers_;
93 Status status_;
94 std::string user_agent_;
95 std::string ca_file_;
96 std::string client_cert_file_;
97 std::string client_cert_private_key_file_;
98 std::string client_cert_private_key_password_;
99
100 // Signaled when the "curl easy perform" task completes.
101 absl::Notification task_exit_event_;
102};
103
104} // namespace shaka
105
106#endif // PACKAGER_FILE_HTTP_H_
Declaration of class which implements a thread-safe circular buffer.
Definition io_cache.h:21
All the methods that are virtual are virtual for mocking.