diff -r e3ae779232a9 -r 24d804a2799f src/server/protocol.c --- a/src/server/protocol.c Fri Dec 30 14:06:56 2011 +0100 +++ b/src/server/protocol.c Fri Dec 30 15:19:16 2011 +0100 @@ -33,7 +33,7 @@ #include "session.h" #include "io.h" - +#include "strbuf.h" void protocol_status(Session *sn, Request *rq, int n, const char *m) { @@ -226,20 +226,20 @@ } -void add_http_status_line(iovec_buf_t *out, Request *rq) { - iovec_buf_write(out, "HTTP/1.1 ", 9); +void add_http_status_line(sbuf_t *out, pool_handle_t *pool, Request *rq) { + sbuf_write(out, "HTTP/1.1 ", 9); - char *status_code_str = pool_malloc(out->pool, 8); + char *status_code_str = pool_malloc(pool, 8); int sc_len = snprintf(status_code_str, 8, "%d ", rq->status_num); - iovec_buf_write(out, status_code_str, sc_len); + sbuf_write(out, status_code_str, sc_len); char *scmsg = pblock_findkeyval(pb_key_status, rq->srvhdrs); - iovec_buf_write(out, scmsg, strlen(scmsg)); + sbuf_write(out, scmsg, strlen(scmsg)); - iovec_buf_write(out, "\r\n", 2); + sbuf_write(out, "\r\n", 2); } -void add_http_response_header(iovec_buf_t *out, Request *rq) { +void add_http_response_header(sbuf_t *out, Request *rq) { pblock *h = rq->srvhdrs; pb_entry *p; @@ -263,10 +263,10 @@ 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); + sbuf_write(out, name, strlen(name)); + sbuf_write(out, ": ", 2); + sbuf_write(out, value, strlen(value)); + sbuf_write(out, "\r\n", 2); p = p->next; } @@ -282,22 +282,23 @@ fcntl(fd, F_SETFL, flags ^ O_NONBLOCK); /* iovec output buffer */ - iovec_buf_t *out = iovec_buf_create(sn->pool); + sbuf_t *out = sbuf_new(512); /* add the http status line to the output buffer */ - add_http_status_line(out, rq); + add_http_status_line(out, sn->pool, rq); /* add server header */ - iovec_buf_write(out, "Server: WS uap-dev\r\n", 20); + sbuf_write(out, "Server: WS uap-dev\r\n", 20); /* add header from rq->srvhdrs */ add_http_response_header(out, rq); /* response header end */ - iovec_buf_write(out, "\r\n", 2); + sbuf_write(out, "\r\n", 2); /* flush buffer to the socket */ - iovec_buf_flush(out, fd); + write(fd, out->ptr, out->length); + sbuf_free(out); rq->senthdrs = 1; }