Wed, 28 Dec 2011 10:57:36 +0100
request and response header now used
--- 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
--- 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
--- 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 */
--- 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 <sys/uio.h> #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