Please explain purpose of GZIP

curiouswebster used Ask the Experts™
I support a C# .NET website which prepares the request thusly:

        public GzipWebRequest(WebRequest wrappedRequest, bool compressRequest, bool acceptCompressedResponse)
            this.wr = wrappedRequest;
            this.gzipRequest = compressRequest;
                wr.Headers["Content-Encoding"] = GZIP;
                wr.Headers["Accept-Encoding"] = GZIP;

Please explain what GZIP is doing.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Big MontyWeb Ninja at large
it's used for file compression on a website -
Dave BaldwinFixer of Problems
Most Valuable Expert 2014
All your code is doing is putting the 'GZIP' text in the appropriate headers.  The actual use of gzip is negotiated between the browser and the server.  The server calculates whether it would take more time to gzip and send it or just send it plain.

Here are the request and response headers when connecting to my web site.

GET / HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: mailviewsplitterv=165; mailviewsplitter=575; prefsviewsplitter=195; folderviewsplitter=300; identviewsplitter=300
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache

HTTP/1.1 200 OK
Date: Thu, 09 Mar 2017 21:47:57 GMT
Server: Apache/2.4.7
X-Frame-Options: SAMEORIGIN
Last-Modified: Thu, 17 Mar 2016 21:19:08 GMT
Etag: "1973-52e452e4d6b00-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 2485
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

Open in new window

Here is verbose version of Dave's comment.

Over Internet, client (typically, browser application) makes a request to the web server. The data transported over wire is text. Data heavy web-sites have to send / receive bulk of data between client and server.

What if this is compressed at source, transported and decompressed at target? Great! Less data to transport over wire.

But does target know that the data is compressed and needs to be decompressed before processing? Oh, so we should have some sort of protocol to inform that.

So client while making a request informs server that 'I am capable of decompressing content using this (in your case gzip) technique, should you prefer to compress it before sending'. This is being informed as part of request header.

When server sees that client is capable of decompressing, it decides if it is more efficient to compress the contents and send.

Hope it clarifies.
curiouswebsterSoftware Engineer



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial