lib/Foswiki.pm at line 1693 should be modified to check whether the urlHost begins with 'http://localhost' rather than being equal to it. This fixes edge cases such as mine, where a proxy-passing setup means the urlHost is actually 'http://localhost:81'.

This was asked as a question here: http://foswiki.org/Support/Question842

-- JustinClarke - 22 Apr 2011

er, wow.

I use mod_proxy_html and other mess, and here you are with another simpler solution.

thankyou. I've changed it so that you use the 'RemovePort' option, and then we compare to http://localhost - can you tell me if that works for you?

-- SvenDowideit -

Does this need to accommodate https: and not just http:

-- GeorgeClark - 08 Mar 2012

I really don't know.

    if ( $url && $url =~ m{^([^:]*://[^/]*).*$} ) {
        $this->{urlHost} = $1;

        if ( $Foswiki::cfg{RemovePortNumber} ) {
            $this->{urlHost} =~ s/\:[0-9]+$//;
        }
        # If the urlHost in the url is localhost, this is a lot less
        # useful than the default url host. This is because new CGI("")
        # assigns this host by default - it's a default setting, used
        # when there is nothing better available.
        if ( $this->{urlHost} =~ /(https?):\/\/localhost/i ) {
            my $protocol = $1;
            $this->{urlHost} = $Foswiki::cfg{DefaultUrlHost};
        }

lets say for a moment that I do test for both http and https as above, what should happen? should both be unconditionally re-written to point to the one protocol (ie, force http to always be https or visversa, or should DefaultUrlHost be changed depending on incoming protocol, or what?)

I find the entire thing a bit horrifyingly obtuse, and always get annoyed that my foswiki is re-writing my url's if i'm using localhost.

clearly, some really really strong docco explaining why you'd want to do what would help - I can't say i entirely understandy why the RemovePortNumber configure option exists - and the help for it tells me nothing about the use case.

SO, I'm going to wimp out and write it this way:

    #{urlHost}  is needed by loadSession..
    my $url = $query->url();
    if ( $url && $url =~ m{^([^:]*://[^/]*).*$} ) {
        $this->{urlHost} = $1;

        if ( $Foswiki::cfg{RemovePortNumber} ) {
            $this->{urlHost} =~ s/\:[0-9]+$//;
        }
        # If the urlHost in the url is localhost, this is a lot less
        # useful than the default url host. This is because new CGI("")
        # assigns this host by default - it's a default setting, used
        # when there is nothing better available.
        if ( $this->{urlHost} =~ /(https?):\/\/localhost/i ) {
            my $protocol = $1;
            #only replace localhost _if_ the protocol matches the one specified in the DefaultUrlHost
            if ($Foswiki::cfg{DefaultUrlHost} =~ /^$protocol/i ) {
                $this->{urlHost} = $Foswiki::cfg{DefaultUrlHost};
            }
        }
    }
    else {
        $this->{urlHost} = $Foswiki::cfg{DefaultUrlHost};
    }

-- SvenDowideit - 10 Mar 2012

ok, re-written it after writing unit tests - which meant adding (some) support for full url processing in Unit::Request

-- SvenDowideit - 14 Mar 2012

Re-titled for release notes, because I had no idea what this was about when I first read it.

-- PaulHarvey - 14 Mar 2012

 

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. see CopyrightStatement. Creative Commons LicenseGet Foswiki at sourceforge.net. Fast, secure and Free Open Source software downloads