Read the HTTP rfc, more details inline...

> -----Original Message-----
> From: André Warnier
> Sent: Thursday, May 20, 2010 16:04
> Subject: how to return a zipped file so that the browser will 
> unzip it ?
> 
> Hi.
> This is not really a Tomcat question, rather something one 
> should be able to do with Tomcat, but I-don't-know-how kind of thing.
> It was inspired by this servlet :
> http://www.javaside.com/u_zipservlet.html
> 
> The question is :
> Suppose that to gain space on my Tomcat server and to speed 
> up content delivery, I have a whole bunch of files in one of 
> my Tomcat contexts, which have been pre-zipped.
> That is, I have for example a.txt, b.txt, c.txt etc... but 
> all these huge text files have already been pre-zipped, and 
> they are really on my server as (catalina_base)/webapps/mywebapp/
>       a.txt.zip
>       b.txt.zip
>       c.txt.zip
>       etc...

First of all I don’t think zip is a supported HTTP transport encoding, I could
be wrong.

> 
> Now I would like the user to be able to request the URL 
> http://hostname/mywebapp/a.txt and obtain this file, as a 
> text, displayed in the browser window.
> Of course I do not want Tomcat to retrieve the file a.zip, 
> unzip it, and send it back unzipped as a.txt. I want it to 
> remain zipped during transmission, to use less bandwidth.
> And I also do not want to leave my files on disk as a.txt, 
> b.txt, etc.. 

Using an http compression method compress your files.

> and ask Tomcat to compress them on-the-fly just before 
> sending them to the browser. The files are already 

When the browser says it accepts the same compression method as you used, send
the file indicating that is is compressed per http rfc.

> compressed, so that would be a waste of CPU cycles.

Otherwise you will have to decompress it and send it per the browsers requested
transmission method.

> 
> Thus I want my Tomcat webapp to
> - receive a request for /a.txt
> - see that there is aready, on disk, a file a.txt.zip
> - consequently, read a.txt.zip, and send this "as is" back to 
> the browser, but telling the browser that this has only be 
> zipped for transmission, but that it is really a.txt, and ask 
> the browser to unzip it and display it as text.
> (If it makes it easier to conceive the difference or benefit, 
> you can also think that instead of text files, these are 
> originally very large PDF files (say a.pdf), which have been 
> zipped (as a.pdf.zip), but which I want to display as PDF in 
> the browser (as a.pdf))
> 
> How would you do that ?
> 
> I can think of creating a special servlet that would do that, 
> by playing with the Content-transfer-encoding header.
> But considering that the default servlet must be already 
> doing more than that (when it actually compresses content 
> before returning it), and is probably much better written and 
> optimised than what I could come up with myself, isn't there 
> a smarter way to do this without writing a special servlet to do it ?
> 
> You see, we perl programmers are lazy; and you Java/Tomcat 
> guys are smart.  There should be some synergy there.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 




--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- Jason Pyeron                      PD Inc. http://www.pdinc.us -
- Principal Consultant              10 West 24th Street #100    -
- +1 (443) 269-1555 x333            Baltimore, Maryland 21218   -
-                                                               -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to