diff --git a/miniserv.pl b/miniserv.pl index ce4a69edb..6356ce740 100755 --- a/miniserv.pl +++ b/miniserv.pl @@ -1520,7 +1520,8 @@ if (defined($header{'host'})) { else { $host = $header{'host'}; } - if ($config{'musthost'} && $host ne $config{'musthost'}) { + if ($config{'musthost'} && $host ne $config{'musthost'} && + !$config{'musthost_redirect'}) { # Disallowed hostname used &http_error(400, "Invalid HTTP hostname"); } @@ -1543,6 +1544,21 @@ if ($config{'redirect_prefix'}) { } $prot = $ssl ? "https" : "http"; +# Disallowed hostname used by redirecting to musthost +if ($config{'musthost'} && $host ne $config{'musthost'} && + $config{'musthost_redirect'}) { + &write_data("HTTP/1.0 302 Moved Temporarily\r\n"); + &write_data("Date: $datestr\r\n"); + &write_data("Server: @{[&server_info()]}\r\n"); + &write_data("Location: $prot://$config{'musthost'}:$redirport\r\n"); + &write_keep_alive(0); + &write_data("\r\n"); + &log_request($loghost, $authuser, $reqline, 302, 0) if $reqline; + shutdown(SOCK, 1); + close(SOCK); + return; + } + undef(%in); if ($page =~ /^([^\?]+)\?(.*)$/) { # There is some query string information