feat: add auth step
This commit is contained in:
parent
16103f9b24
commit
1e42dc04dc
4 changed files with 27 additions and 1 deletions
|
|
@ -97,3 +97,21 @@ bool http_loop_step_body_to_buf(event_loop_conn *conn) {
|
|||
|
||||
return ctx->req.body_received == ctx->req.body_len;
|
||||
}
|
||||
|
||||
bool http_loop_step_auth(event_loop_conn *conn) {
|
||||
http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
for (size_t i = 0; i < ctx->req.num_headers; i++) {
|
||||
struct phr_header *header = &ctx->req.headers[i];
|
||||
|
||||
if ((strncmp("X-Api-Key", header->name, header->name_len) == 0) &&
|
||||
(strncmp(header->value, ctx->g->api_key, header->value_len) == 0)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->res.status = http_unauthorized;
|
||||
conn->state = event_loop_conn_state_res;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue