combining multiple filtered files into a single response
Brian <[email protected]>
| Newsgroups | gmane.comp.apache.mod-perl |
|---|---|
| Organization | Photo Researchers, Inc. |
| Message-ID | <[email protected]> |
Hello,
I've read through the documentation and searched the list archives and elsewhere
for information on how to do this properly, but I've come up short so I'm
turning to the users list for help.
What I'm trying to do is determine the proper way, modperl-style, to iterate the
process of passing a bucket brigade of file contents through an output filter
for a series of files, all within a single request/response cycle. And I want
to do it right.
So for example example, start with a simple handler and filter, where the
handler will use add_output_filter() to add a filter and call sendfile() on a
given file to generate filtered output. In this example imagine that the filter
prefixes every line of the file with the filename in the output so that the
lines of the filtered output stream all begin with "[filename]:". (But for the
solution, the filter needs to be able to operate on binary content.)
Now, imagine a request where a user submits to a form three filenames: "fileA",
"fileB" and "fileC". The goal is to have the handler perform the equivalent of
a sendfile() on each, have each pass through the filter in succession, and
output the concatenated content to the client connection in a single response.
The main handler would perform other functions too like inserting header or
footer sections and possibly additional metadata at the file boundaries. The
response headers can all be set at the beginning. What is the proper way to do
this? Subrequests? (The documentation on subrequests is poor and doesn't
suggest how you might combine multiple subrequests). Special boundary buckets to
indicate content switch?
I want to do this the right way but I'm not sure which modperl tools are right
for the job. I've thought of a few potential solutions which I'm not sure how to
implement.
One is to iterate over the filenames with subrequests (if this is even
possible/supported), so that each can be passed internally to a single request
as in the simple (single-file) handler described in the example above. If the
output of the subrequests can be captured then they can be combined into a
single response. That idea seems to be the cleanest, if not the most efficient.
If that doesn't work then I can imagine iterating over the files with calls to
"sendfile()" and using a modified filter to guess at file boundaries. However
since the filter needs to be able to handle binary content it can't do this by
reading the data itself (nor should it, since that's inefficient), but it could
do so by counting bytes if it knows the size of the files ahead of time, or some
other out-of-band signal like a "flush" bucket that indicates a file boundary.
However that solution seems messy and prone to error.
I'd also like to avoid the last resort which would be to run a long process to
process each file, save them to a temporary directory, and then re-read them at
the end into a single output stream. This defeats the purpose because I'd like
to be able to start writing the output of the first filtered file to the client
as soon as it's processed.
Any advice? Really what I want is a response handler that can generate: [apache
headers] + HeaderSection + {sendfile(file1)->output_filter} +
{sendfile(file2)->output_filter} + ... + {sendfile{fileN)->output_filter} +
FooterSection. The trick being that the "output_filter" is doing a
file-specific thing for each file and can't operate on a single stream of data
without being able to recognize the file boundaries.
Thanks for your help,
Brian