From f6641aeca1f4f4345c807e9cdea7aab2956f4935 Mon Sep 17 00:00:00 2001 From: "roberto@quantal64" Date: Thu, 9 Aug 2012 11:41:51 +0200 Subject: [PATCH] honour --add-header in php,rack and psgi plugins --- plugins/php/php_plugin.c | 12 ++++++++++++ plugins/psgi/psgi_response.c | 27 +++++++++++++++++++++++---- plugins/rack/rack_plugin.c | 13 +++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/plugins/php/php_plugin.c b/plugins/php/php_plugin.c index cd5d028a..d1694140 100644 --- a/plugins/php/php_plugin.c +++ b/plugins/php/php_plugin.c @@ -188,6 +188,18 @@ static int sapi_uwsgi_send_headers(sapi_headers_struct *sapi_headers) h = zend_llist_get_next_ex(&sapi_headers->headers, &pos); } + struct uwsgi_string_list *ah = uwsgi.additional_headers; + while(ah) { + iov[0].iov_base = ah->value; + iov[0].iov_len = ah->len; + iov[1].iov_base = "\r\n"; + iov[1].iov_len = 2; + wsgi_req->headers_size += wsgi_req->socket->proto_writev_header(wsgi_req, iov, 2); + wsgi_req->header_cnt++; + ah = ah->next; + } + + wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, "\r\n", 2); return SAPI_HEADER_SENT_SUCCESSFULLY; diff --git a/plugins/psgi/psgi_response.c b/plugins/psgi/psgi_response.c index 462ee0ca..47f9c563 100644 --- a/plugins/psgi/psgi_response.c +++ b/plugins/psgi/psgi_response.c @@ -104,7 +104,10 @@ int psgi_response(struct wsgi_request *wsgi_req, AV *response) { // put them in hvec for(i=0; i<=av_len(headers); i++) { - + if (wsgi_req->header_cnt+1 > uwsgi.max_vars) { + uwsgi_log("no more space in iovec. consider increasing max-vars...\n"); + break; + } vi = (i*2)+base; hitem = av_fetch(headers,i,0); chitem = SvPV(*hitem, hlen); @@ -123,10 +126,26 @@ int psgi_response(struct wsgi_request *wsgi_req, AV *response) { i++; } - vi = (i*2)+base; - wsgi_req->hvec[vi].iov_base = "\r\n"; wsgi_req->hvec[vi].iov_len = 2; + int j = (i*2)+base; + struct uwsgi_string_list *ah = uwsgi.additional_headers; + while(ah) { + if (wsgi_req->header_cnt+1 > uwsgi.max_vars) { + uwsgi_log("no more space in iovec. consider increasing max-vars...\n"); + break; + } + wsgi_req->header_cnt++; + wsgi_req->hvec[j].iov_base = ah->value; + wsgi_req->hvec[j].iov_len = ah->len; + j++; + wsgi_req->hvec[j].iov_base = "\r\n"; + wsgi_req->hvec[j].iov_len = 2; + j++; + ah = ah->next; + } - wsgi_req->headers_size += wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, vi+1); + wsgi_req->hvec[j].iov_base = "\r\n"; wsgi_req->hvec[j].iov_len = 2; + + wsgi_req->headers_size += wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, j+1); hitem = av_fetch(response, 2, 0); diff --git a/plugins/rack/rack_plugin.c b/plugins/rack/rack_plugin.c index 875cfc8d..bfb9b5a4 100644 --- a/plugins/rack/rack_plugin.c +++ b/plugins/rack/rack_plugin.c @@ -810,6 +810,19 @@ int uwsgi_rack_request(struct wsgi_request *wsgi_req) { } } + struct uwsgi_string_list *ah = uwsgi.additional_headers; + struct iovec iov[2]; + while(ah) { + iov[0].iov_base = ah->value; + iov[0].iov_len = ah->len; + iov[1].iov_base = "\r\n"; + iov[1].iov_len = 2; + wsgi_req->headers_size += wsgi_req->socket->proto_writev_header(wsgi_req, iov, 2); + wsgi_req->header_cnt++; + ah = ah->next; + } + + wsgi_req->socket->proto_write(wsgi_req, (char *)"\r\n", 2); body = RARRAY_PTR(ret)[2] ;