Presentation is loading. Please wait.

Presentation is loading. Please wait.

Block 5: An application layer protocol: HTTP

Similar presentations


Presentation on theme: "Block 5: An application layer protocol: HTTP"— Presentation transcript:

1 Block 5: An application layer protocol: HTTP
Jin Sa 5-May-18 Client-Server Programming

2 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 5-May-18 Client-Server Programming

3 Client-Server Programming
HTTP overview 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 request PC running Explorer HTTP response HTTP request Server running Apache Web server HTTP response Mac running Navigator 5-May-18 Client-Server Programming

4 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 5-May-18 Client-Server Programming

5 Client-Server Programming
HTTP connections 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 5-May-18 Client-Server Programming

6 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 time to transmit file initiate TCP connection RTT request received time 5-May-18 Client-Server Programming

7 Client-Server Programming
Persistent HTTP 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 5-May-18 Client-Server Programming

8 HTTP request message format
ASCII (human-readable format) request line (GET, POST, HEAD commands) GET /somedir/page.html HTTP/1.1 Host: 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 5-May-18 Client-Server Programming

9 Commonly used HTTP Methods
GET: retrieve a file (95% of requests) HEAD: just get meta-data POST: submitting a form to a server 5-May-18 Client-Server Programming

10 HTTP response message format
status line (protocol status code status phrase) HTTP/ OK Connection: close Date: Thu, 06 Aug :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 5-May-18 Client-Server Programming

11 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 5-May-18 Client-Server Programming

12 Trying out HTTP (client side) for yourself
1. Telnet to your favorite Web server: telnet 80 Opens TCP connection to port 80 (default HTTP server port) at 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! 5-May-18 Client-Server Programming

13 Client-Server Programming
Web Proxy Caching origin server 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 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 5-May-18 Client-Server Programming

14 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. 5-May-18 Client-Server Programming

15 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 5-May-18 Client-Server Programming

16 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: …. 5-May-18 Client-Server Programming

17 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: The Web server sends response to the cache: HTTP/ OK Date: Thu, 7 Jul :39:29 Server: Apache/1.3.0(unix) Last-Modified: Mon, 4 Jul :23:25 Content-Type: image/gif (data data ….) 5-May-18 Client-Server Programming

18 How does Conditional GET work?-1a
origin server: Proxy server HTTP request HTTP request client HTTP response HTTP response 5-May-18 Client-Server Programming

19 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: If-modified-since: Mon, 4 Jul :23:25 Note the value of If-modified-since: is the same as the Last-Modified. 5-May-18 Client-Server Programming

20 How does Conditional GET work?-2a
origin server: Proxy server HTTP request HTTP request client HTTP response HTTP response HTTP request HTTP response client 5-May-18 Client-Server Programming

21 How does Conditional GET work?-3a
Cache Original server HTTP request msg If-modified-since: <date> object not modified HTTP response HTTP/1.1 304 Not Modified 5-May-18 Client-Server Programming

22 How does Conditional GET work?-3b
Cache Original server HTTP request msg If-modified-since: <date> object modified HTTP response HTTP/ OK <data data ..> 5-May-18 Client-Server Programming

23 Cookies: keeping “state”
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 5-May-18 Client-Server Programming

24 Cookies: keeping “state” (cont.)
client server usual http request msg usual http response + Set-cookie: 1678 cookie: 1678 usual http response msg cookie- specific action spectific Cookie file ebay: 8734 server creates ID 1678 for user entry in backend database Cookie file amazon: 1678 ebay: 8734 access one week later: access Cookie file amazon: 1678 ebay: 8734 5-May-18 Client-Server Programming

25 Client-Server Programming
Cookies (continued) 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 5-May-18 Client-Server Programming

26 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 5-May-18 Client-Server Programming


Download ppt "Block 5: An application layer protocol: HTTP"

Similar presentations


Ads by Google