From 4cd3526fde2fe81b0faf5aa3c535e1321796041b Mon Sep 17 00:00:00 2001 From: Francesco MDE <6103677+fralken@users.noreply.github.com> Date: Sat, 16 Mar 2024 08:40:46 +0100 Subject: [PATCH] remove confusing goto and replace with if/else statement --- forward.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/forward.c b/forward.c index f81a64f..3ee2d1d 100644 --- a/forward.c +++ b/forward.c @@ -163,13 +163,14 @@ rr_data_t forward_request(void *thread_data, rr_data_t request) { * - read proxy response * - forward it to the client with HTTP body, if present * - * There two goto's: - * - beginning: jump here to retry request (when cached connection timed out + * There is one goto to "beginning": + * - jump here to retry request (when cached connection timed out * or we thought proxy was notauth, but got 407) - * - shortcut: jump here from 1st iter. of inner loop, when we detect - * that auth isn't required by proxy. We do loop++, make the jump and - * the reply to our auth attempt (containing valid response) is sent to - * client directly without us making a request a second time. + * + * During 1st iter. of inner loop (loop == 0), when we detect + * that auth isn't required by proxy, we set loop = 1 and + * the reply to our auth attempt (containing valid response) is sent to + * client directly without us making a request a second time. */ if (request) { if (retry) @@ -233,7 +234,6 @@ rr_data_t forward_request(void *thread_data, rr_data_t request) { syslog(LOG_DEBUG, "%s %s %s", saddr, data[0]->method, data[0]->url); } -shortcut: /* * Modify request headers. * @@ -307,7 +307,7 @@ rr_data_t forward_request(void *thread_data, rr_data_t request) { * !!! that's why we reset data[1] below !!! * * Reply to auth request wasn't 407? Then auth is not required, - * let's jump into the next loop and forward it to client + * let's set loop = 1 so that we forward reply to client * Also just forward if proxy doesn't reply with keep-alive, * because without it, NTLM auth wouldn't work anyway. * @@ -320,14 +320,13 @@ rr_data_t forward_request(void *thread_data, rr_data_t request) { if (data[1]->code < 400) noauth = 1; loop = 1; - goto shortcut; + } else { + /* + * If we're continuing normally, we have to free possible + * auth response from proxy_authenticate() in data[1] + */ + reset_rr_data(data[1]); } - - /* - * If we're continuing normally, we have to free possible - * auth response from proxy_authenticate() in data[1] - */ - reset_rr_data(data[1]); } /*