Write Web Server 4 by yourself (how does the Web server compress data and implement the gzip module of the Web server)

Source: Internet
Author: User

Write Web Server 4 by yourself (how does the Web server compress data and implement the gzip module of the Web server)-software studio in March-Ren ji-blog channel-csdn. net

Write Web Server 4 by yourself (how does the Web server compress data and implement the gzip module of the Web server) Category: open-source Linux C Language Read by 320 Comment (0) Favorites Report

Why do web servers need to compress data?

If the web page to be sent by the Web server is compressed, the data to be sent will be reduced by about half, which will save a lot of bandwidth, in this way, you can increase your concurrency and reduce the webpage transmission time. Accelerate web browsing.

Is it true that enabling compression on the web server will definitely improve the performance?

Not necessarily, because each compression requires File compression.Algorithm. It will consume a certain amount of CPU and I/O. Therefore, it is unnecessary to enable the compression function when the file is small.

 

BenProgramI have compiled it in Ubuntu and tested it in Firefox, Windows System IE 8, Firefox, and chrome.

This program needs to use the zlib compression class library. If it is not installed, it will not succeed. I only provideCodeAnd running mode. I hope you will understand. About

The knowledge in the zlib library will be explained in a new blog later. For details about the gzip compression header, refer to another blog.Gzip Header Format.

Use zlib to illustrate http://blog.csdn.net/rentiansheng/article/details/8519681

 

Source code and makefile: http://pan.baidu.com/share/link? Consumer id = 167795 & UK = 2181414688

Running process:

1. Download the code and makefile.

2. Transfer the terminal to the directory of the file where the agent buyer and makefile are located.

3. Execute the make command to compile

4. Execute the generated reage Program (./reage)

5. enter 127.0.0.1: 1024 in the browser to view the result.

(My compressed content is fixed. Sorry. I also forgot to compare the size before compression with the size after compression. Because less content is compressed, it cannot be reflected. Focuses on function implementation)

directly give Source Code to everyone. The following is the source code. (If you have any questions, I hope you can point them out.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.