2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +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
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_BASE_HTTP_KEY_FETCHER_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_HTTP_KEY_FETCHER_H_
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2021-02-02 21:09:18 +00:00
|
|
|
#include <string>
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/file/http_file.h>
|
|
|
|
#include <packager/macros.h>
|
|
|
|
#include <packager/media/base/key_fetcher.h>
|
|
|
|
#include <packager/status/status.h>
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-12-16 17:13:29 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
/// A KeyFetcher implementation that retrieves keys over HTTP(s).
|
|
|
|
/// This class is not fully thread safe. It can be used in multi-thread
|
|
|
|
/// environment once constructed, but it may not be safe to create a
|
|
|
|
/// HttpKeyFetcher object when any other thread is running due to use of
|
|
|
|
/// curl_global_init.
|
|
|
|
class HttpKeyFetcher : public KeyFetcher {
|
2013-12-16 17:13:29 +00:00
|
|
|
public:
|
2014-10-07 21:33:08 +00:00
|
|
|
/// Creates a fetcher with no timeout.
|
|
|
|
HttpKeyFetcher();
|
|
|
|
/// Create a fetcher with timeout.
|
|
|
|
/// @param timeout_in_seconds specifies the timeout in seconds.
|
2021-08-04 18:56:44 +00:00
|
|
|
HttpKeyFetcher(int32_t timeout_in_seconds);
|
2015-07-22 23:40:45 +00:00
|
|
|
~HttpKeyFetcher() override;
|
2014-10-07 21:33:08 +00:00
|
|
|
|
|
|
|
/// @name KeyFetcher implementation overrides.
|
2015-07-22 23:40:45 +00:00
|
|
|
Status FetchKeys(const std::string& url,
|
|
|
|
const std::string& request,
|
|
|
|
std::string* response) override;
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Fetch content using HTTP GET.
|
|
|
|
/// @param url specifies the content URL.
|
|
|
|
/// @param[out] response will contain the body of the http response on
|
|
|
|
/// success. It should not be NULL.
|
|
|
|
/// @return OK on success.
|
2014-10-07 21:33:08 +00:00
|
|
|
virtual Status Get(const std::string& url, std::string* response);
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Fetch content using HTTP POST.
|
|
|
|
/// @param url specifies the content URL.
|
|
|
|
/// @param[out] response will contain the body of the http response on
|
|
|
|
/// success. It should not be NULL.
|
|
|
|
/// @return OK on success.
|
2014-02-20 22:38:28 +00:00
|
|
|
virtual Status Post(const std::string& url,
|
|
|
|
const std::string& data,
|
2014-10-07 21:33:08 +00:00
|
|
|
std::string* response);
|
2013-12-16 17:13:29 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-18 01:33:07 +00:00
|
|
|
Status FetchInternal(HttpMethod method, const std::string& url,
|
2013-12-16 17:13:29 +00:00
|
|
|
const std::string& data, std::string* response);
|
|
|
|
|
2021-08-04 18:56:44 +00:00
|
|
|
const int32_t timeout_in_seconds_;
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(HttpKeyFetcher);
|
2013-12-16 17:13:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_HTTP_KEY_FETCHER_H_
|