g_assert_not_reached ();
}
+ msg->url = rspamd_fstring_append (msg->url, cbd->data->rest,
+ strlen (cbd->data->rest));
+
+ if (cbd->data->userinfo) {
+ rspamd_http_message_add_header (msg, "Authorization",
+ cbd->data->userinfo);
+ }
+
MAP_RETAIN (cbd, "http_callback_data");
- rspamd_http_connection_write_message (cbd->conn, msg, cbd->data->host,
- NULL, cbd, cbd->fd, &cbd->tv, cbd->ev_base);
+ rspamd_http_connection_write_message (cbd->conn,
+ msg,
+ cbd->data->host,
+ NULL,
+ cbd,
+ cbd->fd,
+ &cbd->tv,
+ cbd->ev_base);
}
else {
msg_err_map ("cannot connect to %s: %s", cbd->data->host,
g_free (data->host);
g_free (data->path);
+ g_free (data->rest);
+
+ if (data->userinfo) {
+ g_free (data->userinfo);
+ }
if (data->etag) {
rspamd_fstring_free (data->etag);
goto err;
}
else {
- if (!(up.field_set & 1 << UF_HOST)) {
+ if (!(up.field_set & 1u << UF_HOST)) {
msg_err_config ("cannot parse HTTP url: %s: no host", bk->uri);
goto err;
}
tok.len = up.field_data[UF_HOST].len;
hdata->host = rspamd_ftokdup (&tok);
- if (up.field_set & 1 << UF_PORT) {
+ if (up.field_set & (1u << UF_PORT)) {
hdata->port = up.port;
}
else {
}
}
- if (up.field_set & 1 << UF_PATH) {
+ if (up.field_set & (1u << UF_PATH)) {
tok.begin = bk->uri + up.field_data[UF_PATH].off;
- tok.len = strlen (tok.begin);
+ tok.len = up.field_data[UF_PATH].len;
hdata->path = rspamd_ftokdup (&tok);
+
+ /* We also need to check query + fragment */
+ if (up.field_set & ((1u << UF_QUERY) | (1u << UF_FRAGMENT))) {
+ tok.begin = bk->uri + up.field_data[UF_PATH].off +
+ up.field_data[UF_PATH].len;
+ tok.len = strlen (tok.begin);
+ hdata->rest = rspamd_ftokdup (&tok);
+ }
+ else {
+ hdata->rest = g_strdup ("");
+ }
+ }
+
+ if (up.field_set & (1u << UF_USERINFO)) {
+ /* Create authorisation header for basic auth */
+ guint len = sizeof ("Basic ") +
+ up.field_data[UF_USERINFO].len * 8 / 5 + 4;
+ hdata->userinfo = g_malloc (len);
+ rspamd_snprintf (hdata->userinfo, len, "Basic %*Bs",
+ (int)up.field_data[UF_USERINFO].len,
+ bk->uri + up.field_data[UF_USERINFO].off);
}
}