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