From: Simon Ruderich Date: Mon, 29 Jul 2013 02:35:24 +0000 (+0200) Subject: Prepare HTTP_RESPONSE_FORMAT for additional headers. X-Git-Url: https://ruderich.org/simon/gitweb/?p=tlsproxy%2Ftlsproxy.git;a=commitdiff_plain;h=34d5e8a98501f972dbfeb990cf0b96fdd77f0bac Prepare HTTP_RESPONSE_FORMAT for additional headers. --- diff --git a/src/connection.c b/src/connection.c index 54e5671..08a7280 100644 --- a/src/connection.c +++ b/src/connection.c @@ -36,11 +36,11 @@ /* Format string used to send HTTP/1.0 error responses to the client. * - * %s is used 4 times, first three are the error code (no %n$s!), the last is - * the message. */ + * %s is used 5 times, first is the error code, then additional headers, next + * two are the error code (no %n$s!), the last is the message. */ #define HTTP_RESPONSE_FORMAT "HTTP/1.0 %s\r\n\ Content-Type: text/html; charset=US-ASCII\r\n\ -\r\n\ +%s\r\n\ \n\ \n\ %s\n\ @@ -548,13 +548,13 @@ static int read_http_request(FILE *client_fd, char *request, size_t length) { static void send_bad_request(FILE *client_fd) { const char error[] = "400 Bad Request"; const char msg[] = "Your browser sent an invalid request."; - fprintf(client_fd, HTTP_RESPONSE_FORMAT, error, error, error, msg); + fprintf(client_fd, HTTP_RESPONSE_FORMAT, error, "", error, error, msg); fflush(client_fd); } static void send_forwarding_failure(FILE *client_fd) { const char error[] = "503 Forwarding failure"; const char msg[] = "Failed to connect to server, check logs."; - fprintf(client_fd, HTTP_RESPONSE_FORMAT, error, error, error, msg); + fprintf(client_fd, HTTP_RESPONSE_FORMAT, error, "", error, error, msg); fflush(client_fd); } static void tls_send_invalid_cert_message(gnutls_session_t session) { @@ -566,7 +566,7 @@ static void tls_send_invalid_cert_message(gnutls_session_t session) { + 3 * sizeof(error) + sizeof(msg)]; result = snprintf(buffer, sizeof(buffer), HTTP_RESPONSE_FORMAT, - error, error, error, msg); + error, "", error, error, msg); assert(result > 0 && (size_t)result < sizeof(buffer)); gnutls_record_send(session, buffer, strlen(buffer));