Skip to content

Commit 8ba0351

Browse files
authored
Merge pull request #5 from cozis/dev
Dev
2 parents 3339360 + 8e7dac9 commit 8ba0351

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ I asked [Reddit](https://www.reddit.com/r/C_Programming/comments/1falo3b/using_m
66
# Specs
77
- Only runs on Linux
88
- HTTP/1.1 support with pipelining and keep-alive
9-
* HTTPS (TLS 1.2 using BearSSL)
9+
- HTTPS (TLS 1.2 using BearSSL)
1010
- Uses request and connection timeouts
1111
- Access log, log file rotation, hard disk usage limits
1212
- 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)

serve.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
#define LOG_DIRECTORY_SIZE_LIMIT_MB 100
7777
#endif
7878

79+
#define KEEPALIVE_MAXREQS 1000
80+
7981
#define LOG_DIRECTORY "logs"
8082

8183
#define HTTPS_KEY_FILE "key.pem"
@@ -1064,7 +1066,7 @@ bool should_keep_alive(Connection *conn)
10641066
return false;
10651067

10661068
// Don't keep alive if we served a lot of requests to this connection
1067-
if (conn->served_count > 100)
1069+
if (conn->served_count > KEEPALIVE_MAXREQS)
10681070
return false;
10691071

10701072
// Don't keep alive if the server is more than 70% full
@@ -1201,11 +1203,11 @@ bool respond_to_available_requests(Connection *conn)
12011203
// Reset the request timer
12021204
conn->start_time = now;
12031205

1204-
conn->keep_alive = false;
1206+
conn->keep_alive = true;
12051207
string keep_alive_header;
12061208
if (find_header(&request, LIT("Connection"), &keep_alive_header)) {
1207-
if (string_match_case_insensitive(trim(keep_alive_header), LIT("Keep-Alive")))
1208-
conn->keep_alive = true;
1209+
if (string_match_case_insensitive(trim(keep_alive_header), LIT("Close")))
1210+
conn->keep_alive = false;
12091211
}
12101212
// Respond
12111213
ResponseBuilder builder;
@@ -1543,6 +1545,13 @@ int main(int argc, char **argv)
15431545

15441546
init_globals();
15451547

1548+
log_format("BACKTRACE=%d\n", BACKTRACE);
1549+
log_format("EOPALLOC=%d\n", EOPALLOC);
1550+
log_format("PROFILE=%d\n", PROFILE);
1551+
log_format("ACCESS_LOG=%d\n", ACCESS_LOG);
1552+
log_format("SHOW_IO=%d\n", SHOW_IO);
1553+
log_format("SHOW_REQUESTS=%d\n", SHOW_REQUESTS);
1554+
15461555
DEBUG("Globals initialized\n");
15471556

15481557
uint64_t last_log_time = 0;

0 commit comments

Comments
 (0)