]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
Add reverse_proxy option which hard-codes cgiurl in CGI output
authorSimon McVittie <smcv@debian.org>
Sun, 5 Oct 2014 22:06:48 +0000 (23:06 +0100)
committerSimon McVittie <smcv@debian.org>
Sun, 5 Oct 2014 22:49:37 +0000 (23:49 +0100)
This solves several people's issues with the CGI trying to be
too clever when IkiWiki is placed behind a reverse-proxy.

IkiWiki.pm
IkiWiki/CGI.pm
t/relativity.t

index 38b91ae1d373e4c6f38f99a8b4ccb61aed33fcc0..570c185ad3728cbe685e62364c06f3c2b54bf616 100644 (file)
@@ -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 => '',
index b6f47a3a7f73c2e0c8cba26f859ea47b334a8ad9..70e3b713473c789e3c844b6dd853b608d8f94709 100644 (file)
@@ -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);
        }
index 675efc903e58626ac94d017333af8aa9d9ba86b2..86b807b5b54601e9811f584824eb16fd32e338f9 100755 (executable)
@@ -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;