2021-02-02 21:09:18 +00:00
|
|
|
// Copyright 2020 Google LLC. All rights reserved.
|
2021-02-02 18:51:50 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
#ifndef PACKAGER_FILE_HTTP_H_
|
|
|
|
#define PACKAGER_FILE_HTTP_H_
|
|
|
|
|
|
|
|
#include <memory>
|
2021-02-02 21:09:18 +00:00
|
|
|
#include <string>
|
2021-02-02 18:51:50 +00:00
|
|
|
|
2023-10-09 23:21:41 +00:00
|
|
|
#include <absl/synchronization/notification.h>
|
feat: First phase of CMake build system implementation (#1072)
There are a lot of changes in this first phase, because there was a
lot of infrastructure required to get some meaningful amount of
porting done. Future PRs should be simpler.
<b>Summary of changes:</b><details>
- Remove old deps:
- boringssl (replaced with mbedtls, lighter, easier to build)
- gflags (replaced with absl::flags)
- Chromium build tools
- New deps to replace parts of Chromium base:
- abseil-cpp
- glog
- nlohmann::json (for tests only)
- Submodules, updates, and CMake build rules for third-party
libraries:
- curl
- gmock/gtest
- Ported internal libraries and their tests by removing Chromium deps
and adding CMake build rules:
- file (now using C++17 filesystem APIs)
- license_notice
- status
- version
- Test improvements
- Removed file tests that can never be re-enabled
- Re-enabled all other disabled file tests
- Debug JSON values when HTTP tests fail
- Fixed chunked-encoding issues in HTTP tests
- Updated and refactored Dockerfiles testing
- All docker files working, with OS versions updated to meet the
new tool requirements
- Local docker builds no longer write files to your working
directory as root
- Local docker builds can now be run in parallel without clobbering
each others' build outputs
- DEBUG=1 can drop you into an interactive shell when a docker
build fails
- Updated and heavily refactored workflows and Dockerfiles
- All docker files now tested in parallel on GitHub, speeding up CI
- All common workflow components broken out and using workflow_call
instead of custom actions
- Self-hosted runners now optional, to make testing easier on forks
- CMake porting works-in-process can now be fully tested on GitHub
- Building ported libraries and passing ported tests on all three
platforms!
- CI hacks for macOS removed, now testing on macos-latest!
- Python2 no longer required! (Only Python3)
- Using strict build flags, treating all warnings as errors.
</details>
<b>Required to build:</b>
- CMake >= 3.16
- Python 3
- A compiler supporting C++ >= 17
- g++ >= 9 if using GCC (Clang also fine)
- MSVC for Windows
<b>Still needs work:</b><details>
- Moving other dependencies into submodules (if we keep them):
- apple_apsl
- icu
- libevent
- libpng
- libwebm
- libxml
- modp_b64
- protobuf
- zlib
- Port remaining internal libraries:
- app
- hls
- media/base
- media/chunking
- media/codecs
- media/crypto
- media/demuxer
- media/event
- media/formats/dvb
- media/formats/mp2t
- media/formats/mp4
- media/formats/packed_audio
- media/formats/ttml
- media/formats/webm
- media/formats/webvtt
- media/formats/wvm
- media/origin
- media/public
- media/replicator
- media/trick_play
- mpd
- Port main application
- Add logging flags in absl and connect them to glog (which expects
gflags)
- Port pssh-box.py
- Port main test targets (packager_test.py and packager_app.py)
- Updating all requirement and build documentation
- Remove any remaining refs to gclient, depot_tools, ninja
- Update and complete release workflows using release-please
</details>
Issue #346 (Switch to abseil)
Issue #1047 (New build system)
2022-08-16 18:34:51 +00:00
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/file/file.h>
|
|
|
|
#include <packager/file/io_cache.h>
|
2021-02-02 18:51:50 +00:00
|
|
|
|
2021-02-02 21:09:18 +00:00
|
|
|
typedef void CURL;
|
|
|
|
struct curl_slist;
|
|
|
|
|
2021-02-02 18:51:50 +00:00
|
|
|
namespace shaka {
|
|
|
|
|
2021-02-02 21:09:18 +00:00
|
|
|
enum class HttpMethod {
|
|
|
|
kGet,
|
|
|
|
kPost,
|
|
|
|
kPut,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// HttpFile reads or writes network requests.
|
2021-02-02 18:51:50 +00:00
|
|
|
///
|
2021-02-02 21:09:18 +00:00
|
|
|
/// Note that calling Flush will indicate EOF for the upload and no more can be
|
|
|
|
/// uploaded.
|
|
|
|
///
|
|
|
|
/// About how to use this, please visit the corresponding documentation [1].
|
2021-02-02 18:51:50 +00:00
|
|
|
///
|
2022-03-07 19:56:34 +00:00
|
|
|
/// [1]
|
|
|
|
/// https://shaka-project.github.io/shaka-packager/html/tutorials/http_upload.html
|
2021-02-02 18:51:50 +00:00
|
|
|
class HttpFile : public File {
|
|
|
|
public:
|
2021-02-02 21:09:18 +00:00
|
|
|
HttpFile(HttpMethod method, const std::string& url);
|
|
|
|
HttpFile(HttpMethod method,
|
|
|
|
const std::string& url,
|
|
|
|
const std::string& upload_content_type,
|
|
|
|
const std::vector<std::string>& headers,
|
2021-08-04 18:56:44 +00:00
|
|
|
int32_t timeout_in_seconds);
|
2021-02-02 21:09:18 +00:00
|
|
|
|
|
|
|
HttpFile(const HttpFile&) = delete;
|
|
|
|
HttpFile& operator=(const HttpFile&) = delete;
|
2021-02-02 18:51:50 +00:00
|
|
|
|
2021-02-02 21:09:18 +00:00
|
|
|
Status CloseWithStatus();
|
2021-02-02 18:51:50 +00:00
|
|
|
|
|
|
|
/// @name File implementation overrides.
|
|
|
|
/// @{
|
|
|
|
bool Close() override;
|
|
|
|
int64_t Read(void* buffer, uint64_t length) override;
|
|
|
|
int64_t Write(const void* buffer, uint64_t length) override;
|
2023-07-14 01:55:48 +00:00
|
|
|
void CloseForWriting() override;
|
2021-02-02 18:51:50 +00:00
|
|
|
int64_t Size() override;
|
|
|
|
bool Flush() override;
|
|
|
|
bool Seek(uint64_t position) override;
|
|
|
|
bool Tell(uint64_t* position) override;
|
2021-02-02 21:09:18 +00:00
|
|
|
bool Open() override;
|
2021-02-02 18:51:50 +00:00
|
|
|
/// @}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~HttpFile() override;
|
|
|
|
|
|
|
|
private:
|
2021-02-02 21:09:18 +00:00
|
|
|
struct CurlDelete {
|
|
|
|
void operator()(CURL* curl);
|
|
|
|
void operator()(curl_slist* headers);
|
2021-02-02 18:51:50 +00:00
|
|
|
};
|
|
|
|
|
2021-02-02 21:09:18 +00:00
|
|
|
void SetupRequest();
|
|
|
|
void ThreadMain();
|
2021-02-02 18:51:50 +00:00
|
|
|
|
2021-02-02 21:09:18 +00:00
|
|
|
const std::string url_;
|
|
|
|
const std::string upload_content_type_;
|
2021-08-04 18:56:44 +00:00
|
|
|
const int32_t timeout_in_seconds_;
|
2021-02-02 21:09:18 +00:00
|
|
|
const HttpMethod method_;
|
|
|
|
IoCache download_cache_;
|
|
|
|
IoCache upload_cache_;
|
|
|
|
std::unique_ptr<CURL, CurlDelete> curl_;
|
|
|
|
// The headers need to remain alive for the duration of the request.
|
|
|
|
std::unique_ptr<curl_slist, CurlDelete> request_headers_;
|
|
|
|
Status status_;
|
2021-05-05 05:53:23 +00:00
|
|
|
std::string user_agent_;
|
feat: First phase of CMake build system implementation (#1072)
There are a lot of changes in this first phase, because there was a
lot of infrastructure required to get some meaningful amount of
porting done. Future PRs should be simpler.
<b>Summary of changes:</b><details>
- Remove old deps:
- boringssl (replaced with mbedtls, lighter, easier to build)
- gflags (replaced with absl::flags)
- Chromium build tools
- New deps to replace parts of Chromium base:
- abseil-cpp
- glog
- nlohmann::json (for tests only)
- Submodules, updates, and CMake build rules for third-party
libraries:
- curl
- gmock/gtest
- Ported internal libraries and their tests by removing Chromium deps
and adding CMake build rules:
- file (now using C++17 filesystem APIs)
- license_notice
- status
- version
- Test improvements
- Removed file tests that can never be re-enabled
- Re-enabled all other disabled file tests
- Debug JSON values when HTTP tests fail
- Fixed chunked-encoding issues in HTTP tests
- Updated and refactored Dockerfiles testing
- All docker files working, with OS versions updated to meet the
new tool requirements
- Local docker builds no longer write files to your working
directory as root
- Local docker builds can now be run in parallel without clobbering
each others' build outputs
- DEBUG=1 can drop you into an interactive shell when a docker
build fails
- Updated and heavily refactored workflows and Dockerfiles
- All docker files now tested in parallel on GitHub, speeding up CI
- All common workflow components broken out and using workflow_call
instead of custom actions
- Self-hosted runners now optional, to make testing easier on forks
- CMake porting works-in-process can now be fully tested on GitHub
- Building ported libraries and passing ported tests on all three
platforms!
- CI hacks for macOS removed, now testing on macos-latest!
- Python2 no longer required! (Only Python3)
- Using strict build flags, treating all warnings as errors.
</details>
<b>Required to build:</b>
- CMake >= 3.16
- Python 3
- A compiler supporting C++ >= 17
- g++ >= 9 if using GCC (Clang also fine)
- MSVC for Windows
<b>Still needs work:</b><details>
- Moving other dependencies into submodules (if we keep them):
- apple_apsl
- icu
- libevent
- libpng
- libwebm
- libxml
- modp_b64
- protobuf
- zlib
- Port remaining internal libraries:
- app
- hls
- media/base
- media/chunking
- media/codecs
- media/crypto
- media/demuxer
- media/event
- media/formats/dvb
- media/formats/mp2t
- media/formats/mp4
- media/formats/packed_audio
- media/formats/ttml
- media/formats/webm
- media/formats/webvtt
- media/formats/wvm
- media/origin
- media/public
- media/replicator
- media/trick_play
- mpd
- Port main application
- Add logging flags in absl and connect them to glog (which expects
gflags)
- Port pssh-box.py
- Port main test targets (packager_test.py and packager_app.py)
- Updating all requirement and build documentation
- Remove any remaining refs to gclient, depot_tools, ninja
- Update and complete release workflows using release-please
</details>
Issue #346 (Switch to abseil)
Issue #1047 (New build system)
2022-08-16 18:34:51 +00:00
|
|
|
std::string ca_file_;
|
|
|
|
std::string client_cert_file_;
|
|
|
|
std::string client_cert_private_key_file_;
|
|
|
|
std::string client_cert_private_key_password_;
|
2021-02-02 18:51:50 +00:00
|
|
|
|
|
|
|
// Signaled when the "curl easy perform" task completes.
|
feat: First phase of CMake build system implementation (#1072)
There are a lot of changes in this first phase, because there was a
lot of infrastructure required to get some meaningful amount of
porting done. Future PRs should be simpler.
<b>Summary of changes:</b><details>
- Remove old deps:
- boringssl (replaced with mbedtls, lighter, easier to build)
- gflags (replaced with absl::flags)
- Chromium build tools
- New deps to replace parts of Chromium base:
- abseil-cpp
- glog
- nlohmann::json (for tests only)
- Submodules, updates, and CMake build rules for third-party
libraries:
- curl
- gmock/gtest
- Ported internal libraries and their tests by removing Chromium deps
and adding CMake build rules:
- file (now using C++17 filesystem APIs)
- license_notice
- status
- version
- Test improvements
- Removed file tests that can never be re-enabled
- Re-enabled all other disabled file tests
- Debug JSON values when HTTP tests fail
- Fixed chunked-encoding issues in HTTP tests
- Updated and refactored Dockerfiles testing
- All docker files working, with OS versions updated to meet the
new tool requirements
- Local docker builds no longer write files to your working
directory as root
- Local docker builds can now be run in parallel without clobbering
each others' build outputs
- DEBUG=1 can drop you into an interactive shell when a docker
build fails
- Updated and heavily refactored workflows and Dockerfiles
- All docker files now tested in parallel on GitHub, speeding up CI
- All common workflow components broken out and using workflow_call
instead of custom actions
- Self-hosted runners now optional, to make testing easier on forks
- CMake porting works-in-process can now be fully tested on GitHub
- Building ported libraries and passing ported tests on all three
platforms!
- CI hacks for macOS removed, now testing on macos-latest!
- Python2 no longer required! (Only Python3)
- Using strict build flags, treating all warnings as errors.
</details>
<b>Required to build:</b>
- CMake >= 3.16
- Python 3
- A compiler supporting C++ >= 17
- g++ >= 9 if using GCC (Clang also fine)
- MSVC for Windows
<b>Still needs work:</b><details>
- Moving other dependencies into submodules (if we keep them):
- apple_apsl
- icu
- libevent
- libpng
- libwebm
- libxml
- modp_b64
- protobuf
- zlib
- Port remaining internal libraries:
- app
- hls
- media/base
- media/chunking
- media/codecs
- media/crypto
- media/demuxer
- media/event
- media/formats/dvb
- media/formats/mp2t
- media/formats/mp4
- media/formats/packed_audio
- media/formats/ttml
- media/formats/webm
- media/formats/webvtt
- media/formats/wvm
- media/origin
- media/public
- media/replicator
- media/trick_play
- mpd
- Port main application
- Add logging flags in absl and connect them to glog (which expects
gflags)
- Port pssh-box.py
- Port main test targets (packager_test.py and packager_app.py)
- Updating all requirement and build documentation
- Remove any remaining refs to gclient, depot_tools, ninja
- Update and complete release workflows using release-please
</details>
Issue #346 (Switch to abseil)
Issue #1047 (New build system)
2022-08-16 18:34:51 +00:00
|
|
|
absl::Notification task_exit_event_;
|
2021-02-02 18:51:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace shaka
|
|
|
|
|
|
|
|
#endif // PACKAGER_FILE_HTTP_H_
|