src/server/protocol.c

changeset 7
3c2ed7a7a5fd
parent 4
998844b5ed25
child 8
f4d56bf9de40
--- a/src/server/protocol.c	Tue Dec 27 20:12:21 2011 +0100
+++ b/src/server/protocol.c	Wed Dec 28 10:57:36 2011 +0100
@@ -239,6 +239,41 @@
     iovec_buf_write(out, "\r\n", 2);
 }
 
+void add_http_response_header(iovec_buf_t *out, Request *rq) {
+    pblock   *h = rq->srvhdrs;
+    pb_entry *p;
+
+    for(int i=0;i<h->hsize;i++) {
+        p = h->ht[i];
+        while(p != NULL) {
+            /* from http.cpp */
+            const pb_key *key = PARAM_KEY(p->param);
+            if (key == pb_key_status || key == pb_key_server || key == pb_key_date) {
+                /* Skip internal Status:, Server:, and Date: information */
+                p = p->next;
+                continue;
+            }
+            /* end http.cpp */
+
+            char *name  = p->param->name;
+            char *value = p->param->value;
+
+            /* make first char of name uppercase */
+            if(name[0] > 90) {
+                name[0] -= 32;
+            }
+
+            iovec_buf_write(out, name, strlen(name));
+            iovec_buf_write(out, ": ", 2);
+            iovec_buf_write(out, value, strlen(value));
+            iovec_buf_write(out, "\r\n", 2);
+            printf(".\n");
+
+            p = p->next;
+        }
+    }
+}
+
 int http_start_response(Session *sn, Request *rq) {
     int fd = ((SystemIOStream*)sn->csd)->fd;
 
@@ -256,7 +291,10 @@
     /* add server header */
     iovec_buf_write(out, "Server: WS uap-dev\r\n", 20);
 
-    // TODO: add header from rq->srvhdrs
+    /* add header from rq->srvhdrs */
+    add_http_response_header(out, rq);
+
+    /* response header end */
     iovec_buf_write(out, "\r\n", 2);
 
     /* flush buffer to the socket */

mercurial