diff --git a/example/logs b/example/logs index 7e2e489..845393b 100644 --- a/example/logs +++ b/example/logs @@ -43,3 +43,11 @@ [2022-01-31T03:25:44Z] swebs started [2022-01-31T03:25:48Z] Couldn't find swebs user [2022-01-31T03:25:48Z] swebs started +[2022-01-31T03:35:13Z] Couldn't find swebs user +[2022-01-31T03:35:13Z] swebs started +[2022-01-31T03:35:35Z] Couldn't find swebs user +[2022-01-31T03:35:35Z] swebs started +[2022-01-31T03:36:20Z] Couldn't find swebs user +[2022-01-31T03:36:20Z] swebs started +[2022-01-31T03:37:29Z] Couldn't find swebs user +[2022-01-31T03:37:29Z] swebs started diff --git a/example/site/easteregg.html b/example/site/easteregg.html index 972bba0..2266a5a 100644 --- a/example/site/easteregg.html +++ b/example/site/easteregg.html @@ -1 +1,3 @@
+There should be a picture of an egg here, but it doesn't show. go to 127.0.0.1:8000/egg.png to see it.
diff --git a/example/site/egg.png b/example/site/egg.png new file mode 100644 index 0000000..4b0fc4d Binary files /dev/null and b/example/site/egg.png differ diff --git a/example/sitefile b/example/sitefile index 9bdbd0e..34e21ff 100644 --- a/example/sitefile +++ b/example/sitefile @@ -10,5 +10,6 @@ read /blog/.* site/blog/ #/blog/2021-1-25.html turns into site/blog//blog/2021-1-25.html set host 127.0.0.1:8000 read / site/easteregg.html +read /egg.png site/egg.png set host .* read /alldomains site/alldomains.html diff --git a/src/connections.c b/src/connections.c index 29ab843..87d7f77 100644 --- a/src/connections.c +++ b/src/connections.c @@ -200,17 +200,19 @@ static int processChar(Connection *conn, char c, Sitefile *site) { conn->receivedBody >= conn->bodylen) getResponse(conn, site); if (conn->progress == SEND_RESPONSE) { - for (;;) { + while (conn->len > 0) { char buffer[1024]; size_t readLen = read(conn->fd, buffer, sizeof(buffer)); - if (readLen == 0) - break; if (readLen < 0) return 1; - size_t writeLen = sendStream(conn->stream, - buffer, readLen); - if (writeLen < readLen) - return 1; + while (readLen > 0) { + size_t writeLen = sendStream(conn->stream, + buffer, readLen); + if (writeLen < 0) + return 1; + readLen -= writeLen; + } + conn->len -= readLen; } resetConnection(conn); } diff --git a/src/include/connections.h b/src/include/connections.h index 1d445d5..c91e439 100644 --- a/src/include/connections.h +++ b/src/include/connections.h @@ -55,7 +55,8 @@ typedef struct Connection { size_t receivedBody; int fd; - //the fd of the response + size_t len; + //the fd and length of the response left to send char *currLine; //persistent diff --git a/src/responses.c b/src/responses.c index 7f9bfa2..b11c91a 100644 --- a/src/responses.c +++ b/src/responses.c @@ -95,6 +95,7 @@ static int readResponse(Connection *conn, char *path) { goto error; lseek(fd, 0, SEEK_SET); sendHeader(conn, CODE_200, len); + conn->len = len; return fd; error: sendErrorResponse(conn, ERROR_500);