7 #include "packager/media/base/http_key_fetcher.h"
9 #include "packager/file/file_closer.h"
16 const char kSoapActionHeader[] =
17 "SOAPAction: \"http://schemas.microsoft.com/DRM/2007/03/protocols/"
18 "AcquirePackagingData\"";
19 const char kXmlContentType[] =
"text/xml; charset=UTF-8";
20 const char kJsonContentType[] =
"application/json";
21 constexpr
size_t kBufferSize = 64 * 1024;
28 : timeout_in_seconds_(timeout_in_seconds) {}
30 HttpKeyFetcher::~HttpKeyFetcher() {}
33 const std::string& request,
34 std::string* response) {
35 return Post(url, request, response);
39 return FetchInternal(HttpMethod::kGet, path,
"", response);
43 const std::string& data,
44 std::string* response) {
45 return FetchInternal(HttpMethod::kPost, path, data, response);
48 Status HttpKeyFetcher::FetchInternal(HttpMethod method,
49 const std::string& path,
50 const std::string& data,
51 std::string* response) {
52 std::string content_type;
53 std::vector<std::string> headers;
54 if (data.find(
"soap:Envelope") != std::string::npos) {
56 content_type = kXmlContentType;
57 headers.push_back(kSoapActionHeader);
59 content_type = kJsonContentType;
62 std::unique_ptr<HttpFile, FileCloser> file(
63 new HttpFile(method, path, content_type, headers, timeout_in_seconds_));
65 return Status(error::INTERNAL_ERROR,
"Cannot open URL");
67 file->Write(data.data(), data.size());
71 char temp[kBufferSize];
72 int64_t ret = file->Read(temp, kBufferSize);
75 response->append(temp, ret);
77 return file.release()->CloseWithStatus();
All the methods that are virtual are virtual for mocking.