Skip to content

Commit

Permalink
Use hostname_vpn if defined for mirror scan
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-suse committed Jul 28, 2021
1 parent 7949645 commit 475d21b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/MirrorCache/Schema/ResultSet/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ sub mirrors_query {
my $ipvx = $ipv eq 'ipv4'? 'ipv6' : 'ipv4';
my $capabilityx = $capability eq 'http'? 'https' : 'http';
my $extra = $mirrorlist? '': "WHERE no4 = 0 and no5 = 0";
my $hostname = $vpn? "COALESCE(s.hostname_vpn,s.hostname)" : "s.hostname";
my $hostname = $vpn? "CASE WHEN length(s.hostname_vpn)>0 THEN s.hostname_vpn ELSE s.hostname END" : "s.hostname";

my $sql = <<"END_SQL";
select * from (
Expand Down Expand Up @@ -160,8 +160,11 @@ concat(
case
when (cap_http.server_id is null and cap_fhttp.server_id is null) then 'http'
else 'https'
end
,'://',s.hostname,s.urldir,f.path) as url, max(fds.folder_diff_id) as diff_id, extract(epoch from max(fd.dt)) as dt_epoch
end,
'://',
CASE WHEN length(s.hostname_vpn)>0 THEN s.hostname_vpn ELSE s.hostname END,
s.urldir,f.path) as url,
max(fds.folder_diff_id) as diff_id, extract(epoch from max(fd.dt)) as dt_epoch
from server s join folder f on f.id=?
left join server_capability_declaration cap_http on cap_http.server_id = s.id and cap_http.capability = 'http' and not cap_http.enabled
left join server_capability_declaration cap_https on cap_https.server_id = s.id and cap_https.capability = 'https' and not cap_https.enabled
Expand Down
8 changes: 4 additions & 4 deletions t/environ/04-remote-nginx-redirect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ $mc/start
$mc/status

$mc/db/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ng7/print_address)','','t','us','na'"
$mc/db/sql "insert into server(hostname,hostname_vpn,urldir,enabled,country,region) select '$($ng8/print_address)','mirror.vpn.us','','t','us','na'"
$mc/db/sql "insert into server(hostname,hostname_vpn,urldir,enabled,country,region) select 'non-vpn.us','$($ng8/print_address)','','t','us','na'"

# remove folder1/file1.1.dt from ng8
# remove a file from ng8
rm $ng8/dt/folder1/file2.1.dat

# first request redirected to MIRRORCACHE_REDIRECT, eventhough files are not there
Expand Down Expand Up @@ -56,6 +56,6 @@ $mc/backstage/shoot
$mc/curl -H "Accept: */*, application/metalink+xml" /download/folder1/file2.1.dat | grep $($ap9/print_address)

# now redirects to ng8
$mc/curl -I /download/folder1/file2.1.dat | grep $($ng8/print_address)
$mc/curl -I /download/folder1/file2.1.dat?PEDANTIC=0 | grep non-vpn.us
# 10.* redirected to mirror.vpn.us
$mc/curl -H 'X-Forwarded-For: 10.0.1.1' -I '/download/folder1/file2.1.dat?PEDANTIC=0&COUNTRY=us' | grep mirror.vpn.us
$mc/curl -H 'X-Forwarded-For: 10.0.1.1' -I '/download/folder1/file2.1.dat?COUNTRY=us' | grep $($ng8/print_address)

0 comments on commit 475d21b

Please sign in to comment.