260 likes | 266 Vues
This block provides an overview of HTTP, HTTP connections, message format, web caching, and cookies. It is based on the book "Computer Networking: A Top Down Approach" by Kurose and Ross.
E N D
Block 5: An application layer protocol: HTTP Jin Sa Client-Server Programming
Outline of block 4 • An overview of HTTP • HTTP connections • HTTP Message Format • Web Caching • Cookies Most of this block is based on chapter 2 of “Computer Networking: A Top Down Approach” by Kurose and Ross, and some lecture slides by Anirban Mahanti Client-Server Programming
HTTP: hypertext transfer protocol Web’s application layer protocol client/server model client: browser that requests, receives, “displays” Web objects server: Web server sends objects in response to requests HTTP 1.0: RFC 1945 HTTP 1.1: RFC 2616 HTTP overview HTTP request PC running Explorer HTTP response HTTP request Server running Apache Web server HTTP response Mac running Navigator Client-Server Programming
HTTP Overview Uses TCP: • client initiates TCP connection (creates socket) to server, port 80 • server accepts TCP connection from client • HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server) • TCP connection closed Client-Server Programming
Non-persistent HTTP At most one object is sent over a TCP connection. HTTP/1.0 uses non-persistent HTTP Persistent HTTP Multiple objects can be sent over single TCP connection between client and server. HTTP/1.1 allows persistent connections HTTP connections Client-Server Programming
initiate TCP connection RTT request file time to transmit file RTT file received time time Response time modeling Definition of RTT (round-trip time): time to send a small packet to travel from client to server and back. Response time: • one RTT to initiate TCP connection • one RTT for HTTP request and first few bytes of HTTP response to return • file transmission time total = 2RTT+transmit time Client-Server Programming
Nonpersistent HTTP issues: requires 2 RTTs per object OS must work and allocate host resources for each TCP connection (but browsers often open parallel TCP connections to fetch referenced objects) Persistent HTTP server leaves connection open after sending response subsequent HTTP messages between same client/server are sent over connection Persistent HTTP Client-Server Programming
HTTP request message format • HTTP request message: • ASCII (human-readable format) request line (GET, POST, HEAD commands) GET /somedir/page.html HTTP/1.1 Host: www.someschool.edu User-agent: Mozilla/4.0 Connection: close Accept-language:fr (extra carriage return, line feed) header lines Carriage return, line feed indicates end of message Client-Server Programming
Commonly used HTTP Methods • GET: retrieve a file (95% of requests) • HEAD: just get meta-data • POST: submitting a form to a server Client-Server Programming
HTTP response message format status line (protocol status code status phrase) HTTP/1.1 200 OK Connection: close Date: Thu, 06 Aug 1998 12:00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 …... Content-Length: 6821 Content-Type: text/html data data data data data ... header lines data, e.g., requested HTML file Client-Server Programming
Some common HTTP Response Status Codes • 200 OK: request succeeded, information returned in response. • 301 Moved Permanently: • 400 Bad Request: generic error code, request not understood by server • 404 Not Found: requested object not on server • 505 HTTP Version Not Supported Client-Server Programming
1. Telnet to your favorite Web server: Trying out HTTP (client side) for yourself telnet www.cems.uwe.ac.uk 80 Opens TCP connection to port 80 (default HTTP server port) at www.cems.uwe.ac.uk • 2. Type in a GET HTTP request: GET /~jsa/index.html HTTP/1.0 By typing this in (hit carriage return twice), you send this minimal (but complete) GET request to HTTP server 3. Look at response message sent by HTTP server! Client-Server Programming
user sets browser: Web accesses via cache browser sends all HTTP requests to cache If object in cache => cache hit: returns object else cache requests object from origin server, then returns object to client Web Proxy Caching origin server Proxy server HTTP request HTTP request client HTTP response HTTP response HTTP request HTTP request HTTP response HTTP response client origin server Cache acts as both client and server Client-Server Programming
Why Cache? • Reduce response time for client request. • Reduce traffic on an institution’s access link (from router to the Internet) • Reduce Web traffic in the Internet as a whole, therefore improving performance for all applications. Client-Server Programming
Problem with Web caching • Copy of object in the cache may be out of date, i.e. the object on the original server is modified after the copy is cached. • To solve this problem, HTTP has a mechanism called Conditional GET Client-Server Programming
Conditional GET • An HTTP request is a conditional GET if • The request message uses a GET method • The request message contains the following header line: If-Modified-Since: …. Client-Server Programming
How does Conditional GET work?-1 • On behalf of a requesting browse, a proxy cache sends a request message to a Web server: GET /fruit/kiwi.gif HTTP/1.1 Host: www.goodies.com • The Web server sends response to the cache: HTTP/1.1 200 OK Date: Thu, 7 Jul 2007 15:39:29 Server: Apache/1.3.0(unix) Last-Modified: Mon, 4 Jul 2007 09:23:25 Content-Type: image/gif (data data ….) Client-Server Programming
How does Conditional GET work?-1a origin server: www.goodies.com Proxy server HTTP request HTTP request client HTTP response HTTP response Client-Server Programming
How does Conditional GET work?-2 • Later, another object requests the same object via the cache. • Object still in cache, but it may be changed on the original Web server, so, cache performs an up-to-date check by issuing a conditional GET: GET /fruit/kiwi.gif HTTP/1.1 Host: www.goodies.com If-modified-since: Mon, 4 Jul 2007 09:23:25 • Note the value of If-modified-since: is the same as the Last-Modified. Client-Server Programming
How does Conditional GET work?-2a origin server: www.goodies.com Proxy server HTTP request HTTP request client HTTP response HTTP response HTTP request HTTP response client Client-Server Programming
HTTP response HTTP/1.1 304 Not Modified How does Conditional GET work?-3a Original server Cache HTTP request msg If-modified-since: <date> object not modified Client-Server Programming
How does Conditional GET work?-3b Original server Cache HTTP request msg If-modified-since: <date> object modified HTTP response HTTP/1.1 200 OK <data data ..> Client-Server Programming
Many major Web sites use cookies Four components: 1) cookie header line in the HTTP response message 2) cookie header line in HTTP request message 3) cookie file kept on user’s host and managed by user’s browser 4) back-end database at Web site Example: Susan access Internet always from same PC She visits a specific e-commerce site for first time When initial HTTP requests arrives at site, site creates a unique ID and creates an entry in backend database for ID Cookies: keeping “state” Client-Server Programming
client server usual http request msg usual http response + Set-cookie: 1678 Cookie file Cookie file Cookie file amazon: 1678 ebay: 8734 amazon: 1678 ebay: 8734 ebay: 8734 cookie- specific action usual http request msg cookie: 1678 usual http request msg cookie: 1678 usual http response msg usual http response msg cookie- spectific action Cookies: keeping “state” (cont.) server creates ID 1678 for user entry in backend database access access one week later: Client-Server Programming
Cookies can simplify the Internet shopping experience, e.g. shopping cart But, They can also be considered as an invasion to privacy, a web site can learn a lot about a user Cookies (continued) Client-Server Programming
Web & HTTP • The major application on the Internet • A large fraction of traffic is HTTP • Client/server model: • Clients make requests, servers respond to them • Done mostly in ASCII text (helps debugging!) • Various headers and commands • Web Caching & Performance Client-Server Programming