HTTP Server Based on boost: ASIO
----
Blog, http://blog.csdn.net/shunqiziranhao007/article/details/8737629
Date, January 1, March 29, 2013
----
This is an example of the boost ASIO Library (I modified some code to achieve the following effect), and implemented HTTP request packets and HTTP response packets of http1.0. Very interesting.
----
HTTP
----
For details, see "Computer Network-top-down v4cn" p61.
For more information, see RFC 2616.
There are two types of HTTP packets: Request Message and Response Message.
----
HTTP Request Message
----
It consists of three parts: one request line, several first rows, and entity body.
The format of the request line is: method, space, Uri, space, Protocol version, for example,
GET/index.html HTTP/1.1 CRLF
Then there is the first line, as shown in figure
HOST: www.xxx.com CRLF
Connection: Close CRLF
CRLF
Finally, Entity
----
HTTP Response Message
----
Part 3: state line 1, first line of several rows, entity body. For example,
HTTP/1.1 200 OK CRLF
Connection: Close CRLF
Date:... CRLF
Server:... CRLF
Last-modified:... CRLF
Content-Length:... CRLF
Content-Type:... CRLF
Entity
----
The following is the program effect.
Root directory of the server,
Alan @ Alan-PC: HTTP $ pwd
/Home/Alan/test/HTTP
Alan @ Alan-PC: HTTP $ cat index.html
<HTML>
<HR>
<B> hello, HTTP Server Based on boost: ASIO! </B>
<HR>
</Html>
Enable the HTTP server,
Alan @ Alan-PC: Server $./http_server.exe 0.0.0.0 10080/home/Alan/test/HTTP
The client accesses the HTTP server,
Alan @ Alan-PC: client $./async_client.exe 0.0.0.0 10080/index.html
Content-Length XH: 78
Content-Type XH: text/html
<HTML>
<HR>
<B> hello, HTTP Server Based on boost: ASIO! </B>
<HR>
</Html>
The browser accesses the HTTP server,