X-Git-Url: http://git.tremily.us/?p=ikiwiki.git;a=blobdiff_plain;f=doc%2Fbugs%2FRunning_on_an_alternative_port_fails.mdwn;h=fa4d86ce069dfdc8737c8796c1306bd09d12c792;hp=8b5fefa91330973b1b3686d97817e5fec28ecaa0;hb=cf8a46b761ab4131fa08aade85b840bbfd4d2ba1;hpb=64e09f9968c5db26aef7bfdd70bde7c86c8fa144 diff --git a/doc/bugs/Running_on_an_alternative_port_fails.mdwn b/doc/bugs/Running_on_an_alternative_port_fails.mdwn index 8b5fefa91..fa4d86ce0 100644 --- a/doc/bugs/Running_on_an_alternative_port_fails.mdwn +++ b/doc/bugs/Running_on_an_alternative_port_fails.mdwn @@ -6,6 +6,8 @@ For example if you run on 'http://my.gear.xxx:8080/' then after clicking login ( NB: both the 'url' and the 'cgiurl' include the port and removing the port element provides the expected functionality. +--- + > I tried to reproduce this by making my laptop's web server use port > 8080. Set up ikiwiki to use that in cgiurl and url, and had > no problem with either openid or password auth login. @@ -14,3 +16,67 @@ NB: both the 'url' and the 'cgiurl' include the port and removing the port eleme > what version you were using. It could also be a problem with your web > server, conceviably, if didn't correctly communicate the port to the cgi > program. --[[Joey]] + +--- + +>> I did think of that so threw a 'printenv' script to check the port was arriving +right. + +>>> SERVER_PORT=8181 +>>> HTTP_HOST=zippy0.ie0.cobbled.net + +[ ... ] + +>>>> In apache, `HTTP_HOST` includes the port. This is not part of the CGI +>>>> spec it seems, but perl's `CGI` module seems to rely on it, +>>>> in `virtual_port`: + +>>>>> my $vh = $self->http('x_forwarded_host') || $self->http('host'); +>>>>> my $protocol = $self->protocol; +>>>>> if ($vh) { +>>>>> return ($vh =~ /:(\d+)$/)[0] || ($protocol eq 'https' ? 443 : 80); + +>>>> The `CGI` module only looks at `SERVER_PORT` when there's no +>>>> `HTTP_HOST`. So this is either a bug in perl's CGI or thttpd. +>>>> --[[Joey]] + +[ ... ] + +--- + +>>>>> This is interesting. If HTTP_HOST is wrong then + +>>>>> 0. the client header must be wrong (i.e. not including the PORT) +>>>>> 0. `perl`'s doing something bad[tm] (or at least lazy) +>>>>> 0. `apache` is adding it +>>>>> 0. `thttpd` is stripping it + +>>>>> Quick hack shows that `thttpd` must be stripping the port +number from the `Host:` header. That can be fixed. + +>>>>> Thanks for the assist. -- fergus + +--- + +Patch for `thttpd-2.25b` for posterity and completeness + +[[!format patch """ + +diff --git a/libhttpd.c b/libhttpd.c +index 73689be..039b7e3 100644 +--- a/libhttpd.c ++++ b/libhttpd.c +@@ -2074,9 +2074,6 @@ httpd_parse_request( httpd_conn* hc ) + cp = &buf[5]; + cp += strspn( cp, " \t" ); + hc->hdrhost = cp; +- cp = strchr( hc->hdrhost, ':' ); +- if ( cp != (char*) 0 ) +- *cp = '\0'; + if ( strchr( hc->hdrhost, '/' ) != (char*) 0 || hc->hdrhost[0] == '.' ) + { + httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" ); + +"""]] + +-- fergus