kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 582e18d2ec4ffbe4ca3b05499fb9eaee1c16b451
parent fb335e1e0c3f0dff311dc9bbdbfbe992cb2b67f4
Author: Frederic Cambus <fred@statdns.com>
Date:   Wed, 21 Apr 2021 14:36:39 +0200

Stop hardcoding HTTP error codes in http_response() calls.

Use predefined HTTP_STATUS_* macros instead.

Diffstat:
src/auth.c | 4++--
src/jsonrpc.c | 8++++----
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/auth.c b/src/auth.c @@ -90,12 +90,12 @@ kore_auth_run(struct http_request *req, struct kore_auth *auth) kore_debug("kore_auth_run() for %s failed", req->path); if (auth->redirect == NULL) { - http_response(req, 403, NULL, 0); + http_response(req, HTTP_STATUS_FORBIDDEN, NULL, 0); return (KORE_RESULT_ERROR); } http_response_header(req, "location", auth->redirect); - http_response(req, 302, NULL, 0); + http_response(req, HTTP_STATUS_FOUND, NULL, 0); return (KORE_RESULT_ERROR); } diff --git a/src/jsonrpc.c b/src/jsonrpc.c @@ -423,13 +423,13 @@ jsonrpc_error(struct jsonrpc_request *req, int code, const char *msg) http_response_header(req->http, "content-type", "application/json"); yajl_gen_get_buf(req->gen, &body, &body_len); succeeded: - http_response(req->http, 200, body, body_len); + http_response(req->http, HTTP_STATUS_OK, body, body_len); if (req->gen != NULL) yajl_gen_clear(req->gen); jsonrpc_destroy_request(req); return (KORE_RESULT_OK); failed: - http_response(req->http, 500, NULL, 0); + http_response(req->http, HTTP_STATUS_INTERNAL_ERROR, NULL, 0); jsonrpc_destroy_request(req); return (KORE_RESULT_OK); } @@ -466,13 +466,13 @@ jsonrpc_result(struct jsonrpc_request *req, http_response_header(req->http, "content-type", "application/json"); yajl_gen_get_buf(req->gen, &body, &body_len); succeeded: - http_response(req->http, 200, body, body_len); + http_response(req->http, HTTP_STATUS_OK, body, body_len); if (req->gen != NULL) yajl_gen_clear(req->gen); jsonrpc_destroy_request(req); return (KORE_RESULT_OK); failed: - http_response(req->http, 500, NULL, 0); + http_response(req->http, HTTP_STATUS_INTERNAL_ERROR, NULL, 0); jsonrpc_destroy_request(req); return (KORE_RESULT_OK); }