-
Notifications
You must be signed in to change notification settings - Fork 1
/
http_client.h
57 lines (49 loc) · 1.18 KB
/
http_client.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
51
52
53
54
55
56
57
#pragma once
#include <curl/curl.h>
#include <pthread.h>
typedef struct http_client_t {
CURLSH *curl_share;
pthread_mutex_t *curl_mutex;
int verbose;
} http_client_t;
typedef struct buffer_t {
char* data;
size_t length;
size_t size;
} buffer_t;
void buffer_init(buffer_t *buffer);
void buffer_free(buffer_t *buffer);
enum http_method{
HTTP_GET,
HTTP_POST
};
/**
* Initialize CURL
* @param verbose 1 - verbose, 0 - silent mode
* @return HTTP client handler
*/
http_client_t *http_init(void);
/**
* Make HTTP POST request
* @param hc HTTP client handler
* @param method HTTP method
* @param url URL for POST request
* @param headers HTTP headers
* @param follow_location 1 - redirect on Location header
* @param request POST request body
* @param buffer request result
* @return 0 on success
*/
int http_request(http_client_t *hc,
enum http_method method,
char *url,
struct curl_slist *headers,
int follow_location,
char *request,
buffer_t *buffer);
/**
* Free HTTP client object
* @brief http_free
* @param hc HTTP client handler
*/
void http_free(http_client_t *hc);