Skip to content

Commit

Permalink
http: add HTTP request connection with authorization
Browse files Browse the repository at this point in the history
Adds a HTTP connection on top of client.c (struct http_cli) to handle the
authorization process by answering 401/403 responses. Supports basic, digest
and bearer authentication. Provides a high level interface for:
- setting HTTP method (GET, POST, PUT),
- setting content type and TLS host name,
- setting user, password and bearer,
- adding custom headers.
  • Loading branch information
cspiel1 committed Oct 16, 2020
1 parent 1fae071 commit 39278fc
Show file tree
Hide file tree
Showing 3 changed files with 601 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/re_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,24 @@ bool http_auth_check(const struct pl *hval, const struct pl *method,
bool http_auth_check_request(const struct http_msg *msg,
struct http_auth *auth,
http_auth_h *authh, void *arg);

/* http_reqconn - HTTP request connection */
struct http_reqconn;
int http_reqconn_alloc(struct http_reqconn **pconn,
struct http_cli *client,
http_resp_h *resph, http_data_h *datah, void* arg);
int http_reqconn_set_auth(struct http_reqconn *conn, const struct pl *user,
const struct pl *pass);
int http_reqconn_set_bearer(struct http_reqconn *conn,
const struct pl *bearer);
int http_reqconn_set_method(struct http_reqconn *conn, const struct pl *met);
int http_reqconn_set_body(struct http_reqconn *conn, const struct pl *body);
int http_reqconn_set_ctype(struct http_reqconn *conn, const struct pl *ctype);
int http_reqconn_add_header(struct http_reqconn *conn,
const struct pl *header);
int http_reqconn_clr_header(struct http_reqconn *conn);
int http_reqconn_send(struct http_reqconn *conn, const struct pl *uri);
#ifdef USE_TLS
int http_reqconn_set_tls_hostname(struct http_reqconn *conn,
const struct pl *hostname);
#endif
1 change: 1 addition & 0 deletions src/http/mod.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
SRCS += http/auth.c
SRCS += http/chunk.c
SRCS += http/client.c
SRCS += http/request.c
SRCS += http/msg.c
SRCS += http/server.c
Loading

0 comments on commit 39278fc

Please sign in to comment.