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
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-02-20 22:38:28 +00:00
|
|
|
#ifndef MEDIA_BASE_HTTP_FETCHER_H_
|
|
|
|
#define MEDIA_BASE_HTTP_FETCHER_H_
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/compiler_specific.h"
|
|
|
|
#include "packager/media/base/status.h"
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-12-16 17:13:29 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Defines a generic http fetcher interface.
|
2014-02-20 22:38:28 +00:00
|
|
|
class HttpFetcher {
|
2013-12-16 17:13:29 +00:00
|
|
|
public:
|
2014-02-20 22:38:28 +00:00
|
|
|
HttpFetcher();
|
|
|
|
virtual ~HttpFetcher();
|
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-02-20 22:38:28 +00:00
|
|
|
virtual Status Get(const std::string& url, std::string* response) = 0;
|
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,
|
|
|
|
std::string* response) = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(HttpFetcher);
|
|
|
|
};
|
|
|
|
|
2014-06-18 01:33:07 +00:00
|
|
|
/// A simple HttpFetcher implementation.
|
|
|
|
/// 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
|
|
|
|
/// SimpleHttpFetcher object when any other thread is running due to use of
|
|
|
|
/// curl_global_init.
|
2014-02-20 22:38:28 +00:00
|
|
|
class SimpleHttpFetcher : public HttpFetcher {
|
|
|
|
public:
|
2014-06-18 01:33:07 +00:00
|
|
|
/// Creates a fetcher with no timeout.
|
2014-02-20 22:38:28 +00:00
|
|
|
SimpleHttpFetcher();
|
2014-06-18 01:33:07 +00:00
|
|
|
/// Create a fetcher with timeout.
|
|
|
|
/// @param timeout_in_seconds specifies the timeout in seconds.
|
2014-09-30 21:52:21 +00:00
|
|
|
SimpleHttpFetcher(uint32_t timeout_in_seconds);
|
2014-02-20 22:38:28 +00:00
|
|
|
virtual ~SimpleHttpFetcher();
|
|
|
|
|
2014-06-18 01:33:07 +00:00
|
|
|
/// @name HttpFetcher implementation overrides.
|
|
|
|
/// @{
|
2014-02-20 22:38:28 +00:00
|
|
|
virtual Status Get(const std::string& url, std::string* response) OVERRIDE;
|
|
|
|
virtual Status Post(const std::string& url,
|
|
|
|
const std::string& data,
|
|
|
|
std::string* response) OVERRIDE;
|
2014-06-18 01:33:07 +00:00
|
|
|
/// @}
|
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-02-20 22:38:28 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(SimpleHttpFetcher);
|
2013-12-16 17:13:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-02-20 22:38:28 +00:00
|
|
|
#endif // MEDIA_BASE_HTTP_FETCHER_H_
|
2013-12-16 17:13:29 +00:00
|
|
|
|