From f15e47c4d9f0b69c648398dd2724ce49e65a79ab Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 7 Oct 2015 16:56:02 +0100 Subject: [PATCH] Fix encryption in HTTP. --- src/libutil/http.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/libutil/http.c b/src/libutil/http.c index dee2d5724..eedc9c451 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -1443,15 +1443,14 @@ rspamd_http_connection_write_message (struct rspamd_http_connection *conn, if (encrypted) { /* Internal reply (encrypted) */ meth_len = rspamd_snprintf (repbuf, sizeof (repbuf), - "HTTP/1.1 %d %s\r\n" + "HTTP/1.1 %d %V\r\n" "Connection: close\r\n" "Server: %s\r\n" "Date: %s\r\n" "Content-Length: %z\r\n" "Content-Type: %s", /* NO \r\n at the end ! */ msg->code, - msg->status ? msg->status->str : - rspamd_http_code_to_str (msg->code), + msg->status, "rspamd/" RVERSION, datebuf, bodylen, @@ -1468,15 +1467,14 @@ rspamd_http_connection_write_message (struct rspamd_http_connection *conn, enclen); } else { - rspamd_printf_fstring (&buf, "HTTP/1.1 %d %s\r\n" + rspamd_printf_fstring (&buf, "HTTP/1.1 %d %V\r\n" "Connection: close\r\n" "Server: %s\r\n" "Date: %s\r\n" "Content-Length: %z\r\n" "Content-Type: %s\r\n", msg->code, - msg->status ? msg->status->str : - rspamd_http_code_to_str (msg->code), + msg->status, "rspamd/" RVERSION, datebuf, bodylen, @@ -1573,6 +1571,11 @@ rspamd_http_connection_write_message (struct rspamd_http_connection *conn, } } + /* Setup external request body */ + priv->out[0].iov_base = buf->str; + priv->out[0].iov_len = buf->len; + + /* Buf will be used eventually for encryption */ if (encrypted) { gint meth_offset, nonce_offset, mac_offset; @@ -1611,10 +1614,6 @@ rspamd_http_connection_write_message (struct rspamd_http_connection *conn, /* During previous writes, buf might be reallocated and changed */ priv->buf->data = buf; - /* Now set up all iov */ - priv->out[0].iov_base = buf->str; - priv->out[0].iov_len = buf->len; - if (encrypted) { /* Finish external HTTP request */ priv->out[1].iov_base = "\r\n"; -- 2.39.5