reqs: simply process_request a bit: create common fail exit point
Michael
This commit is contained in:
parent
9c0c3d5ced
commit
0bfc0e90c1
70
src/reqs.c
70
src/reqs.c
@ -313,10 +313,7 @@ static struct request_s *process_request (struct conn_s *connptr,
|
|||||||
request->protocol = (char *) safemalloc (request_len);
|
request->protocol = (char *) safemalloc (request_len);
|
||||||
|
|
||||||
if (!request->method || !url || !request->protocol) {
|
if (!request->method || !url || !request->protocol) {
|
||||||
safefree (url);
|
goto fail;
|
||||||
free_request_struct (request);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sscanf (connptr->request_line, "%[^ ] %[^ ] %[^ ]",
|
ret = sscanf (connptr->request_line, "%[^ ] %[^ ] %[^ ]",
|
||||||
@ -350,11 +347,7 @@ BAD_REQUEST_ERROR:
|
|||||||
indicate_http_error (connptr, 400, "Bad Request",
|
indicate_http_error (connptr, 400, "Bad Request",
|
||||||
"detail", "Request has an invalid format",
|
"detail", "Request has an invalid format",
|
||||||
"url", url, NULL);
|
"url", url, NULL);
|
||||||
|
goto fail;
|
||||||
safefree (url);
|
|
||||||
free_request_struct (request);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
@ -364,11 +357,7 @@ BAD_REQUEST_ERROR:
|
|||||||
indicate_http_error (connptr, 400, "Bad Request",
|
indicate_http_error (connptr, 400, "Bad Request",
|
||||||
"detail", "Request has an empty URL",
|
"detail", "Request has an empty URL",
|
||||||
"url", url, NULL);
|
"url", url, NULL);
|
||||||
|
goto fail;
|
||||||
safefree (url);
|
|
||||||
free_request_struct (request);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
#ifdef REVERSE_SUPPORT
|
#ifdef REVERSE_SUPPORT
|
||||||
if (config.reversepath_list != NULL) {
|
if (config.reversepath_list != NULL) {
|
||||||
@ -381,14 +370,13 @@ BAD_REQUEST_ERROR:
|
|||||||
char *reverse_url;
|
char *reverse_url;
|
||||||
|
|
||||||
reverse_url = reverse_rewrite_url (connptr, hashofheaders, url);
|
reverse_url = reverse_rewrite_url (connptr, hashofheaders, url);
|
||||||
safefree (url);
|
|
||||||
|
|
||||||
if (!reverse_url) {
|
if (!reverse_url) {
|
||||||
free_request_struct (request);
|
goto fail;
|
||||||
return NULL;
|
|
||||||
} else {
|
|
||||||
url = reverse_url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
safefree (url);
|
||||||
|
url = reverse_url;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -401,22 +389,14 @@ BAD_REQUEST_ERROR:
|
|||||||
indicate_http_error (connptr, 400, "Bad Request",
|
indicate_http_error (connptr, 400, "Bad Request",
|
||||||
"detail", "Could not parse URL",
|
"detail", "Could not parse URL",
|
||||||
"url", url, NULL);
|
"url", url, NULL);
|
||||||
|
goto fail;
|
||||||
safefree (url);
|
|
||||||
free_request_struct (request);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
} else if (strcmp (request->method, "CONNECT") == 0) {
|
} else if (strcmp (request->method, "CONNECT") == 0) {
|
||||||
if (extract_ssl_url (url, request) < 0) {
|
if (extract_ssl_url (url, request) < 0) {
|
||||||
indicate_http_error (connptr, 400, "Bad Request",
|
indicate_http_error (connptr, 400, "Bad Request",
|
||||||
"detail", "Could not parse URL",
|
"detail", "Could not parse URL",
|
||||||
"url", url, NULL);
|
"url", url, NULL);
|
||||||
|
goto fail;
|
||||||
safefree (url);
|
|
||||||
free_request_struct (request);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify that the port in the CONNECT method is allowed */
|
/* Verify that the port in the CONNECT method is allowed */
|
||||||
@ -431,11 +411,7 @@ BAD_REQUEST_ERROR:
|
|||||||
log_message (LOG_INFO,
|
log_message (LOG_INFO,
|
||||||
"Refused CONNECT method on port %d",
|
"Refused CONNECT method on port %d",
|
||||||
request->port);
|
request->port);
|
||||||
|
goto fail;
|
||||||
safefree (url);
|
|
||||||
free_request_struct (request);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connptr->connect_method = TRUE;
|
connptr->connect_method = TRUE;
|
||||||
@ -443,9 +419,7 @@ BAD_REQUEST_ERROR:
|
|||||||
#ifdef TRANSPARENT_PROXY
|
#ifdef TRANSPARENT_PROXY
|
||||||
if (!do_transparent_proxy
|
if (!do_transparent_proxy
|
||||||
(connptr, hashofheaders, request, &config, url)) {
|
(connptr, hashofheaders, request, &config, url)) {
|
||||||
safefree (url);
|
goto fail;
|
||||||
free_request_struct (request);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
indicate_http_error (connptr, 501, "Not Implemented",
|
indicate_http_error (connptr, 501, "Not Implemented",
|
||||||
@ -454,9 +428,7 @@ BAD_REQUEST_ERROR:
|
|||||||
"url", url, NULL);
|
"url", url, NULL);
|
||||||
log_message (LOG_INFO, "Unknown method (%s) or protocol (%s)",
|
log_message (LOG_INFO, "Unknown method (%s) or protocol (%s)",
|
||||||
request->method, url);
|
request->method, url);
|
||||||
safefree (url);
|
goto fail;
|
||||||
free_request_struct (request);
|
|
||||||
return NULL;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,16 +458,11 @@ BAD_REQUEST_ERROR:
|
|||||||
"detail",
|
"detail",
|
||||||
"The request you made has been filtered",
|
"The request you made has been filtered",
|
||||||
"url", url, NULL);
|
"url", url, NULL);
|
||||||
|
goto fail;
|
||||||
safefree (url);
|
|
||||||
free_request_struct (request);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
safefree (url);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check to see if they're requesting the stat host
|
* Check to see if they're requesting the stat host
|
||||||
@ -503,12 +470,17 @@ BAD_REQUEST_ERROR:
|
|||||||
if (config.stathost && strcmp (config.stathost, request->host) == 0) {
|
if (config.stathost && strcmp (config.stathost, request->host) == 0) {
|
||||||
log_message (LOG_NOTICE, "Request for the stathost.");
|
log_message (LOG_NOTICE, "Request for the stathost.");
|
||||||
connptr->show_stats = TRUE;
|
connptr->show_stats = TRUE;
|
||||||
|
goto fail;
|
||||||
free_request_struct (request);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
safefree (url);
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
safefree (url);
|
||||||
|
free_request_struct (request);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user