From: Simon McVittie Date: Sun, 5 Oct 2014 22:06:48 +0000 (+0100) Subject: Add reverse_proxy option which hard-codes cgiurl in CGI output X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/commitdiff_plain/3b8da667cc1514a9589190b614307c0a76af532a?ds=sidebyside Add reverse_proxy option which hard-codes cgiurl in CGI output This solves several people's issues with the CGI trying to be too clever when IkiWiki is placed behind a reverse-proxy. --- diff --git a/IkiWiki.pm b/IkiWiki.pm index 38b91ae1d..570c185ad 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -108,6 +108,14 @@ sub getsetup () { safe => 1, rebuild => 1, }, + reverse_proxy => { + type => "boolean", + default => 0, + description => "do not adjust cgiurl if CGI is accessed via different URL", + advanced => 0, + safe => 1, + rebuild => 0, # only affects CGI requests + }, cgi_wrapper => { type => "string", default => '', diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index b6f47a3a7..70e3b7134 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -59,7 +59,7 @@ sub cgitemplate ($$$;@) { my $template=template("page.tmpl"); my $topurl = $config{url}; - if (defined $cgi && ! $config{w3mmode}) { + if (defined $cgi && ! $config{w3mmode} && ! $config{reverse_proxy}) { $topurl = $cgi->url; } @@ -93,7 +93,13 @@ sub cgitemplate ($$$;@) { sub redirect ($$) { my $q=shift; eval q{use URI}; - my $url=URI->new(urlabs(shift, $q->url)); + + my $topurl; + if (defined $q && ! $config{w3mmode} && ! $config{reverse_proxy}) { + $topurl = $q->url; + } + + my $url=URI->new(urlabs(shift, $topurl)); if (! $config{w3mmode}) { print $q->redirect($url); } diff --git a/t/relativity.t b/t/relativity.t index 675efc903..86b807b5b 100755 --- a/t/relativity.t +++ b/t/relativity.t @@ -571,11 +571,8 @@ run(["./t/tmp/ikiwiki.cgi"], \undef, \$content, init => sub { %bits = parse_cgi_content($content); like($bits{tophref}, qr{^(?:/wiki|\.)/$}); like($bits{cgihref}, qr{^(?:(?:https:)?//example.com)?/cgi-bin/ikiwiki.cgi$}); -TODO: { -local $TODO = "reverse-proxy support needed"; is($bits{basehref}, "https://example.com/wiki/"); like($bits{stylehref}, qr{^(?:(?:https:)?//example.com)?/wiki/style.css$}); -} # previewing a page $in = 'do=edit&page=a/b/c&Preview'; @@ -589,10 +586,7 @@ run(["./t/tmp/ikiwiki.cgi"], \$in, \$content, init => sub { %bits = parse_cgi_content($content); like($bits{tophref}, qr{^(?:/wiki|\.\./\.\./\.\.)/$}); like($bits{cgihref}, qr{^(?:(?:https:)?//example.com)?/cgi-bin/ikiwiki.cgi$}); -TODO: { -local $TODO = "reverse-proxy support needed"; is($bits{basehref}, "https://example.com/wiki/a/b/c/"); like($bits{stylehref}, qr{^(?:(?:https:)?//example.com)?/wiki/style.css$}); -} done_testing;