Added error checking with sending responses
This commit is contained in:
@@ -43,3 +43,11 @@
|
|||||||
[2022-01-31T03:25:44Z] swebs started
|
[2022-01-31T03:25:44Z] swebs started
|
||||||
[2022-01-31T03:25:48Z] Couldn't find swebs user
|
[2022-01-31T03:25:48Z] Couldn't find swebs user
|
||||||
[2022-01-31T03:25:48Z] swebs started
|
[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
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
<h1>You found the easter egg!</h1>
|
<h1>You found the easter egg!</h1>
|
||||||
|
<img src="/egg.png">
|
||||||
|
<p>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.</p>
|
||||||
|
|||||||
BIN
example/site/egg.png
Normal file
BIN
example/site/egg.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.2 KiB |
@@ -10,5 +10,6 @@ read /blog/.* site/blog/
|
|||||||
#/blog/2021-1-25.html turns into site/blog//blog/2021-1-25.html
|
#/blog/2021-1-25.html turns into site/blog//blog/2021-1-25.html
|
||||||
set host 127.0.0.1:8000
|
set host 127.0.0.1:8000
|
||||||
read / site/easteregg.html
|
read / site/easteregg.html
|
||||||
|
read /egg.png site/egg.png
|
||||||
set host .*
|
set host .*
|
||||||
read /alldomains site/alldomains.html
|
read /alldomains site/alldomains.html
|
||||||
|
|||||||
@@ -200,17 +200,19 @@ static int processChar(Connection *conn, char c, Sitefile *site) {
|
|||||||
conn->receivedBody >= conn->bodylen)
|
conn->receivedBody >= conn->bodylen)
|
||||||
getResponse(conn, site);
|
getResponse(conn, site);
|
||||||
if (conn->progress == SEND_RESPONSE) {
|
if (conn->progress == SEND_RESPONSE) {
|
||||||
for (;;) {
|
while (conn->len > 0) {
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
size_t readLen = read(conn->fd, buffer, sizeof(buffer));
|
size_t readLen = read(conn->fd, buffer, sizeof(buffer));
|
||||||
if (readLen == 0)
|
|
||||||
break;
|
|
||||||
if (readLen < 0)
|
if (readLen < 0)
|
||||||
return 1;
|
return 1;
|
||||||
size_t writeLen = sendStream(conn->stream,
|
while (readLen > 0) {
|
||||||
buffer, readLen);
|
size_t writeLen = sendStream(conn->stream,
|
||||||
if (writeLen < readLen)
|
buffer, readLen);
|
||||||
return 1;
|
if (writeLen < 0)
|
||||||
|
return 1;
|
||||||
|
readLen -= writeLen;
|
||||||
|
}
|
||||||
|
conn->len -= readLen;
|
||||||
}
|
}
|
||||||
resetConnection(conn);
|
resetConnection(conn);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ typedef struct Connection {
|
|||||||
size_t receivedBody;
|
size_t receivedBody;
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
//the fd of the response
|
size_t len;
|
||||||
|
//the fd and length of the response left to send
|
||||||
|
|
||||||
char *currLine;
|
char *currLine;
|
||||||
//persistent
|
//persistent
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ static int readResponse(Connection *conn, char *path) {
|
|||||||
goto error;
|
goto error;
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
sendHeader(conn, CODE_200, len);
|
sendHeader(conn, CODE_200, len);
|
||||||
|
conn->len = len;
|
||||||
return fd;
|
return fd;
|
||||||
error:
|
error:
|
||||||
sendErrorResponse(conn, ERROR_500);
|
sendErrorResponse(conn, ERROR_500);
|
||||||
|
|||||||
Reference in New Issue
Block a user