On Fri 16 Jan 2009, André Warnier wrote:
> What exact form would a HTTP response need to have, for the browser
> to correctly interpret that the response it is getting is a document
> (for example an OpenOffice document or an email in eml format), but
> which has been zipped for transmission ?
>
> What I would like to happen is that the browser receives the zipped
> document, but instead of proposing to open it as a zip file or save
> it to disk as a zip file, unzips it and handles it properly as per
> the content of the zipped response.
>
> I know that this has to do with the Content-Type and
> Content-disposition and Content-encoding (Content-type-encoding ?)
> headers, but do not know exactly what are the caveats or rules or
> "things that work with one browser and not the other" kind of stuff.
>
> Does anyone know ?
>
> If more context is required :
> A server-side application stores on the one hand original documents
> of different kinds, zipped, and on the other hand meta-data about
> these documents in a database and search-engine.
> The user can search the database, and obtain a response html page, on
> which appear icons representing the original documents.  When
> clicking on such an icon, the user should receive the original
> document. It seems a pity, considering that the document is already
> stored zipped at the server side, to unzip it before sending it to
> the browser, so that the browser would know that it is not a
> zip-file, but an OpenOffice document.
> The plan is thus to have, underneath the icons, a link which invokes
> an application on the server (Apache module, mod_perl module,
> cgi-bin,..), which retrieves the zipped original, composes the
> appropriate HTTP headers (wich it can do only based on info stored in
> the db), and sends the document in the appropriate way to the
> browser, in the zipped format. The filename of the zipped document on
> the server gives no clue as to its content. Only the meta-data in the
> db indicates that.
>
> Thanks in advance for any insights, advice, pointers etc..

You can send the file in DEFLATE format (rfc1951) or in GZIP format 
(1952). The latter happens to be the output of the gzip program. Winzip 
& Co use a different format! I think I do something like you want to.

use APR::Finfo ();
use APR::Const -compile=>qw/FINFO_NORM/;
if( $r->finfo->filetype and
    $r->headers_in->{'Accept-Encoding'}=~/gzip/ and
    -f $r->filename.'.gz' ) {
  $r->filename($r->filename.'.gz');
  $r->content_encoding('gzip');
  $r->finfo(APR::Finfo::stat($r->filename, APR::Const::FINFO_NORM, 
$r->pool));
  $r->headers_out->add(Vary=>'Accept-Encoding');
}

You have to check if the browser accepts gzip format. Set the 
Content-Encoding header and the Vary header (for proxies). 
mod_negotiation (MultiViews) provides a similar functionality.

Torsten

-- 
Need professional mod_perl support?
Just hire me: torsten.foert...@gmx.net

Reply via email to