From aebc731c4e081da46d37e71dd2921c9dda9e6785 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Tue, 3 Aug 2021 23:09:57 +0200 Subject: [PATCH] fixed error status codes --- src/client.c | 2 +- src/lib/rev_proxy.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/client.c b/src/client.c index 51cc18f..b588f4a 100644 --- a/src/client.c +++ b/src/client.c @@ -379,7 +379,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int res.status = http_get_status(200); if (fastcgi_init(&php_fpm, client_num, req_num, client, &req, &uri) != 0) { - res.status = http_get_status(502); + res.status = http_get_status(503); sprintf(err_msg, "Unable to communicate with PHP-FPM."); goto respond; } diff --git a/src/lib/rev_proxy.c b/src/lib/rev_proxy.c index e8e8d6e..188c7bc 100644 --- a/src/lib/rev_proxy.c +++ b/src/lib/rev_proxy.c @@ -186,7 +186,7 @@ int rev_proxy_init(http_req *req, http_res *res, host_config *conf, sock *client goto rev_proxy_timeout_err; if (setsockopt(client->socket, SOL_SOCKET, SO_SNDTIMEO, &server_timeout, sizeof(server_timeout)) < 0) { rev_proxy_timeout_err: - res->status = http_get_status(502); + res->status = http_get_status(500); print(ERR_STR "Unable to set timeout for socket: %s" CLR_STR, strerror(errno)); sprintf(err_msg, "Unable to set timeout for socket: %s", strerror(errno)); goto proxy_err; @@ -194,7 +194,7 @@ int rev_proxy_init(http_req *req, http_res *res, host_config *conf, sock *client struct hostent *host_ent = gethostbyname(conf->rev_proxy.hostname); if (host_ent == NULL) { - res->status = http_get_status(502); + res->status = http_get_status(503); print(ERR_STR "Unable to connect to server: Name or service not known" CLR_STR); sprintf(err_msg, "Unable to connect to server: Name or service not known."); goto proxy_err; @@ -210,7 +210,13 @@ int rev_proxy_init(http_req *req, http_res *res, host_config *conf, sock *client } if (connect(rev_proxy.socket, (struct sockaddr *) &address, sizeof(address)) < 0) { - res->status = http_get_status(502); + if (errno == ETIMEDOUT) { + res->status = http_get_status(504); + } else if (errno == ECONNREFUSED) { + res->status = http_get_status(503); + } else { + res->status = http_get_status(500); + } print(ERR_STR "Unable to connect to server: %s" CLR_STR, strerror(errno)); sprintf(err_msg, "Unable to connect to server: %s.", strerror(errno)); goto proxy_err;