forked from chunyi1994/cppevent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpclient.h
36 lines (30 loc) · 1.01 KB
/
httpclient.h
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
#ifndef HTTPCLIENT_H
#define HTTPCLIENT_H
#include <string>
#include <functional>
#include "tcpclient.h"
#include "http_message.h"
namespace cppevent{
class EventLoop;
typedef std::function<void(const HttpMessage&, const std::string &)> HttpMessageCallback;
class HttpClient
{
public:
HttpClient(EventLoop *loop);
void addHeader(const std::string& name, const std::string& value);
void setMessageCallback(const HttpMessageCallback& cb);
void setHttpMessage(const HttpMessage& msg);
int get(const std::string&url, size_t port = 80);
int get(const std::string&url, const std::string& data, size_t port = 80);
int post(const std::string&url, size_t port = 80);
int post(const std::string&url, const std::string& data, size_t port = 80);
private:
void setDefaultHeaders(const std::string& host);
void handleMessage(const ConnectionPtr& conn);
TcpClient tcpClient_;
HttpMessage request_;
HttpMessage response_;
HttpMessageCallback httpMessageCallback_;
};
}
#endif // HTTPCLIENT_H