|
|
|
@ -3,6 +3,7 @@ |
|
|
|
#include <stdlib.h> /* for exit */ |
|
|
|
#include <errno.h> /* for errno */ |
|
|
|
#include <unistd.h> |
|
|
|
#include <ctype.h> |
|
|
|
#include <time.h> |
|
|
|
|
|
|
|
#include "server.h" |
|
|
|
@ -17,6 +18,7 @@ |
|
|
|
#include "http/request.h" |
|
|
|
#include "http/request/parser.h" |
|
|
|
#include "http/request/queue.h" |
|
|
|
#include "http/header.h" |
|
|
|
//* until here |
|
|
|
|
|
|
|
#undef MAX |
|
|
|
@ -79,16 +81,35 @@ serverRun(Server this) |
|
|
|
|
|
|
|
for (j=0; j<queue->nrequests; j++) { |
|
|
|
HttpRequest request = queue->requests[j]; |
|
|
|
char * header; |
|
|
|
char * header_ptr; |
|
|
|
|
|
|
|
//if (NULL != request->body) { |
|
|
|
// puts("==REQUEST BODY=="); |
|
|
|
// puts(request->body); |
|
|
|
//} |
|
|
|
|
|
|
|
header = httpHeaderGet( |
|
|
|
request->header, |
|
|
|
request->nheader, |
|
|
|
"connection"); |
|
|
|
|
|
|
|
if (NULL != header) { |
|
|
|
for (header_ptr = header; |
|
|
|
0 != *header_ptr; |
|
|
|
header_ptr++) { |
|
|
|
*header_ptr = tolower(*header_ptr); |
|
|
|
} |
|
|
|
|
|
|
|
if (0 == strcmp(header, "keep-alive")) { |
|
|
|
(this->conns)[fd].keep_alive = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* @TODO: for now simply remove request and send not found. |
|
|
|
* Make this sane. |
|
|
|
*/ |
|
|
|
|
|
|
|
delete(&request); |
|
|
|
|
|
|
|
/** |
|
|
|
@ -99,7 +120,6 @@ serverRun(Server this) |
|
|
|
char timestr[200]; |
|
|
|
|
|
|
|
#define RESP_HEAD "HTTP/1.1 404 Not Found\r\n" \ |
|
|
|
"Connection: Keep-Alive\r\n" \ |
|
|
|
"Content-Type: text/html\r\n" \ |
|
|
|
"Content-Length: %lu\r\n" \ |
|
|
|
"Date: %s\r\n" \ |
|
|
|
@ -121,7 +141,12 @@ serverRun(Server this) |
|
|
|
* @TODO: just to send an answer and be able to make some |
|
|
|
* apache benchs i do it here...this definetly MUST BE moved |
|
|
|
*/ |
|
|
|
sprintf((this->conns)[fd].wbuf, RESP_HEAD "\r\n" RESP_DATA, sizeof(RESP_DATA) - 1, timestr); |
|
|
|
if ((this->conns)[fd].keep_alive) { |
|
|
|
sprintf((this->conns)[fd].wbuf, RESP_HEAD "Connection: Keep-Alive\r\n\r\n" RESP_DATA, sizeof(RESP_DATA) - 1, timestr); |
|
|
|
} |
|
|
|
else { |
|
|
|
sprintf((this->conns)[fd].wbuf, RESP_HEAD "Connection: close\r\n\r\n" RESP_DATA, sizeof(RESP_DATA) - 1, timestr); |
|
|
|
} |
|
|
|
(this->fds)[i].events |= POLLOUT; |
|
|
|
} |
|
|
|
|
|
|
|
@ -148,9 +173,13 @@ serverRun(Server this) |
|
|
|
"write error, closing connection"); |
|
|
|
} |
|
|
|
|
|
|
|
//serverCloseConn(this, i); |
|
|
|
if ((this->conns)[fd].keep_alive) { |
|
|
|
(this->fds)[i].events &= ~POLLOUT; |
|
|
|
} |
|
|
|
else { |
|
|
|
serverCloseConn(this, i); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
memmove((this->conns)[fd].wbuf, |
|
|
|
(this->conns)[fd].wbuf + size, |
|
|
|
|