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.)