47 printf(
"Exiting....\n");
53 printf(
"\tHeader key/value = {%s : %s}\n",key,value);
60 const char *method = hpd_httpd_method_str(m);
65 printf(
"Got %s request on %s\n", method, url);
70 char *body1 =
"<html><body><h1>Hello</h1>Your language: ";
71 char *body2 = lm_find(headers,
"Accept-Language");
72 if (body2 == NULL) body2 =
"n/a";
73 char *body3 =
"</body></html>";
74 char *body = malloc((strlen(body1)+strlen(body2)+strlen(body3)+1)*
sizeof(
char));
75 sprintf(body,
"%s%s%s",body1, body2, body3);
86 int main(
int argc,
char *argv[])
94 settings.
port = HPD_TCPD_P_HTTP_ALT;
98 printf(
"Debugging is set\n");
hpd_error_t hpd_httpd_response_create(hpd_httpd_response_t **response, hpd_httpd_request_t *req, hpd_status_t status)
Create the reponse and constructs the status line.
void header_printer(void *data, const char *key, const char *value)
hpd_error_t hpd_httpd_destroy(hpd_httpd_t *httpd)
Destroy a httpd instance.
hpd_error_t hpd_httpd_response_sendf(hpd_httpd_response_t *res, const char *fmt,...)
Send response to client.
static hpd_httpd_t * server
hpd_error_t hpd_httpd_request_get_url(hpd_httpd_request_t *req, const char **url)
Get the URL of this request.
struct hp_settings settings
hpd_error_t hpd_httpd_request_get_headers(hpd_httpd_request_t *req, hpd_map_t **headers)
Get a linked map of all headers for a request.
int handle_request(hpd_httpd_t *ins, hpd_httpd_request_t *req, void *ws_ctx, void **req_data)
hpd_error_t hpd_httpd_request_get_method(hpd_httpd_request_t *req, hpd_httpd_method_t *method)
Get the method of the http request.
Settings struct for webserver.
static struct ev_loop * loop
hpd_error_t hpd_httpd_create(hpd_httpd_t **httpd, hpd_httpd_settings_t *settings, const hpd_module_t *context, hpd_ev_loop_t *loop)
Create a new httpd instance.
hpd_error_t hpd_httpd_stop(hpd_httpd_t *httpd)
Stop a httpd instance.
int main(int argc, char *argv[])
hpd_error_t hpd_httpd_start(hpd_httpd_t *httpd)
Start a httpd instance.
hpd_httpd_nodata_f on_req_cmpl
#define HPD_HTTPD_SETTINGS_DEFAULT
Default settings for httpd.
enum hpd_httpd_method hpd_httpd_method_t
struct ev_loop hpd_ev_loop_t
static void exit_handler(int sig)