Bug 17148 - SCRIPT_URI is missing port number for implied files from DirectoryIndex
Summary: SCRIPT_URI is missing port number for implied files from DirectoryIndex
Status: RESOLVED WORKSFORME
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_dir (show other bugs)
Version: 2.0.44
Hardware: PC Linux
: P3 major with 4 votes (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-18 03:07 UTC by Matthew Bogosian
Modified: 2007-06-08 23:32 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Bogosian 2003-02-18 03:07:31 UTC
I'm only guessing this is in mod_dir...it could be in mod_rewrite or something
entirely different for all I know.

Here's how to reproduce:

1. run a webserver on port 8080:

    Listen 8080

2. create a cgi-directory with the following properties

    Options +ExecCGI
    AddHandler cgi-script .cgi
    DirectoryIndex index.html ... index.cgi

3. create a file called index.cgi in that directory:

- - - - - - - - %< CUT HERE >% - - - - - - - -
#!/bin/sh                                                                       
echo 'Content-type: text/html'
echo
echo '<pre>'
echo "\$SCRIPT_URI = $SCRIPT_URI"
echo '</pre>'

exit 0
- - - - - - - - %< CUT HERE >% - - - - - - - -

4. Navigate to that file on your server. For example:

    lynx -source http://somehost.somedomain:8080/cgi-bin/index.cgi

You should see the following output:

<pre>
$SCRIPT_URI = http://somehost.somedomain:8080/cgi-bin/index.cgi
</pre>

5. Now navigate to just the CGI directory and let DirectoryIndex resolve to
index.cgi for you. For example:

    lynx -source http://somehost.somedomain:8080/cgi-bin/

You should now see the following output:

<pre>
$SCRIPT_URI = http://somehost.somedomain/cgi-bin/
</pre>

6. Notice how the port is missing in the second output.

Another way to see this is when running PHP in Apache. The
$_SERVER['SCRIPT_URI'] entry will be missing the port number for any script
arrived at through DirectoryIndex resolution.

I have not tried experimenting with any of the Rewrite* directives. I have not
tried this in Apache 1.x.
Comment 1 Matthew Bogosian 2003-02-18 03:10:29 UTC
I should have noted that this happens on any non standard port (not just 8080).
Comment 2 Matthew Bogosian 2003-08-02 04:45:05 UTC
This may also be related to bug #17148.
Comment 3 Matthew Bogosian 2003-08-02 04:46:11 UTC
Oops...I meant bug #17149. :-/
Comment 4 Matthew Bogosian 2004-07-17 16:28:05 UTC
This is still a major pain in the butt, but I haven't seen any activity or
comment on this one. I'm changing the component to be what I believe is more
accurate.
Comment 5 Matthew Bogosian 2004-07-17 17:03:06 UTC
Perhaps this isn't mod_rewrite's fault after all. From mod_rewrite (2.0.50):

    1125     /*
    1126      *  create the SCRIPT_URI variable for the env
    1127      */
    1128 
    1129     /* add the canonical URI of this URL */
    1130     thisserver = ap_get_server_name(r);
    1131     port = ap_get_server_port(r);
    1132     if (ap_is_default_port(port, r)) {
    1133         thisport = "";
    1134     }
    1135     else {
    1136         apr_snprintf(buf, sizeof(buf), ":%u", port);
    1137         thisport = buf;
    1138     }

This looks pretty simple. As far as I can tell, ap_get_server_port is defined in
server/core.c, and ap_is_default_port is a macro defined in include/httpd.h
which expands to: "(port == ap_run_default_port(r))". Unfortunately, I'm not
very adept at internal Apache development, and ap_run_default_port is defined
via some hook function macro magic that I don't fully understand.

Can anyone verify what the output of "ap_get_server_port(r)" and
"ap_is_default_port(port, r)" are in this context (i.e., when browsing to an
implied file via DirectoryIndex a la the above)?
Comment 6 Paul Querna 2004-08-30 03:55:47 UTC
doesn't really look like a mod_rewrite problem to me
Comment 7 Davi Arnaut 2007-06-08 17:32:24 UTC
Doesn't look like a problem at all. It's perfectly fine because port 80 is the default port
for the http scheme.
Comment 8 Matthew Bogosian 2007-06-08 22:04:27 UTC
Davi, you closed the bug without actually reading any of the comments or
understanding it. This has nothing to do with port 80. This has to do with using
a non-standard port (see comment #1) and DirectoryIndex.

Please run through the examples yourself before just blindly closing bugs
without actually taking the time to understand them.
Comment 9 Davi Arnaut 2007-06-08 22:35:07 UTC
Yes, I may have initially misunderstood. This has to do with internal redirects,
and since internal redirects "have no ports", the default port is 80 for the sub
request. I don't think it's worth propagating this down the sub request, since
it's another request.
Comment 10 Davi Arnaut 2007-06-08 23:32:15 UTC
I can't reproduce the problem with 2.0.60-dev. If more information appears later,
please re-open the bug.

[davi@montefiori 2.0.x]$ lynx -source http://localhost:8080/cgi-bin/
<pre>
$SCRIPT_URI = http://localhost:8080/cgi-bin/
</pre>