diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 3e2b02e1..05df46d8 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -719,6 +719,7 @@ int uwsgi_python_manage_options(int i, char *optarg) { return 1; +#ifdef UWSGI_INI case LONG_ARGS_INI_PASTE: uwsgi.ini = optarg; if (uwsgi.ini[0] != '/') { @@ -728,6 +729,7 @@ int uwsgi_python_manage_options(int i, char *optarg) { up.paste = uwsgi_concat2("config:", uwsgi.ini); } return 1; +#endif case LONG_ARGS_PASTE: up.paste = optarg; return 1; diff --git a/plugins/python/wsgi_headers.c b/plugins/python/wsgi_headers.c index 8b2cfba3..01b0deed 100644 --- a/plugins/python/wsgi_headers.c +++ b/plugins/python/wsgi_headers.c @@ -13,7 +13,6 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { PyObject *headers, *head; PyObject *h_key, *h_value; int i, j; - struct uwsgi_header uh; PyObject *exc_info = NULL; struct wsgi_request *wsgi_req = current_wsgi_req(); @@ -70,10 +69,8 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { } wsgi_req->hvec[0].iov_len = wsgi_req->protocol_len; - uh.pktsize = wsgi_req->hvec[0].iov_len; wsgi_req->hvec[1].iov_base = " "; wsgi_req->hvec[1].iov_len = 1; - uh.pktsize += wsgi_req->hvec[1].iov_len; #ifdef PYTHREE wsgi_req->hvec[2].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(head)); wsgi_req->hvec[2].iov_len = strlen(wsgi_req->hvec[2].iov_base); @@ -81,18 +78,15 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { wsgi_req->hvec[2].iov_base = PyString_AsString(head); wsgi_req->hvec[2].iov_len = PyString_Size(head); #endif - uh.pktsize += wsgi_req->hvec[2].iov_len; wsgi_req->status = uwsgi_str3_num(wsgi_req->hvec[2].iov_base); wsgi_req->hvec[3].iov_base = nl; wsgi_req->hvec[3].iov_len = NL_SIZE; - uh.pktsize += wsgi_req->hvec[3].iov_len; } else { // drop http status on cgi mode base = 3; wsgi_req->hvec[0].iov_base = "Status: "; wsgi_req->hvec[0].iov_len = 8; - uh.pktsize = wsgi_req->hvec[0].iov_len; #ifdef PYTHREE wsgi_req->hvec[1].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(head)); wsgi_req->hvec[1].iov_len = strlen(wsgi_req->hvec[1].iov_base); @@ -100,11 +94,9 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { wsgi_req->hvec[1].iov_base = PyString_AsString(head); wsgi_req->hvec[1].iov_len = PyString_Size(head); #endif - uh.pktsize += wsgi_req->hvec[1].iov_len; wsgi_req->status = uwsgi_str3_num(wsgi_req->hvec[1].iov_base); wsgi_req->hvec[2].iov_base = nl; wsgi_req->hvec[2].iov_len = NL_SIZE; - uh.pktsize += wsgi_req->hvec[2].iov_len; } headers = PyTuple_GetItem(args, 1); @@ -146,10 +138,8 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { wsgi_req->hvec[j].iov_base = PyString_AsString(h_key); wsgi_req->hvec[j].iov_len = PyString_Size(h_key); #endif - uh.pktsize += wsgi_req->hvec[j].iov_len; wsgi_req->hvec[j + 1].iov_base = h_sep; wsgi_req->hvec[j + 1].iov_len = H_SEP_SIZE; - uh.pktsize += wsgi_req->hvec[j+1].iov_len; #ifdef PYTHREE wsgi_req->hvec[j + 2].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(h_value)); wsgi_req->hvec[j + 2].iov_len = strlen(wsgi_req->hvec[j + 2].iov_base); @@ -158,23 +148,38 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { wsgi_req->hvec[j + 2].iov_len = PyString_Size(h_value); #endif - uh.pktsize += wsgi_req->hvec[j+2].iov_len; wsgi_req->hvec[j + 3].iov_base = nl; wsgi_req->hvec[j + 3].iov_len = NL_SIZE; - uh.pktsize += wsgi_req->hvec[j+3].iov_len; //uwsgi_log( "%.*s: %.*s\n", wsgi_req->hvec[j].iov_len, (char *)wsgi_req->hvec[j].iov_base, wsgi_req->hvec[j+2].iov_len, (char *) wsgi_req->hvec[j+2].iov_base); } + j = (i * 4) + base; + + struct uwsgi_string_list *ah = uwsgi.additional_headers; + while(ah) { + if (wsgi_req->header_cnt+1 <= uwsgi.max_vars) { + 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 = nl; + wsgi_req->hvec[j].iov_len = NL_SIZE; + j++; + ah = ah->next; + } + else { + uwsgi_log("no more space in iovec. consider increasing max-vars...\n"); + break; + } + } + // \r\n - j = (i * 4) + base; wsgi_req->hvec[j].iov_base = nl; wsgi_req->hvec[j].iov_len = NL_SIZE; - uh.pktsize += wsgi_req->hvec[j].iov_len; - UWSGI_RELEASE_GIL wsgi_req->headers_size = wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, j + 1); UWSGI_GET_GIL diff --git a/protocol.c b/protocol.c index 7eb7d225..1d3fb339 100644 --- a/protocol.c +++ b/protocol.c @@ -1242,7 +1242,16 @@ int uwsgi_file_serve(struct wsgi_request *wsgi_req, char *document_root, uint16_ if (st.st_mtime <= ims) { wsgi_req->status = 304; wsgi_req->headers_size = wsgi_req->socket->proto_write_header(wsgi_req, wsgi_req->protocol, wsgi_req->protocol_len); - wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, " 304 Not Modified\r\n\r\n", 21); + wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, " 304 Not Modified\r\n", 19); + + struct uwsgi_string_list *ah = uwsgi.additional_headers; + while(ah) { + wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, ah->value, ah->len); + wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, "\r\n", 2); + ah = ah->next; + } + + wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, "\r\n", 2); return 0; } } @@ -1256,6 +1265,13 @@ int uwsgi_file_serve(struct wsgi_request *wsgi_req, char *document_root, uint16_ wsgi_req->headers_size = wsgi_req->socket->proto_write_header(wsgi_req, wsgi_req->protocol, wsgi_req->protocol_len); wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, " 200 OK\r\n", 9); + struct uwsgi_string_list *ah = uwsgi.additional_headers; + while(ah) { + wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, ah->value, ah->len); + wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, "\r\n", 2); + ah = ah->next; + } + if (uwsgi.file_serve_mode == 1) { wsgi_req->header_cnt = 2; wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, "X-Accel-Redirect: ", 18); diff --git a/utils.c b/utils.c index 921d1bc5..9045cf85 100644 --- a/utils.c +++ b/utils.c @@ -2219,6 +2219,7 @@ struct uwsgi_string_list *uwsgi_string_new_list(struct uwsgi_string_list **list, } uwsgi_string->value = value; + uwsgi_string->len = strlen(value); uwsgi_string->next = NULL; return uwsgi_string; diff --git a/uwsgi.c b/uwsgi.c index 485dbc49..110b97c9 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -185,6 +185,7 @@ static struct option long_base_options[] = { #ifdef UWSGI_ROUTING {"routing", no_argument, &uwsgi.routing, 1}, #endif + {"add-header", required_argument, 0, LONG_ARGS_ADD_HEADER}, {"check-static", required_argument, 0, LONG_ARGS_CHECK_STATIC}, {"static-map", required_argument, 0, LONG_ARGS_STATIC_MAP}, {"file-serve-mode", required_argument, 0, LONG_ARGS_FILE_SERVE_MODE}, @@ -2562,6 +2563,9 @@ static int manage_base_opt(int i, char *optarg) { uwsgi.erlang_cookie = optarg; return 1; #endif + case LONG_ARGS_ADD_HEADER: + uwsgi_string_new_list(&uwsgi.additional_headers, optarg); + return 1; case LONG_ARGS_CHECK_STATIC: uwsgi.check_static = realpath(optarg, NULL); uwsgi.check_static_len = strlen(uwsgi.check_static); diff --git a/uwsgi.h b/uwsgi.h index c12b5623..aaac38ba 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -249,6 +249,7 @@ struct uwsgi_static_map { struct uwsgi_string_list { char *value; + size_t len; struct uwsgi_string_list *next; }; @@ -434,6 +435,7 @@ struct uwsgi_opt { #define LONG_ARGS_SQLITE3 17106 #define LONG_ARGS_AUTO_SNAPSHOT 17107 #define LONG_ARGS_LOG_SOCKET 17108 +#define LONG_ARGS_ADD_HEADER 17109 #define UWSGI_OK 0 @@ -862,6 +864,8 @@ struct uwsgi_server { char *emperor_amqp_username; char *emperor_amqp_password; + struct uwsgi_string_list *additional_headers; + time_t master_mercy; int cpu_affinity;