#ifndef C8_HTTP_H
#define C8_HTTP_H
#include <stdbool.h>
/*
* HTTP through curl as a subprocess, so there's no HTTP library in the
* apps and a hung server only costs its timeout. The request goes on
* curl's stdin (--config -), so a token or key is never in the process
* list. https only, unless allow_http (tests against a local mock).
*/
struct c8_http {
const char *method; // NULL: GET
const char *url;
const char *body; // sent as JSON, or NULL
/* Instead of a body: a file's bytes, sent as content_type (a picture
* for a server to keep) */
const char *upload, *content_type;
const char *token; // a bearer token, or NULL
const char *accept; // the Accept header, or NULL
const char *dest; // a download: the file (written as dest.part first)
const char *agent; // User-Agent
bool follow; // redirects
bool allow_http;
};
/* status: the HTTP one, 0 when the server wasn't reached (or there's no
* curl, or a download couldn't be put in place); body: NULL then, and
* for a download */
typedef void (*c8_http_fn)(int status, const char *body, void *data);
void c8_http(const struct c8_http *request, c8_http_fn fn, void *data);
#endif