}
return res;
+}
+
+const gchar*
+rspamd_http_message_get_http_host (struct rspamd_http_message *msg)
+{
+ if (msg->flags & RSPAMD_HTTP_FLAG_HAS_HOST_HEADER) {
+ rspamd_ftok_t srch;
+
+ RSPAMD_FTOK_ASSIGN(&srch, "Host");
+
+ khiter_t k = kh_get (rspamd_http_headers_hash, msg->headers, &srch);
+
+ if (k != kh_end (msg->headers)) {
+ return (kh_value (msg->headers, k)->value).begin;
+ }
+ else if (msg->host) {
+ return msg->host->str;
+ }
+ }
+ else {
+ if (msg->host) {
+ return msg->host->str;
+ }
+ }
+
+ return NULL;
}
\ No newline at end of file
*/
guint rspamd_http_message_get_flags (struct rspamd_http_message *msg);
+/**
+ * Returns an HTTP hostname for a message, derived from a header if it has it
+ * or from a url if it doesn't
+ * @param msg
+ * @return
+ */
+const gchar* rspamd_http_message_get_http_host (struct rspamd_http_message *msg);
+
#ifdef __cplusplus
}
#endif
struct rspamd_cryptobox_pubkey *peer_pk;
rspamd_inet_addr_t *addr;
gchar *mime_type;
- gchar *host;
+ const gchar *host;
gchar *auth;
const gchar *url;
gsize max_size;
bool numeric_ip = false;
/* Check if we can skip resolving */
- if (msg->host) {
- cbd->host = msg->host->str;
+ cbd->host = rspamd_http_message_get_http_host (msg);
+ if (cbd->host) {
if (cbd->flags & RSPAMD_LUA_HTTP_FLAG_KEEP_ALIVE) {
const rspamd_inet_addr_t *ka_addr = rspamd_http_context_has_keepalive(NULL,
- msg->host->str, msg->port, msg->flags & RSPAMD_HTTP_FLAG_WANT_SSL);
+ rspamd_http_message_get_http_host (msg),
+ msg->port, msg->flags & RSPAMD_HTTP_FLAG_WANT_SSL);
if (ka_addr) {
cbd->addr = rspamd_inet_address_copy(ka_addr);
}
if (!cbd->addr) {
+ /* We use msg->host here, not cbd->host ! */
if (rspamd_parse_inet_address (&cbd->addr,
- msg->host->str, msg->host->len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
+ msg->host->str, msg->host->len,
+ RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
numeric_ip = true;
}
}