Skip to content

Commit

Permalink
remove confusing goto and replace with if/else statement
Browse files Browse the repository at this point in the history
  • Loading branch information
fralken committed Mar 16, 2024
1 parent 59cdefe commit 4cd3526
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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]);
}

/*
Expand Down

0 comments on commit 4cd3526

Please sign in to comment.