Commit 3d735c7fc7ce1a952b70c7c734875bd92015085d
1 parent
6c888a8c
made a first cruel handling for keep-alive and non keep-alive requests. @TODO: this MUST BE cleaned
Showing
4 changed files
with
45 additions
and
6 deletions
1 | +2012-02-10 09:52:27 +0100 Georg Hopp | |
2 | + | |
3 | + * made a first cruel handling for keep-alive and non keep-alive requests. @TODO: this MUST BE cleaned (HEAD, master) | |
4 | + | |
5 | +2012-02-10 08:14:31 +0100 Georg Hopp | |
6 | + | |
7 | + * now only use keep-alive.... (origin/master, origin/HEAD) | |
8 | + | |
1 | 9 | 2012-02-10 06:36:43 +0100 Georg Hopp |
2 | 10 | |
3 | - * moved request_parser.h and request_queue.h in separeate request subfolder (HEAD, master) | |
11 | + * moved request_parser.h and request_queue.h in separeate request subfolder | |
4 | 12 | |
5 | 13 | 2012-02-10 06:22:39 +0100 Georg Hopp |
6 | 14 | |
... | ... | @@ -20,7 +28,7 @@ |
20 | 28 | |
21 | 29 | 2012-02-09 22:34:32 +0100 Georg Hopp |
22 | 30 | |
23 | - * start split of request parser (origin/master, origin/HEAD) | |
31 | + * start split of request parser | |
24 | 32 | |
25 | 33 | 2012-02-09 11:44:17 +0100 Georg Hopp |
26 | 34 | ... | ... |
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | #include <stdlib.h> /* for exit */ |
4 | 4 | #include <errno.h> /* for errno */ |
5 | 5 | #include <unistd.h> |
6 | +#include <ctype.h> | |
6 | 7 | #include <time.h> |
7 | 8 | |
8 | 9 | #include "server.h" |
... | ... | @@ -17,6 +18,7 @@ |
17 | 18 | #include "http/request.h" |
18 | 19 | #include "http/request/parser.h" |
19 | 20 | #include "http/request/queue.h" |
21 | +#include "http/header.h" | |
20 | 22 | //* until here |
21 | 23 | |
22 | 24 | #undef MAX |
... | ... | @@ -79,16 +81,35 @@ serverRun(Server this) |
79 | 81 | |
80 | 82 | for (j=0; j<queue->nrequests; j++) { |
81 | 83 | HttpRequest request = queue->requests[j]; |
84 | + char * header; | |
85 | + char * header_ptr; | |
82 | 86 | |
83 | 87 | //if (NULL != request->body) { |
84 | 88 | // puts("==REQUEST BODY=="); |
85 | 89 | // puts(request->body); |
86 | 90 | //} |
87 | 91 | |
92 | + header = httpHeaderGet( | |
93 | + request->header, | |
94 | + request->nheader, | |
95 | + "connection"); | |
96 | + | |
97 | + if (NULL != header) { | |
98 | + for (header_ptr = header; | |
99 | + 0 != *header_ptr; | |
100 | + header_ptr++) { | |
101 | + *header_ptr = tolower(*header_ptr); | |
102 | + } | |
103 | + | |
104 | + if (0 == strcmp(header, "keep-alive")) { | |
105 | + (this->conns)[fd].keep_alive = 1; | |
106 | + } | |
107 | + } | |
88 | 108 | /** |
89 | 109 | * @TODO: for now simply remove request and send not found. |
90 | 110 | * Make this sane. |
91 | 111 | */ |
112 | + | |
92 | 113 | delete(&request); |
93 | 114 | |
94 | 115 | /** |
... | ... | @@ -99,7 +120,6 @@ serverRun(Server this) |
99 | 120 | char timestr[200]; |
100 | 121 | |
101 | 122 | #define RESP_HEAD "HTTP/1.1 404 Not Found\r\n" \ |
102 | - "Connection: Keep-Alive\r\n" \ | |
103 | 123 | "Content-Type: text/html\r\n" \ |
104 | 124 | "Content-Length: %lu\r\n" \ |
105 | 125 | "Date: %s\r\n" \ |
... | ... | @@ -121,7 +141,12 @@ serverRun(Server this) |
121 | 141 | * @TODO: just to send an answer and be able to make some |
122 | 142 | * apache benchs i do it here...this definetly MUST BE moved |
123 | 143 | */ |
124 | - sprintf((this->conns)[fd].wbuf, RESP_HEAD "\r\n" RESP_DATA, sizeof(RESP_DATA) - 1, timestr); | |
144 | + if ((this->conns)[fd].keep_alive) { | |
145 | + sprintf((this->conns)[fd].wbuf, RESP_HEAD "Connection: Keep-Alive\r\n\r\n" RESP_DATA, sizeof(RESP_DATA) - 1, timestr); | |
146 | + } | |
147 | + else { | |
148 | + sprintf((this->conns)[fd].wbuf, RESP_HEAD "Connection: close\r\n\r\n" RESP_DATA, sizeof(RESP_DATA) - 1, timestr); | |
149 | + } | |
125 | 150 | (this->fds)[i].events |= POLLOUT; |
126 | 151 | } |
127 | 152 | |
... | ... | @@ -148,8 +173,12 @@ serverRun(Server this) |
148 | 173 | "write error, closing connection"); |
149 | 174 | } |
150 | 175 | |
151 | - //serverCloseConn(this, i); | |
152 | - (this->fds)[i].events &= ~POLLOUT; | |
176 | + if ((this->conns)[fd].keep_alive) { | |
177 | + (this->fds)[i].events &= ~POLLOUT; | |
178 | + } | |
179 | + else { | |
180 | + serverCloseConn(this, i); | |
181 | + } | |
153 | 182 | } |
154 | 183 | else { |
155 | 184 | memmove((this->conns)[fd].wbuf, | ... | ... |
Please
register
or
login
to post a comment