mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Merge pull request #13825 from obsidiansystems/slight-optimize-s3ToHttpsURL
`ParsedS3URL::toHttpsUrl` Slight optimize
This commit is contained in:
commit
ca94905593
1 changed files with 6 additions and 4 deletions
|
|
@ -68,8 +68,10 @@ try {
|
||||||
|
|
||||||
ParsedURL ParsedS3URL::toHttpsUrl() const
|
ParsedURL ParsedS3URL::toHttpsUrl() const
|
||||||
{
|
{
|
||||||
std::string regionStr = region.value_or("us-east-1");
|
auto toView = [](const auto & x) { return std::string_view{x}; };
|
||||||
std::string schemeStr = scheme.value_or("https");
|
|
||||||
|
auto regionStr = region.transform(toView).value_or("us-east-1");
|
||||||
|
auto schemeStr = scheme.transform(toView).value_or("https");
|
||||||
|
|
||||||
// Handle endpoint configuration using std::visit
|
// Handle endpoint configuration using std::visit
|
||||||
return std::visit(
|
return std::visit(
|
||||||
|
|
@ -77,7 +79,7 @@ ParsedURL ParsedS3URL::toHttpsUrl() const
|
||||||
[&](const std::monostate &) {
|
[&](const std::monostate &) {
|
||||||
// No custom endpoint, use standard AWS S3 endpoint
|
// No custom endpoint, use standard AWS S3 endpoint
|
||||||
return ParsedURL{
|
return ParsedURL{
|
||||||
.scheme = schemeStr,
|
.scheme = std::string{schemeStr},
|
||||||
.authority = ParsedURL::Authority{.host = "s3." + regionStr + ".amazonaws.com"},
|
.authority = ParsedURL::Authority{.host = "s3." + regionStr + ".amazonaws.com"},
|
||||||
.path = (CanonPath::root / bucket / CanonPath(key)).abs(),
|
.path = (CanonPath::root / bucket / CanonPath(key)).abs(),
|
||||||
};
|
};
|
||||||
|
|
@ -85,7 +87,7 @@ ParsedURL ParsedS3URL::toHttpsUrl() const
|
||||||
[&](const ParsedURL::Authority & auth) {
|
[&](const ParsedURL::Authority & auth) {
|
||||||
// Endpoint is just an authority (hostname/port)
|
// Endpoint is just an authority (hostname/port)
|
||||||
return ParsedURL{
|
return ParsedURL{
|
||||||
.scheme = schemeStr,
|
.scheme = std::string{schemeStr},
|
||||||
.authority = auth,
|
.authority = auth,
|
||||||
.path = (CanonPath::root / bucket / CanonPath(key)).abs(),
|
.path = (CanonPath::root / bucket / CanonPath(key)).abs(),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue