Files
2026-09-29 20:42:04 +01:00

77 lines
1.7 KiB
C

#ifndef NX_HTTP_H
#define NX_HTTP_H
#include "nx_types.h"
#include "nx_buf.h"
#include "nx_socket.h"
#include "nx_sockaddr.h"
#if defined(__cplusplus)
extern "C" {
#endif
#define NX_HTTP_MAX_HEADER_BYTES (64 * 1024)
#define NX_HTTP_MAX_HEADERS 128
#define NX_HTTP_MAX_LINE 8192
#define NX_HTTP_MAX_BODY (16 * 1024 * 1024)
#define NX_HTTP_DEFAULT_PORT 80
#define NX_HTTP_TIMEOUT_MS 10000
typedef struct nx_http_header {
const char *name;
const char *value;
} nx_http_header;
typedef struct nx_http_response {
int status;
char reason[128];
char version[16];
nx_buf headers_buf;
nx_http_header headers[NX_HTTP_MAX_HEADERS];
int nheaders;
nx_buf body;
int has_body;
int chunked;
int keep_alive;
} nx_http_response;
typedef struct nx_http_request {
const char *method;
const char *host;
const char *path;
const void *body;
size_t body_len;
nx_http_header *headers;
int nheaders;
int timeout_ms;
int max_body;
int follow_redirect;
int user_agent;
} nx_http_request;
void nx_http_request_defaults(nx_http_request *req);
void nx_http_response_free(nx_http_response *res);
int nx_http_perform(const char *url, nx_http_request *req,
nx_http_response *res);
int nx_http_perform_fd(int fd, const char *host, const char *path,
nx_http_request *req, nx_http_response *res);
int nx_http_read_response(int fd, nx_buf *scratch, nx_http_request *req,
nx_http_response *res);
const char *nx_http_header_get(const nx_http_response *res, const char *name);
const char *nx_http_error(void);
#if defined(__cplusplus)
}
#endif
#endif