HTTP Server
2005/03/30
Reference
W. Richard Stevens, “Unix Network Programming 2/e Volume 1” ,1998
James F. Kurose and Keith W. Ross, "Computer
Networks: A Top-Down Approach Featuring the Internet 3/e“, 2002.
IETF RFC 2616,“Hypertext Transfer Protocol --
HTTP/1.1 “
HTTP connections
Nonpersistent HTTP
At most one object is sent over a TCP
connection.
HTTP/1.0 uses
nonpersistent HTTP
Persistent HTTP
Multiple objects can be sent over single TCP connection between client and server.
HTTP/1.1 uses
persistent connections
in default mode
HTTP Request Message Format
HTTP Response Message Format
version status reason
Message Body
Message Format Example
Request message
Response message
GET /index.html HTTP/1.1 Connection: close
User-agent: Mozilla/4.0 Accept-language: fr
HTTP/1.1 200 OK Connection: close
Date: Thu, 06 Aug 1998 12:00:15 GMT Last-Modified: Mon, 22 Jun 1998 09:23:24 Content-Length: 6821
Content-Type: text/html (data data)
HW2:HTTP Server
You have to implement a simple HTTP
Server with Persistent and Non-Persistent functions
In request message
Connection: close
Means non-persistent connection
Connection: Keep-Alive
Means persistent connection
Server should keep the connection alive a default time(10s) and send back the Keep-Alive header
Ex. Keep-Alive: timeout=10, max=100
HW2:HTTP Server
URL in request line
Filename is related to the working directory
Ex. /index.htm means to get ./index.htm
Default is to get index.html or index.htm
Ex. / means to get ./index.html or ./index.htm
No need to support directory, but is encourged
If file doesn’t exist, reply 404 not found.
In the response message
Connection, Date, Content-Length, Content-Type, Last- Modified should be supported
Keep-Alive is optional (depends on Connection)
HW2:HTTP Server
Possible value of the header
Connection
close, Keep-Alive
Date, Last-Modified
Thu, 06 Aug 1998 12:00:15 GMT
Content-Length
file size
Content-Type
text/html, image/jpg (only have to support these)
HW2:HTTP Server
HTTP Server execution format
Your program must be gcc 3.3.1 compatible
Name your program in this way
b91902xxx_s.cc for HTTP Server (suffix may be c, cc, cpp)
Make your program as a tarball
Email the tarball to
[email protected]
Subject:[network hw2]b91902xxx name
Due after four weeks (4/27 PM2:20)
HttpServer server_port
tar zcvf b91902xxx_hw2.tar.gz b91902xxx_s.cc
Something Useful
IE, Mozilla, ..
Ethereal (http://www.ethereal.com)
String related function