aboutsummaryrefslogtreecommitdiff
path: root/src/download.c
blob: 4154dcbc433a9ca940cf4f02097aa685759e2f9a (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
#include "download.h"
#include "buffer.h"
#include "program.h"

int download_to_buffer(const char *url, Buffer *buffer) {
    const char *args[] = {
        "curl", "-s", "-L", "-f",
        "-H", "user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
        "-H", "Accept-Language: en-US,en;q=0.5",
        "--compressed",
        "--",
        url,
        NULL
    };
    int result = program_exec(args, program_buffer_write_callback, buffer);
    if(result != 0)
        return result;
    buffer_append(buffer, "\0", 1);
    return result;
}

int is_header_response_ok(const char *url) {
    const char *args[] = {
        "curl", "-s", "-L", "-f", "-I",
        "-H", "user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
        "-H", "Accept-Language: en-US,en;q=0.5",
        "--",
        url,
        NULL
    };
    return program_exec(args, NULL, NULL);
}