0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 14:08:56 +02:00

ircd:Ⓜ️:fed: Use single codepath for request target; use canonize rewrite.

This commit is contained in:
Jason Volk 2020-04-26 14:53:00 -07:00
parent cbb988d31c
commit e87a26c142
2 changed files with 28 additions and 15 deletions

View file

@ -21,7 +21,7 @@ namespace ircd::m::fed
string_view well_known(const mutable_buffer &out, const string_view &origin);
net::hostport matrix_service(net::hostport remote) noexcept;
net::hostport server(const mutable_buffer &out, const string_view &origin);
string_view server(const mutable_buffer &out, const string_view &origin);
bool errant(const string_view &origin);
bool linked(const string_view &origin);
@ -56,8 +56,8 @@ inline ircd::net::hostport
ircd::m::fed::matrix_service(net::hostport remote)
noexcept
{
if(likely(!net::port(remote)))
net::service(remote) = net::service(remote)?: m::canon_service;
if(!net::port(remote) && !net::service(remote))
net::service(remote) = m::canon_service;
return remote;
}

View file

@ -1400,18 +1400,20 @@ ircd::m::fed::request::request(const mutable_buffer &buf_,
// Perform well-known query; note that we hijack the user's buffer to make
// this query and receive the result at the front of it. When there's no
// well-known this fails silently by just returning the input (likely).
const string_view remote
const string_view &target
{
// We don't query for well-known if the origin has an explicit port.
!port(net::hostport(opts.remote))?
well_known(buf_, opts.remote):
opts.remote
fed::server(buf_, opts.remote)
};
// Devote the remaining buffer for HTTP as otherwise intended.
const mutable_buffer buf
{
buf_ + size(remote)
buf_ + size(target)
};
const net::hostport remote
{
target
};
// Generate the request head including the X-Matrix into buffer.
@ -1419,7 +1421,7 @@ ircd::m::fed::request::request(const mutable_buffer &buf_,
{
// Note that we override the HTTP Host header with the well-known
// remote; otherwise default is the destination above which may differ.
{ "Host", remote }
{ "Host", service(remote)? host(remote) : target }
});
// Setup some buffering features which can optimize the server::request
@ -1434,7 +1436,7 @@ ircd::m::fed::request::request(const mutable_buffer &buf_,
// Launch the request
return server::request
{
matrix_service(remote),
remote,
std::move(opts.out),
std::move(opts.in),
opts.sopts
@ -1520,7 +1522,7 @@ ircd::m::fed::errant(const string_view &origin)
});
}
ircd::net::hostport
ircd::string_view
ircd::m::fed::server(const mutable_buffer &buf,
const string_view &origin)
{
@ -1529,10 +1531,21 @@ ircd::m::fed::server(const mutable_buffer &buf,
origin
};
if(likely(!port(remote)))
remote = well_known(buf, host(remote));
string_view target
{
!port(remote)?
well_known(buf, host(remote)):
origin
};
return matrix_service(remote);
remote = target;
if(!port(remote) && !service(remote))
{
service(remote) = m::canon_service;
target = net::canonize(buf, remote);
}
return target;
}
//