7#include <packager/media/base/http_key_fetcher.h>
15#include <packager/file/file_closer.h>
16#include <packager/file/http_file.h>
17#include <packager/status.h>
24const char kSoapActionHeader[] =
25 "SOAPAction: \"http://schemas.microsoft.com/DRM/2007/03/protocols/"
26 "AcquirePackagingData\"";
27const char kXmlContentType[] =
"text/xml; charset=UTF-8";
28const char kJsonContentType[] =
"application/json";
29constexpr size_t kBufferSize = 64 * 1024;
36 : timeout_in_seconds_(timeout_in_seconds) {}
38HttpKeyFetcher::~HttpKeyFetcher() {}
41 const std::string& request,
42 std::string* response) {
43 return Post(url, request, response);
47 return FetchInternal(HttpMethod::kGet, path,
"", response);
51 const std::string& data,
52 std::string* response) {
53 return FetchInternal(HttpMethod::kPost, path, data, response);
56Status HttpKeyFetcher::FetchInternal(HttpMethod method,
57 const std::string& path,
58 const std::string& data,
59 std::string* response) {
60 std::string content_type;
61 std::vector<std::string> headers;
62 if (!content_type_.empty()) {
63 content_type = content_type_;
64 }
else if (data.find(
"soap:Envelope") != std::string::npos) {
66 content_type = kXmlContentType;
67 headers.push_back(kSoapActionHeader);
69 content_type = kJsonContentType;
71 headers.insert(headers.end(), extra_headers_.begin(), extra_headers_.end());
73 std::unique_ptr<HttpFile, FileCloser> file(
74 new HttpFile(method, path, content_type, headers, timeout_in_seconds_));
76 return Status(error::INTERNAL_ERROR,
"Cannot open URL");
78 file->Write(data.data(), data.size());
80 file->CloseForWriting();
83 char temp[kBufferSize];
84 int64_t ret = file->Read(temp, kBufferSize);
87 response->append(temp, ret);
89 return file.release()->CloseWithStatus();
All the methods that are virtual are virtual for mocking.