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-02-20 22:38:28 +00:00
|
|
|
#include "base/compiler_specific.h"
|
2013-12-16 17:13:29 +00:00
|
|
|
#include "media/base/status.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
|
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
|
|
|
|
|
|
|
// Fetch |response| from |url| using HTTP GET.
|
|
|
|
// |response| should not be NULL, will contain the body of the http response
|
|
|
|
// on success.
|
|
|
|
// 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
|
|
|
|
|
|
|
// Fetch |response| from |url| using HTTP POST.
|
|
|
|
// |response| should not be NULL, will contain the body of the http response
|
|
|
|
// on success.
|
|
|
|
// 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);
|
|
|
|
};
|
|
|
|
|
|
|
|
// A simple HttpFetcher implementation using happyhttp.
|
|
|
|
class SimpleHttpFetcher : public HttpFetcher {
|
|
|
|
public:
|
2014-03-19 00:09:50 +00:00
|
|
|
// TODO: Add timeout support.
|
2014-02-20 22:38:28 +00:00
|
|
|
SimpleHttpFetcher();
|
|
|
|
virtual ~SimpleHttpFetcher();
|
|
|
|
|
|
|
|
// HttpFetcher implementation overrides.
|
|
|
|
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;
|
2013-12-16 17:13:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Internal implementation of HTTP functions, e.g. Get and Post.
|
|
|
|
Status FetchInternal(const std::string& method, const std::string& url,
|
|
|
|
const std::string& data, std::string* response);
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
// Track whether WSAStartup executes successfully.
|
|
|
|
bool wsa_startup_succeeded_;
|
|
|
|
#endif
|
|
|
|
|
2014-02-20 22:38:28 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(SimpleHttpFetcher);
|
2013-12-16 17:13:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
|
2014-02-20 22:38:28 +00:00
|
|
|
#endif // MEDIA_BASE_HTTP_FETCHER_H_
|
2013-12-16 17:13:29 +00:00
|
|
|
|