2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
2015-03-23 19:55:58 +00:00
|
|
|
//
|
|
|
|
/// NOTE: Inclusion of this module will cause curl_global_init and
|
|
|
|
/// curl_global_cleanup to be called at static initialization /
|
|
|
|
/// deinitialization time.
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
#ifndef MEDIA_BASE_HTTP_KEY_FETCHER_H_
|
|
|
|
#define MEDIA_BASE_HTTP_KEY_FETCHER_H_
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/compiler_specific.h"
|
2014-10-07 21:33:08 +00:00
|
|
|
#include "packager/media/base/key_fetcher.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/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.
|
|
|
|
HttpKeyFetcher(uint32_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
|
|
|
enum HttpMethod {
|
|
|
|
GET,
|
|
|
|
POST,
|
|
|
|
PUT
|
|
|
|
};
|
|
|
|
|
2013-12-16 17:13:29 +00:00
|
|
|
// Internal implementation of HTTP functions, e.g. Get and Post.
|
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);
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_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
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
#endif // MEDIA_BASE_HTTP_KEY_FETCHER_H_
|