diff --git a/README.md b/README.md index aa81afc..654d63a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a minimal web server designed to serve my blog. I'm writing it to be rob # Specs - Only runs on Linux - HTTP/1.1 support with pipelining and keep-alive -* HTTPS (TLS 1.2 using BearSSL) +- HTTPS (TLS 1.2 using BearSSL) - Uses request and connection timeouts - Access log, log file rotation, hard disk usage limits - No `Transfer-Encoding: Chunked` (when receiving a chunked request the server responds with `411 Length Required`, prompting the client to try again with the `Content-Length` header) diff --git a/serve.c b/serve.c index e37992c..564cc7e 100644 --- a/serve.c +++ b/serve.c @@ -76,6 +76,8 @@ #define LOG_DIRECTORY_SIZE_LIMIT_MB 100 #endif +#define KEEPALIVE_MAXREQS 1000 + #define LOG_DIRECTORY "logs" #define HTTPS_KEY_FILE "key.pem" @@ -1064,7 +1066,7 @@ bool should_keep_alive(Connection *conn) return false; // Don't keep alive if we served a lot of requests to this connection - if (conn->served_count > 100) + if (conn->served_count > KEEPALIVE_MAXREQS) return false; // Don't keep alive if the server is more than 70% full @@ -1201,11 +1203,11 @@ bool respond_to_available_requests(Connection *conn) // Reset the request timer conn->start_time = now; - conn->keep_alive = false; + conn->keep_alive = true; string keep_alive_header; if (find_header(&request, LIT("Connection"), &keep_alive_header)) { - if (string_match_case_insensitive(trim(keep_alive_header), LIT("Keep-Alive"))) - conn->keep_alive = true; + if (string_match_case_insensitive(trim(keep_alive_header), LIT("Close"))) + conn->keep_alive = false; } // Respond ResponseBuilder builder; @@ -1543,6 +1545,13 @@ int main(int argc, char **argv) init_globals(); + log_format("BACKTRACE=%d\n", BACKTRACE); + log_format("EOPALLOC=%d\n", EOPALLOC); + log_format("PROFILE=%d\n", PROFILE); + log_format("ACCESS_LOG=%d\n", ACCESS_LOG); + log_format("SHOW_IO=%d\n", SHOW_IO); + log_format("SHOW_REQUESTS=%d\n", SHOW_REQUESTS); + DEBUG("Globals initialized\n"); uint64_t last_log_time = 0;