Bug 15423 - mod_include ends chunked encoding if included script issues a redirect
Summary: mod_include ends chunked encoding if included script issues a redirect
Status: CLOSED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_include (show other bugs)
Version: 2.0.44
Hardware: Sun Solaris
: P3 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
: 16673 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-12-17 00:58 UTC by Steven Grimm
Modified: 2004-11-16 19:05 UTC (History)
1 user (show)



Attachments
patch file for adding the subrequest filter in internal_internal_redirect() (827 bytes, patch)
2003-02-23 14:30 UTC, Jeff Trawick
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steven Grimm 2002-12-17 00:58:33 UTC
If I have the following .shtml file:

<!--#include virtual="/cgi-bin/redir" --> Got to end!

And /cgi-bin/redir is a script like:

#!/bin/sh
echo 'Location: /foo.html'
echo ''

Then I'll see the contents of foo.html, but not the "Got to end" message.  This
works fine in Apache 1.x.
Comment 1 Justin Erenkrantz 2003-02-17 00:09:41 UTC
Works for me with HEAD of httpd.  Please try Apache 2.0.44.

Thanks for using Apache HTTP Server!
Comment 2 Steven Grimm 2003-02-17 19:28:27 UTC
Still broken under 2.0.44.  I've poked around a bit more and figured out some
additional details; it looks like this is a problem with interaction between
chunked encoding and mod_include:

---
dozer% cat test-apache2-redir.shtml
<!--#include virtual="/cgi-bin/redirtest" --> Got to end!
dozer% cat foo.html
hiya
dozer% cat ~/apache/cgi-bin/redirtest
#!/bin/sh
echo Location: /foo.html
echo ''
dozer% nc dozer 8763
GET /test-apache2-redir.shtml HTTP/1.1
Host: dozer.ironplanet.com:8763

HTTP/1.1 200 OK
Date: Mon, 17 Feb 2003 19:09:24 GMT
Server: Apache/2.0.44 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0210222112
Accept-Ranges: bytes
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-1

5
hiya

0

0

d
 Got to end!

0

---

Notice that although the "got to end" message *does* make it through, it comes
through *after* not one but two 0-length chunks, each of which is supposed to
indicate the end of the document (see RFC2616 section 3.6.1).  If you hit this
URL with Mozilla or MSIE or links, you just see the "hiya" message.

Now, if I replace the include of the CGI script with a direct include of
/foo.html, the result is much more reasonable:

---
dozer% cat test-apache2-redir2.shtml
<!--#include virtual="/foo.html" --> Got to end!
dozer% nc dozer 8763
GET /test-apache2-redir2.shtml HTTP/1.1
Host: dozer.ironplanet.com:8763

HTTP/1.1 200 OK
Date: Mon, 17 Feb 2003 19:22:29 GMT
Server: Apache/2.0.44 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0210222112
Accept-Ranges: bytes
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-1

5
hiya

d
 Got to end!

0

---
I'd expect to see exactly the same output whether or not there's an internal
redirect in the middle of the server-side processing of the .shtml file.
Comment 3 Jeff Trawick 2003-02-23 14:28:44 UTC
I can easily reproduce this on current code.

The problem is that we're getting down to the chunk filter on an internal redirect.

I'll attach a patch that fixes it for me in just a second.  I'm not sure
if the patch is complete, so I'm not ready to commit it.
Comment 4 Jeff Trawick 2003-02-23 14:30:05 UTC
Created attachment 4981 [details]
patch file for adding the subrequest filter in internal_internal_redirect()
Comment 5 Steven Grimm 2003-02-23 18:39:18 UTC
This patch appears to fix the problem for me.
Comment 6 Jeff Trawick 2003-02-24 01:00:22 UTC
Thanks for the quick feedback.  After reviewing my patch some more I understand
it well enough, so I've committed it to 2.1-dev.  I'll propose that it be merged
into
the stable tree (2.0.45-dev).

Thanks for using Apache, and thanks for your report!
Comment 7 Jeff Trawick 2003-02-24 04:07:20 UTC
*** Bug 16673 has been marked as a duplicate of this bug. ***
Comment 8 Jeff Trawick 2003-03-12 18:28:24 UTC
FYI, the fix for this problem has been merged into the stable tree for 2.0.45.