Shaka Packager SDK
http_key_fetcher.h
1 // Copyright 2014 Google Inc. 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 //
10 
11 #ifndef PACKAGER_MEDIA_BASE_HTTP_KEY_FETCHER_H_
12 #define PACKAGER_MEDIA_BASE_HTTP_KEY_FETCHER_H_
13 
14 #include "packager/base/compiler_specific.h"
15 #include "packager/media/base/key_fetcher.h"
16 #include "packager/status.h"
17 
18 namespace shaka {
19 namespace media {
20 
26 class HttpKeyFetcher : public KeyFetcher {
27  public:
32  HttpKeyFetcher(uint32_t timeout_in_seconds);
33  ~HttpKeyFetcher() override;
34 
36  Status FetchKeys(const std::string& url,
37  const std::string& request,
38  std::string* response) override;
39 
45  virtual Status Get(const std::string& url, std::string* response);
46 
52  virtual Status Post(const std::string& url,
53  const std::string& data,
54  std::string* response);
55 
61  void SetClientCertInfo(const std::string& cert_file,
62  const std::string& private_key_file,
63  const std::string& private_key_password) {
64  client_cert_file_ = cert_file;
65  client_cert_private_key_file_ = private_key_file;
66  client_cert_private_key_password_ = private_key_password;
67  }
70  void SetCaFile(const std::string& ca_file) {
71  ca_file_ = ca_file;
72  }
73 
74  private:
75  enum HttpMethod {
76  GET,
77  POST,
78  PUT
79  };
80 
81  // Internal implementation of HTTP functions, e.g. Get and Post.
82  Status FetchInternal(HttpMethod method, const std::string& url,
83  const std::string& data, std::string* response);
84 
85  const uint32_t timeout_in_seconds_;
86  std::string ca_file_;
87  std::string client_cert_file_;
88  std::string client_cert_private_key_file_;
89  std::string client_cert_private_key_password_;
90 
91  DISALLOW_COPY_AND_ASSIGN(HttpKeyFetcher);
92 };
93 
94 } // namespace media
95 } // namespace shaka
96 
97 #endif // PACKAGER_MEDIA_BASE_HTTP_KEY_FETCHER_H_
void SetCaFile(const std::string &ca_file)
All the methods that are virtual are virtual for mocking.
virtual Status Get(const std::string &url, std::string *response)
Base class for fetching keys from the license service.
Definition: key_fetcher.h:17
void SetClientCertInfo(const std::string &cert_file, const std::string &private_key_file, const std::string &private_key_password)
Status FetchKeys(const std::string &url, const std::string &request, std::string *response) override
HttpKeyFetcher()
Creates a fetcher with no timeout.
virtual Status Post(const std::string &url, const std::string &data, std::string *response)