src/server/protocol.c

changeset 7
3c2ed7a7a5fd
parent 4
998844b5ed25
child 8
f4d56bf9de40
equal deleted inserted replaced
6:ce8fecc9847d 7:3c2ed7a7a5fd
237 iovec_buf_write(out, scmsg, strlen(scmsg)); 237 iovec_buf_write(out, scmsg, strlen(scmsg));
238 238
239 iovec_buf_write(out, "\r\n", 2); 239 iovec_buf_write(out, "\r\n", 2);
240 } 240 }
241 241
242 void add_http_response_header(iovec_buf_t *out, Request *rq) {
243 pblock *h = rq->srvhdrs;
244 pb_entry *p;
245
246 for(int i=0;i<h->hsize;i++) {
247 p = h->ht[i];
248 while(p != NULL) {
249 /* from http.cpp */
250 const pb_key *key = PARAM_KEY(p->param);
251 if (key == pb_key_status || key == pb_key_server || key == pb_key_date) {
252 /* Skip internal Status:, Server:, and Date: information */
253 p = p->next;
254 continue;
255 }
256 /* end http.cpp */
257
258 char *name = p->param->name;
259 char *value = p->param->value;
260
261 /* make first char of name uppercase */
262 if(name[0] > 90) {
263 name[0] -= 32;
264 }
265
266 iovec_buf_write(out, name, strlen(name));
267 iovec_buf_write(out, ": ", 2);
268 iovec_buf_write(out, value, strlen(value));
269 iovec_buf_write(out, "\r\n", 2);
270 printf(".\n");
271
272 p = p->next;
273 }
274 }
275 }
276
242 int http_start_response(Session *sn, Request *rq) { 277 int http_start_response(Session *sn, Request *rq) {
243 int fd = ((SystemIOStream*)sn->csd)->fd; 278 int fd = ((SystemIOStream*)sn->csd)->fd;
244 279
245 /* set socket blocking */ 280 /* set socket blocking */
246 int flags; 281 int flags;
254 add_http_status_line(out, rq); 289 add_http_status_line(out, rq);
255 290
256 /* add server header */ 291 /* add server header */
257 iovec_buf_write(out, "Server: WS uap-dev\r\n", 20); 292 iovec_buf_write(out, "Server: WS uap-dev\r\n", 20);
258 293
259 // TODO: add header from rq->srvhdrs 294 /* add header from rq->srvhdrs */
295 add_http_response_header(out, rq);
296
297 /* response header end */
260 iovec_buf_write(out, "\r\n", 2); 298 iovec_buf_write(out, "\r\n", 2);
261 299
262 /* flush buffer to the socket */ 300 /* flush buffer to the socket */
263 iovec_buf_flush(out, fd); 301 iovec_buf_flush(out, fd);
264 302

mercurial