0

I've configured apache 2.4 to compress content before it is delivered to the client, using mod_deflate and the clients header set to "Accept-Encoding: gzip". So this I got already working, producing a valid gzipped file:

curl --header "Accept-Encoding: gzip" https://my.website/ > content.gz

Is there a way to allow "Accept-Encoding: zip" to compress as zip?

As far as I understand the documentation this seems not possible:

The gzip encoding is the only one supported to ensure complete compatibility with old browser implementations. The deflate encoding is not supported ... (https://httpd.apache.org/docs/2.4/mod/mod_deflate.html)

Question comes from a Windows user who cannot unzip gzip files (I guess using only Windows native tools).

[edit: as gerald-schneider noted a browser will automatically decompress the content - but we are using curl and such command line tools to be able to script the API and thus there is no browser involved. Thanks also all the other answers and comments, I think I should have be more precise , i.e. writing down the curl command to begin with].

dr0i
  • 231
  • 2
  • 11
  • 1
    Perhaps you want to use gzip tool in windows rather than reinvent the wheel in httpd. Check this solved issue in stackoverflow regarding gzip and windows in the command line. [Using gunzip on Windows in command line](https://stackoverflow.com/questions/51905489/using-gunzip-on-windows-in-command-line) – Daniel Ferradal Aug 18 '20 at 10:35
  • Yes, I was unclear if I really understood the documentation.So it is not possible. I asked, because after all, searching at the internet there _are_ apache examples using `"Accept-Encoding: zip"`, but no examples of how to configure apache to do it. So I guess these are just some mistypes. – dr0i Aug 18 '20 at 12:37
  • What is the point of this? What is the end result you are trying to achieve? – Michael Hampton Aug 18 '20 at 19:23

3 Answers3

3

I think you misunderstood what the compression in the HTTP protocol is for. It is not for downloading archives. It is to reduce the data that is transferred when you are just browsing. The files that are compressed by it are HTML, CSS, JavaScripts and images. The decompression is handled by the browser before it displays the pages. And the browsers can handle gzip just fine on Windows.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • Ah, thx for the answer! Didn't know that. As we use command line tools, like `curl`, this doesn't solve my problem, though. I will edit my question putting curl into it. – dr0i Aug 18 '20 at 09:25
  • 2
    I still don't understand what exactly your problem is. – Gerald Schneider Aug 18 '20 at 09:50
  • I added "So this makes a valid gzipped file: "... (see at the top of my question). I hope it's clear now. Thx for making me aware to work more with explicit examples. – dr0i Aug 18 '20 at 12:32
  • Just a note: not only HTML, CSS, JavaScripts and images are compressed but all kinds of content. I think it is really type agnostic. In my case an API serves JSON, CSV etc. and this data is nicely compressed using `gzip`. – dr0i Aug 18 '20 at 13:03
  • It's not necessarily type agnostic. It's the most common case, but the server will compress whatever it is configured to compress. This can be all, nothing, or anything in between. Hell, you could configure Apache to compress all files that are older than X days, but no newer files if you wanted to. Not that that would make sense. The types I listed just were some examples, the list could be endless. – Gerald Schneider Aug 18 '20 at 13:10
2

As pointed out in the question's citation of the apache documentation it is not possible to configure apache to serve content compressed as zip with the mod_deflate and client's header set to Accept-Encoding: zip. Only gzip works. If a user uses a browser that browser will decode it on the fly. If the user downloads the content with e.g. curl she has to gunzip the gziped content, be it with OS native tools or installed ones (the latter necessary for e.g. Windows users).

dr0i
  • 231
  • 2
  • 11
0

Reading your comment, I am a bit unsure of what you are asking:

  • Do you want your apache server to send normal (think html or plaintext) file with a Zip encoding instead of Gzip? (Impossible according to documentation)
  • Do you want curl to be able to fetch data from your server? (in that case, you don't need to worry about the encoding as it is just a "minor" network optimisation)
  • Do you want to have curl download some zip content? In that case you should instead configure httpd so it serve directly your zip archive with some "static file" settings

Anyway, I am not sure the content-encoding is what you are looking for here...