1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#ifndef CERT_TRANS_NET_URL_FETCHER_H_
#define CERT_TRANS_NET_URL_FETCHER_H_
#include <chrono>
#include <map>
#include <memory>
#include <ostream>
#include <string>
#include "base/macros.h"
#include "net/url.h"
#include "util/compare.h"
#include "util/task.h"
namespace cert_trans {
namespace libevent {
class Base;
}
class ThreadPool;
class UrlFetcher {
public:
typedef std::multimap<std::string, std::string, ci_less<std::string>>
Headers;
enum class Verb {
GET,
POST,
PUT,
DELETE,
};
struct Request {
Request() : verb(Verb::GET) {
}
Request(const URL& input_url) : verb(Verb::GET), url(input_url) {
}
Verb verb;
URL url;
Headers headers;
std::string body;
};
struct Response {
Response() : status_code(0) {
}
int status_code;
Headers headers;
std::string body;
};
UrlFetcher(libevent::Base* base, ThreadPool* thread_pool);
virtual ~UrlFetcher();
// If the status on the task is not OK, the response will be in an
// undefined state. If it is OK, it only means that the transaction
// with the remote server went correctly, you should still check
// Response::status_code.
virtual void Fetch(const Request& req, Response* resp, util::Task* task);
protected:
UrlFetcher();
private:
struct Impl;
const std::unique_ptr<Impl> impl_;
DISALLOW_COPY_AND_ASSIGN(UrlFetcher);
};
std::ostream& operator<<(std::ostream& output, const UrlFetcher::Request& req);
std::ostream& operator<<(std::ostream& output,
const UrlFetcher::Response& resp);
::std::ostream& operator<<(::std::ostream& os,
const UrlFetcher::Headers& headers);
::std::ostream& operator<<(::std::ostream& os, const UrlFetcher::Verb& verb);
} // namespace cert_trans
#endif // CERT_TRANS_NET_URL_FETCHER_H_
|