You are on page 1of 18

Chapter 2 Application Layer

Computer Networking: A Top Down Approach,

4th edition. Jim Kurose, Keith Ross Addison-Wesley, July 2007.

HTTP overview (continued)


Uses TCP: Client initiates TCP connection 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) Advantage of Layered architecture HTTP does not worry about lost data or how TCP recovers from loss HTTP is stateless Server maintains no information about past client requests

HTTP connections
Nonpersistent HTTP At most one object is sent over a TCP connection. Persistent HTTP Multiple objects can be sent over single TCP connection between client and server.

Nonpersistent HTTP
(contains text, Suppose user enters URL references to 10 www.someSchool.edu/someDepartment/home.index jpeg images)

1a. HTTP client initiates TCP

connection to HTTP server (process) at www.someSchool.edu on port 80

1b. HTTP server at host


www.someSchool.edu waiting for TCP connection at port 80. accepts connection, notifying client

2. HTTP client sends HTTP


request message (containing URL) into TCP connection socket. Message indicates that client wants object someDepartment/home.index
time

3. HTTP server receives request


message, forms response message containing requested object, and sends message to the client

Nonpersistent HTTP (cont.)


4. HTTP server closes TCP 5. HTTP client receives response
message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects
connection.

time

6. Steps 1-4 repeated for each


of 10 jpeg objects

When the user requests the webpage 11 TCP connections are generated

Non-Persistent HTTP: Response time


Definition of RTT: time for a packet to travel from client to server and back. Response time: one RTT to initiate TCP connection one RTT for HTTP request response
total = 2RTT+transmit

initiate TCP connection

RTT
request file RTT file received time time to transmit file

time

time

Persistent HTTP
Nonpersistent HTTP issues: Requires 2 RTTs per object Maintain TCP buffers in both client and server Burden on the Web Server High overhead Persistent HTTP Server leaves TCP connection open after sending response Subsequent HTTP messages between same client/server sent over open connection Default mode is Persistent with pipelining

HTTP Request Message


Two types of HTTP messages: Request, Response HTTP request message: Human-readable format A typical HTTP request message GET /somedir/page.html HTTP/1.1 Host: www.someschool.edu User-agent: Mozilla/4.0 Connection: close Accept-language:fr (Blank Line) Body

HTTP Request Message


Request Line

First Line of HTTP request message The request line has three fields Method field can take on several values GET,POST, PUT, DELETE etc Majority of HTTP request messages use GET URL field HTTP version field Header Lines Host: Host on which the object resides User-agent: Identifies the client program e.g. Mozilla/4.0 Connection: Shows whether the connection should be closed or not Accept-language: Shows the language the client prefers

HTTP Request Message


Body is empty with

GET method Used with the POST method Web page often includes form input Input is sent to server in body

PUT method: To upload objects to web server DELETE method Allows a user or an application to delete an object on web server

Find out about OPTIONS, TRACE, HEAD?

HTTP Response Message


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
Body contains Requested Object

HTTP Response Message


Status Line Protocol Version Status Code and Status Message
The status code and associated phrase indicate the result of the request

Header Line Connection: Shows whether the connection should be closed or not Date and time: When the HTTP response was created Server: Analogous to user-agent in request message Last-modified: When the Object was last created or modified Content-length: Number of bytes in object being sent Content-Type: Indicates the object type (HTML text etc.)

HTTP Response Status Codes


The status code and associated phrase indicate the result of the request

200 OK

Request succeeded and information is returned in response Requested object moved, new location specified later in this message (Location:) Request message not understood by server Requested document not found on this server

301 Moved Permanently

400 Bad Request

404 Not Found

505 Version not supported

HTTP version is not supported by the server

User-Server Interaction: Cookies


It is often desirable for web

servers to identify users Server wishes to restrict user access Wants to serve content as a function of user identity Many major Web sites use cookies

Four components:
1) Cookie header line of HTTP response message 2) Cookie header line in HTTP request message 3) Cookie file kept on users host, managed by users browser 4) Back-end database at Web site

Example: Susan accesses Internet always from PC visits specific ecommerce site for first time When initial HTTP requests arrives at server, server creates: unique ID entry in backend database for ID

Cookies: keeping state (cont.)


Client Server

usual http request msg

cookie file
amazon 1678

Set-cookie: 1678
usual http request msg

usual http response

Amazon server creates ID 1678 for user create

entry

cookie: 1678

one week later:


amazon 1678

usual http response msg usual http request msg

cookiespecific action
cookiespectific action

access

access

backend database

cookie: 1678

usual http response msg

Cookies (continued)
Cookies Pages visited in which order and at what times Shopping carts One click shopping Recommendations of other products Cookies and privacy: Cookies permit sites to learn a lot about you Can inform third party You may supply name and e-mail to sites

For more info on Cookies see RFC-2965 HTTP State Management Mechanism www.cookiecentral.com

Web Caches (Proxy Server)


Goal: Satisfy client request without involving origin server Web Cache has its own disk storage Keeps copies of recently requested objects in storage User sets browser: Web accesses via cache Browser sends all HTTP requests to cache object in cache: cache returns object else cache requests object from origin server, then returns object to client Origin Server Proxy Server

Client

Client

More about Web Caching


Cache acts as both client and server Typically cache is installed by ISP (university, company) Why Web Caching? Reduce response time for client request Reduce traffic on an institutions access link.
Does not have to upgrade bandwidth as quickly, thereby reducing costs.

You might also like