



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Rensselaer Polytechnic Institute CSCI- 4220 – Network Programming David Goldschmidt, Ph.D.
All endpoints must “understand” and correctly implement the protocol Protocols must be formally defined, unambiguous, and well-documented Protocols should address error conditions and unexpected scenarios
Web servers are essentially HTTP servers
Most clients and servers support version 1. But 1.0 is also in use (maybe also 0.9?!)
P Ethernet Hdr | IP Hdr | TCP Hdr | HTTP Request | Cksum IP Hdr | TCP Hdr | HTTP Request TCP Hdr | HTTP Request HTTP Request P Q
see http://www.ietf.org/rfc/rfc1945.txt
see http://www.ietf.org/rfc/rfc2616.txt
see http://www.ietf.org/rfc/rfc2396.txt
HTTP is an application-level protocol with the lightness and speed necessary for distributed, hypermedia information systems
HTTP communication generally takes place over TCP/IP connections The default port is TCP 80, but other ports can be used
A client sends a request The server sends a response
e.g. try using telnet to access a Web server....
Lines must always end with "\r\n" (a.k.a. CRLF) Headers are optional A blank line separates the request from the content Request-Line Header(s) ... ... -- blank line -- Content ... ... ...
Each token is separated by a space character Though "\r\n" is required by the protocol, "\n" seems to work in practice The HTTP-Version is either HTTP/1. or HTTP/1.
GET – request information identified by the given URI (absolute or relative?) HEAD – request metadata regarding the given URI (search engines!) POST – send (i.e. post) information to the given URI (e.g. via a form) Method URI HTTP-Version\r\n
Who is making the request What kind of client is making the request What kind of content will be accepted
For GET and HEAD requests, that’s the end (though don’t forget the blank line!) GET /index.html HTTP/1. Accept: text/html Host: www.rpi.edu From: [email protected] User-Agent: Mozilla/4. Referer: http://somewhere.else.com/rpi.html -- blank line --
POST /~goldsd/changegrade.php HTTP/1. Accept: / Host: www.cs.rpi.edu User-Agent: SecretAgent v3. Referer: http://somewhere.devious.com/x.php Content-Length: 36 -- blank line -- rin=660123456&item=midterm&grade=
A Status-Line is always returned A blank line separates the response from the content Content is a sequence of bytes (e.g. HTML, image, text, etc.) Status-Line Header(s) ... ... -- blank line -- Content ... ... ...
The HTTP-Version is either HTTP/1. or HTTP/1.1 (and does not necessarily match the corresponding request) Response status is represented using a 3-digit Status-Code and a human-readable Message HTTP-Version Status-Code Message
1xx – Informational 2xx – Success 3xx – Redirection 4xx – Client Error 5xx – Server Error
HTTP/1.0 301 Moved Permanently HTTP/1.0 400 Bad Request HTTP/1.0 403 Forbidden HTTP/1.0 500 Internal Server Error
Header lines specify attribute name/value pairs (e.g. Date:) As with request headers, response headers end with a blank line Status-Line Header(s) ... ... -- blank line -- Content ... ... ...
What kind of entity/document How many bytes are in the document How the document is encoded When the document was last modified
HTTP/1.1 200 OK Date: Wed, 30 Jan 2002 12:48:17 EST Server: Apache/1. Content-Type: text/html Content-Length: 1756 Content-Encoding: gzip -- blank line -- 2309fjfjef0jefe0fje2f0je2f0je2f0e2jfe0fje fj2e0fjef0jef0e2jf0efje0fje02fje20fje2f0ejf 0jef2e09fj209g209fj20gag09ha0gh0agha0gjg0jg
Client sends a complete HTTP request Server sends back a complete HTTP response Server closes its socket
If the client needs another document (e.g. images, CSS, etc.), the client must open a new socket connection!
Multiple requests can be handled over a single TCP/IP socket connection The Keep-Alive: header is used to keep the connection alive