You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.3 KiB
C

#ifndef HTTP_H
#define HTTP_H
#include <event.h>
#include "http-parser/http_parser.h"
typedef struct {
const char *s;
size_t sz;
} str_t;
struct http_client {
/* socket and server reference */
int fd;
struct event ev;
struct server *s;
14 years ago
int needs_free;
/* input buffer */
char *buffer;
size_t sz;
/* http parser */
http_parser_settings settings;
http_parser parser;
/* decoded http */
enum http_method verb;
str_t path;
str_t body;
14 years ago
str_t header_connection;
14 years ago
str_t header_if_none_match;
str_t out_content_type;
str_t out_etag;
14 years ago
/* private, used in HTTP parser */
str_t last_header_name;
};
struct http_client *
http_client_new(int fd, struct server *s);
void
http_client_serve(struct http_client *c);
void
http_client_free(struct http_client *c);
int
http_on_path(http_parser*, const char *at, size_t length);
int
http_on_path(http_parser*, const char *at, size_t length);
int
http_on_body(http_parser*, const char *at, size_t length);
14 years ago
int
http_on_header_name(http_parser*, const char *at, size_t length);
int
http_on_header_value(http_parser*, const char *at, size_t length);
int
http_on_complete(http_parser*);
void
http_set_header(str_t *h, const char *p);
14 years ago
void
http_send_reply(struct http_client *c, short code, const char *msg,
const char *body, size_t body_len);
#endif