# HG changeset patch # User Olaf Wintermann # Date 1325066256 -3600 # Node ID 3c2ed7a7a5fd4be8ea2c9ce8760116db0bcc9dd3 # Parent ce8fecc9847d035240d908a804a7909fb7d9254f request and response header now used diff -r ce8fecc9847d -r 3c2ed7a7a5fd src/server/httprequest.c --- a/src/server/httprequest.c Tue Dec 27 20:12:21 2011 +0100 +++ b/src/server/httprequest.c Wed Dec 28 10:57:36 2011 +0100 @@ -135,6 +135,20 @@ rq->rq.reqpb); // pass http header to the NSAPI request structure + int hlen = request->headers->len; + HeaderArray *ha = request->headers; + for(int i=0;i<=hlen;i++) { + if(i == hlen) { + ha = ha->next; + if(ha == NULL) { + break; + } + i = 0; + hlen = ha->len; + } + + pblock_nvinsert(ha->headers[i].name, ha->headers[i].value, rq->rq.headers); + } // Send the request to the NSAPI system diff -r ce8fecc9847d -r 3c2ed7a7a5fd src/server/pblock.h --- a/src/server/pblock.h Tue Dec 27 20:12:21 2011 +0100 +++ b/src/server/pblock.h Wed Dec 28 10:57:36 2011 +0100 @@ -341,6 +341,8 @@ } #endif +#define PARAM_KEY(pp) *(const pb_key **)(pp + 1) /* new */ + NSPR_END_EXTERN_C #define param_create INTparam_create diff -r ce8fecc9847d -r 3c2ed7a7a5fd src/server/protocol.c --- 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;ihsize;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 */ diff -r ce8fecc9847d -r 3c2ed7a7a5fd src/server/protocol.h --- a/src/server/protocol.h Tue Dec 27 20:12:21 2011 +0100 +++ b/src/server/protocol.h Wed Dec 28 10:57:36 2011 +0100 @@ -30,7 +30,7 @@ #define HTTP_H #include "nsapi.h" - +#include "io.h" #include #ifdef __cplusplus @@ -40,6 +40,9 @@ void protocol_status(Session *sn, Request *rq, int n, const char *m); const char* protocol_status_message(int code); +void add_http_status_line(iovec_buf_t *out, Request *rq); +void add_http_response_header(iovec_buf_t *out, Request *rq); + int http_start_response(Session *sn, Request *rq); #ifdef __cplusplus