Browse Source

[Minor] Simplify host element handling in HTTP message

tags/1.9.1
Vsevolod Stakhov 5 years ago
parent
commit
02de13af4e
4 changed files with 36 additions and 63 deletions
  1. 32
    55
      src/libutil/http_connection.c
  2. 2
    2
      src/libutil/http_message.c
  3. 1
    1
      src/libutil/http_private.h
  4. 1
    5
      src/lua/lua_http.c

+ 32
- 55
src/libutil/http_connection.c View File

@@ -720,7 +720,7 @@ rspamd_http_simple_client_helper (struct rspamd_http_connection *conn)
struct rspamd_http_connection_private *priv;
gpointer ssl;
gint request_method;
rspamd_fstring_t *prev_host;
GString *prev_host = NULL;

priv = conn->priv;
ssl = priv->ssl;
@@ -754,7 +754,7 @@ rspamd_http_simple_client_helper (struct rspamd_http_connection *conn)
}
else {
if (prev_host) {
rspamd_fstring_free (prev_host);
g_string_free (prev_host, TRUE);
}
}
}
@@ -1426,8 +1426,7 @@ rspamd_http_connection_copy_msg (struct rspamd_http_message *msg, GError **err)
}

if (msg->host) {
new_msg->host = rspamd_fstring_new_init (msg->host->str,
msg->host->len);
new_msg->host = g_string_new_len (msg->host->str, msg->host->len);
}

new_msg->method = msg->method;
@@ -1812,12 +1811,15 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
}
}
else {

/* Client request */
if (conn->opts & RSPAMD_HTTP_CLIENT_KEEP_ALIVE) {
conn_type = "keep-alive";
}

/* Format request */
enclen += msg->url->len + strlen (http_method_str (msg->method)) + 1;
enclen += RSPAMD_FSTRING_LEN (msg->url) +
strlen (http_method_str (msg->method)) + 1;

if (host == NULL && msg->host == NULL) {
/* Fallback to HTTP/1.0 */
@@ -1855,59 +1857,34 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
}
else {
/* Normal HTTP/1.1 with Host */
if (host == NULL) {
host = msg->host->str;
}

if (encrypted) {
if (host != NULL) {
rspamd_printf_fstring (buf,
"%s %s HTTP/1.1\r\n"
"Connection: %s\r\n"
"Host: %s\r\n"
"Content-Length: %z\r\n"
"Content-Type: application/octet-stream\r\n",
"POST",
"/post",
conn_type,
host,
enclen);
}
else {
rspamd_printf_fstring (buf,
"%s %s HTTP/1.1\r\n"
"Connection: %s\r\n"
"Host: %V\r\n"
"Content-Length: %z\r\n"
"Content-Type: application/octet-stream\r\n",
"POST",
"/post",
conn_type,
msg->host,
enclen);
}
rspamd_printf_fstring (buf,
"%s %s HTTP/1.1\r\n"
"Connection: %s\r\n"
"Host: %s\r\n"
"Content-Length: %z\r\n"
"Content-Type: application/octet-stream\r\n",
"POST",
"/post",
conn_type,
host,
enclen);
}
else {
if (host != NULL) {
rspamd_printf_fstring (buf,
"%s %V HTTP/1.1\r\n"
"Connection: %s\r\n"
"Host: %s\r\n"
"Content-Length: %z\r\n",
http_method_str (msg->method),
msg->url,
conn_type,
host,
bodylen);
}
else {
rspamd_printf_fstring (buf,
"%s %V HTTP/1.1\r\n"
"Connection: %s\r\n"
"Host: %V\r\n"
"Content-Length: %z\r\n",
http_method_str (msg->method),
msg->url,
conn_type,
msg->host,
bodylen);
}
rspamd_printf_fstring (buf,
"%s %V HTTP/1.1\r\n"
"Connection: %s\r\n"
"Host: %s\r\n"
"Content-Length: %z\r\n",
http_method_str (msg->method),
msg->url,
conn_type,
host,
bodylen);

if (bodylen > 0) {
if (mime_type != NULL) {

+ 2
- 2
src/libutil/http_message.c View File

@@ -104,7 +104,7 @@ rspamd_http_message_from_url (const gchar *url)
}
}

msg->host = rspamd_fstring_new_init (host, pu.field_data[UF_HOST].len);
msg->host = g_string_new_len (host, pu.field_data[UF_HOST].len);
msg->url = rspamd_fstring_append (msg->url, path, pathlen);

REF_INIT_RETAIN (msg, rspamd_http_message_free);
@@ -489,7 +489,7 @@ rspamd_http_message_free (struct rspamd_http_message *msg)
rspamd_fstring_free (msg->status);
}
if (msg->host != NULL) {
rspamd_fstring_free (msg->host);
g_string_free (msg->host, TRUE);
}
if (msg->peer_key != NULL) {
rspamd_pubkey_unref (msg->peer_key);

+ 1
- 1
src/libutil/http_private.h View File

@@ -43,7 +43,7 @@ struct rspamd_http_header {
*/
struct rspamd_http_message {
rspamd_fstring_t *url;
rspamd_fstring_t *host;
GString *host;
rspamd_fstring_t *status;
struct rspamd_http_header *headers;


+ 1
- 5
src/lua/lua_http.c View File

@@ -127,10 +127,6 @@ lua_http_fin (gpointer arg)
g_free (cbd->mime_type);
}

if (cbd->host) {
g_free (cbd->host);
}

if (cbd->auth) {
g_free (cbd->auth);
}
@@ -935,7 +931,7 @@ lua_http_request (lua_State *L)
}

if (msg->host) {
cbd->host = rspamd_fstring_cstr (msg->host);
cbd->host = msg->host->str;
}

if (body) {

Loading…
Cancel
Save