-
Notifications
You must be signed in to change notification settings - Fork 45
/
http.h
50 lines (42 loc) · 1.24 KB
/
http.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef __http_h
#define __http_h
#include <ev.h>
#include <curl/curl.h>
struct Buffer; // from evbuffsock.h
struct HttpClient {
CURLM *multi;
struct ev_loop *loop;
struct ev_timer timer_event;
int still_running;
};
struct HttpResponse {
int status_code;
struct Buffer *data;
};
struct HttpRequest {
CURL *easy;
char *url;
struct HttpClient *httpc;
char error[CURL_ERROR_SIZE];
struct Buffer *data;
void (*callback)(struct HttpRequest *req, struct HttpResponse *resp, void *arg);
void *cb_arg;
};
struct HttpSocket {
curl_socket_t sockfd;
CURL *easy;
int action;
long timeout;
struct ev_io ev;
int evset;
struct HttpClient *httpc;
};
struct HttpClient *new_http_client(struct ev_loop *loop);
void free_http_client(struct HttpClient *httpc);
struct HttpRequest *new_http_request(const char *url,
void (*callback)(struct HttpRequest *req, struct HttpResponse *resp, void *arg), void *cb_arg);
void free_http_request(struct HttpRequest *req);
struct HttpResponse *new_http_response(int status_code, void *data);
void free_http_response(struct HttpResponse *resp);
int http_client_get(struct HttpClient *httpc, struct HttpRequest *req);
#endif