- gnutls_record_send(session, "HTTP/1.0 500 Internal Server Error\r\n", 36);
- gnutls_record_send(session, "\r\n", 2);
+#define RESPONSE_ERROR "500 Internal Server Error"
+#define RESPONSE_MSG "Server certificate validation failed, check logs."
+
+ char buffer[sizeof(HTTP_RESPONSE_FORMAT) - 1 /* '\0' */
+ - 4 * 2 /* four %s */
+ + (sizeof(RESPONSE_ERROR) - 1 /* '\0' */) * 3
+ + sizeof(RESPONSE_MSG) - 1 /* '\0' */
+ + 1 /* '\0' */];
+
+ snprintf(buffer, sizeof(buffer),
+ HTTP_RESPONSE_FORMAT,
+ RESPONSE_ERROR, RESPONSE_ERROR, RESPONSE_ERROR, RESPONSE_MSG);
+
+ gnutls_record_send(session, buffer, sizeof(buffer) - 1);
+ /* don't send trailing '\0' */
+#undef RESPONSE_ERROR
+#undef RESPONSE_MSG