summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/html-error.c33
-rw-r--r--src/html-error.h2
-rw-r--r--src/stats.c2
3 files changed, 20 insertions, 17 deletions
diff --git a/src/html-error.c b/src/html-error.c
index 071d415..b6dd29d 100644
--- a/src/html-error.c
+++ b/src/html-error.c
@@ -133,7 +133,9 @@ send_html_file (FILE *infile, struct conn_s *connptr)
return 1;
}
-int send_http_headers (struct conn_s *connptr, int code, const char *message)
+int send_http_headers (
+ struct conn_s *connptr, int code,
+ const char *message, const char *extra)
{
const char headers[] =
"HTTP/1.0 %d %s\r\n"
@@ -142,21 +144,9 @@ int send_http_headers (struct conn_s *connptr, int code, const char *message)
"%s"
"Connection: close\r\n" "\r\n";
- const char p_auth_str[] =
- "Proxy-Authenticate: Basic realm=\""
- PACKAGE_NAME "\"\r\n";
-
- const char w_auth_str[] =
- "WWW-Authenticate: Basic realm=\""
- PACKAGE_NAME "\"\r\n";
-
- /* according to rfc7235, the 407 error must be accompanied by
- a Proxy-Authenticate header field. */
- const char *add = code == 407 ? p_auth_str : (code == 401 ? w_auth_str : "");
-
return (write_message (connptr->client_fd, headers,
code, message, PACKAGE, VERSION,
- add));
+ extra));
}
/*
@@ -180,8 +170,21 @@ int send_http_error_message (struct conn_s *connptr)
"<p><em>Generated by %s version %s.</em></p>\n" "</body>\n"
"</html>\n";
+ const char p_auth_str[] =
+ "Proxy-Authenticate: Basic realm=\""
+ PACKAGE_NAME "\"\r\n";
+
+ const char w_auth_str[] =
+ "WWW-Authenticate: Basic realm=\""
+ PACKAGE_NAME "\"\r\n";
+
+ /* according to rfc7235, the 407 error must be accompanied by
+ a Proxy-Authenticate header field. */
+ const char *add = connptr->error_number == 407 ? p_auth_str :
+ (connptr->error_number == 401 ? w_auth_str : "");
+
send_http_headers (connptr, connptr->error_number,
- connptr->error_string);
+ connptr->error_string, add);
error_file = get_html_file (connptr->error_number);
if (!(infile = fopen (error_file, "r"))) {
diff --git a/src/html-error.h b/src/html-error.h
index c133cef..bc9b7ce 100644
--- a/src/html-error.h
+++ b/src/html-error.h
@@ -33,7 +33,7 @@ extern int add_error_variable (struct conn_s *connptr, const char *key,
const char *val);
extern int send_html_file (FILE * infile, struct conn_s *connptr);
extern int send_http_headers (struct conn_s *connptr, int code,
- const char *message);
+ const char *message, const char *extra);
extern int add_standard_vars (struct conn_s *connptr);
#endif /* !TINYPROXY_HTML_ERROR_H */
diff --git a/src/stats.c b/src/stats.c
index dfe054c..1228aa3 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -122,7 +122,7 @@ err_minus_one:
add_error_variable (connptr, "deniedconns", denied);
add_error_variable (connptr, "refusedconns", refused);
add_standard_vars (connptr);
- send_http_headers (connptr, 200, "Statistic requested");
+ send_http_headers (connptr, 200, "Statistic requested", "");
send_html_file (statfile, connptr);
fclose (statfile);
pthread_mutex_unlock(&stats_file_lock);