HTTP An overview Web Servers Clients and servers
HTTP – An overview
Web Servers Clients and servers communicate using the Hyper. Text Transfer Protocol (HTTP) n n Client and server establish TCP connection Client requests content Server responds with requested content Client and server close connection (usually) HTTP request Web client (browser) Web server HTTP response (content) Current version is HTTP/1. 1 n – 2– RFC 2616, June, 1999. 15 -213, F’ 02
URLs Each file managed by a server has a unique name called a URL (Universal Resource Locator) URLs http: //www. cs. cmu. edu: 80/index. html n n http: //www. cs. cmu. edu/index. html http: //www. cs. cmu. edu l Identifies a file called index. html, managed by a Web server at www. cs. cmu. edu that is listening on port 80. – 3– 15 -213, F’ 02
URLs General form: scheme: object-address n The scheme is often a communications protocol, such as telnet or ftp For the http protocol, the object-address is: fully qualified domain name/doc path For the file protocol, only the doc path is needed – 4– 15 -213, F’ 02
URLs Host name may include a port number, as in zeppo: 80 (80 is the default, so this is silly) URLs cannot include spaces or any of a collection of other special characters (semicolons, . . . ) The doc path may be abbreviated as a partial path n The rest is furnished by the server configuration If the doc path ends with a slash, it means it is a directory – 5– 15 -213, F’ 02
Web Content Web servers return content to clients n content: a sequence of bytes with an associated MIME (Multipurpose Internet Mail Extensions) type Example MIME types n n n text/html HTML document text/plain Unformatted text application/postscript Postcript document image/gif Binary image encoded in GIF format image/jpeg Binary image encoded in JPEG format – 6– 15 -213, F’ 02
Static and Dynamic Content The content returned in HTTP responses can be either static or dynamic. n Static content: content stored in files and retrieved in response to an HTTP request l Examples: HTML files, images, audio clips. n Dynamic content: content produced on-the-fly in response to an HTTP request l Example: content produced by a program executed by the server on behalf of the client. Bottom line: All Web content is associated with a file that is managed by the server. – 7– 15 -213, F’ 02
HTTP Requests HTTP request is a request line, followed by zero or more request headers Request line: <method> <uri> <version> n n n – 8– <version> is HTTP version of request (HTTP/1. 0 or HTTP/1. 1) <uri> is typically URL for proxies, URL suffix for servers. <method> is either GET, POST, OPTIONS, HEAD, PUT, DELETE, or TRACE. 15 -213, F’ 02
HTTP Requests (cont) HTTP methods: n GET: Retrieve static or dynamic content l Arguments for dynamic content are in URI l Workhorse method (99% of requests) n POST: Retrieve dynamic content l Arguments for dynamic content are in the request body n n n OPTIONS: Get server or file attributes HEAD: Like GET but no data in response body PUT: Write a file to the server! DELETE: Delete a file on the server! TRACE: Echo request in response body l Useful for debugging. – 9– 15 -213, F’ 02
HTTP Requests (cont) Request headers: <header name>: <header data> n – 10 – Provide additional information to the server. 15 -213, F’ 02
HTTP Response Form: Status line Response header fields blank line Response body Status line format: HTTP version status code explanation Example: HTTP/1. 1 200 OK (Current version is 1. 1) The header field, Content-type, is required – 11 – 15 -213, F’ 02
HTTP Responses HTTP response is a response line followed by zero or more response headers. Response line: <version> <status code> <status msg> n n <version> is HTTP version of the response. <status code> is numeric status. Response headers: <header name>: <header data> n n n – 12 – Provide additional information about response Content-Type: MIME type of content in response body. Content-Length: Length of content in response body. 15 -213, F’ 02
HTTP Status Codes n Status code is a three-digit number; first digit specifies the general status l l l n 1 => Informational 2 => Success 3 => Redirection 4 => Client error 5 => Server error <status msg> is corresponding English text. l 200 l 403 l 404 – 13 – OK Forbidden Not found Request was handled without error Server lacks permission to access file Server couldn’t find the file. 15 -213, F’ 02
GET Request GET /test. html HTTP/1. 1 Accept: */* Accept-Language: en-us Accept-Encoding: gzip, deflate User-Agent: Mozilla/4. 0 (compatible; MSIE 4. 01; Windows 98) Host: euro. ecom. cmu. edu Connection: Keep-Alive CRLF (rn) – 14 – 15 -213, F’ 02
GET Response From Apache Server HTTP/1. 1 200 OK Date: Thu, 22 Jul 1999 04: 02: 15 GMT Server: Apache/1. 3. 3 Ben-SSL/1. 28 (Unix) Last-Modified: Thu, 22 Jul 1999 03: 33: 21 GMT ETag: "48 bb 2 -4 f-37969101" Accept-Ranges: bytes Content-Length: 79 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/html CRLF <html> <head><title>Test page</title></head> <body> <h 1>Test page</h 1> </html> – 15 -213, F’ 02
- Slides: 15