summaryrefslogtreecommitdiff
path: root/src/curl/http.h
blob: 952a74aeda6d20089b2651f9530e32d45d1f7b6f (plain)
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
#pragma once

#include <al/str.h>

#include "../util/buffer.h"

#include "../loop.h"

#include "curl.h"

enum {
    NNWT_HTTP_HEAD = 0,
    NNWT_HTTP_GET,
    NNWT_HTTP_POST
};

enum {
    NNWT_HTTP_READ = 0,
    NNWT_HTTP_WRITE,
    NNWT_HTTP_RESPONSE_CODE,
    NNWT_HTTP_CONTENT_LENGTH,
    NNWT_HTTP_REDIRECT,
    NNWT_HTTP_FINISHED,
    NNWT_HTTP_ERROR
};

struct nn_http {
    struct nn_curl curl;
    long status_code;
    curl_off_t content_length;
    struct curl_slist *headers;
    void (*callback)(void *, u8, u8 *, void *);
    void *userdata;
};

struct nn_http_request {
    struct nn_http http;
    size_t pointer;
    struct nn_buffer payload;
    struct nn_buffer response;
    void (*callback)(void *, struct nn_http_request *, bool);
    void *userdata;
};

bool nn_http_init(struct nn_http *http);
void nn_http_set_url(struct nn_http *http, str *url);
void nn_http_set_user_agent(struct nn_http *http, str *user_agent);
void nn_http_add_header(struct nn_http *http, str *header);
void nn_http_set_range(struct nn_http *http, size_t start, size_t end);
void nn_http_close(struct nn_http *http);
bool nn_http_request_stream(struct nn_http *http, u8 method, struct nn_event_loop *loop,
    void (*callback)(void *, u8, u8 *, void *), void *userdata);
bool nn_http_request_init(struct nn_http_request *request);
bool nn_http_request(struct nn_http_request *request, u8 method, struct nn_event_loop *loop,
    void (*callback)(void *, struct nn_http_request *, bool), void *userdata);
void nn_http_request_close(struct nn_http_request *request);