0% found this document useful (0 votes)
13 views

Lecture 5

Uploaded by

Hamza tariq
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Lecture 5

Uploaded by

Hamza tariq
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 26

Computer Communications

& Networks
CSNC-2413

Lec: 5
• Web & HTTP Computer
Networking: A Top
Down Approach
6th edition
Jim Kurose, Keith Ross
Addison-Wesley
March 2012
Chapter 2: outline
2.1 Principles of network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic mail
 SMTP, POP3
2.5 DNS
2.6 P2P applications
2.7 Socket programming with UDP and TCP

2
Web and HTTP
First, a review…
 web page consists of a base HTML file
which may include several referenced objects
 object can be…
HTML file, JPEG image, Java applet, audio file, etc
 each object is addressable by a URL, e.g,

www.someschool.edu/someDept/page.html

host name path

3
HTTP overview
HTTP: Hypertext Transfer Protocol
 Web’s application layer protocol HT
TP
req
PC running ues
 HTTP implemented in two HT
T
t
Firefox browser Pr
programs; clients & servers es p
ons
e
 Client (browser) requests
t
web objects u es
req server
T P n se
 Server sends objects in response HT s po running
r e Apache Web
T TP
 HTTP defines messages exchanged H server

between client/server
iphone running
 structure of messages Safari browser
and their sequence

4
HTTP overview
HTTP uses TCP: HTTP is “stateless”
 HTTP client initiates TCP  server maintains no
connection to server at port 80 information about past
 HTTP server accepts TCP client requests
connection from client  simplifies design
 HTTP client/server then access
TCP thru their socket interfaces aside
 exchange HTTP messages
protocols that maintain “ state
” are complex!
 TCP provides reliable data delivery need to maintain past history
to HTTP (state)
 HTTP need not worry about data
loss, re-ordering

5
HTTP connections
Non-persistent HTTP Persistent HTTP
 at most one object sent over  multiple objects can be sent
a TCP connection over single TCP connection
 connection then closed between
client & server
 downloading multiple
objects requires multiple
connections

6
Non-persistent HTTP
(contains text,
suppose user enters URL: references to 10
www.someSchool.edu/someDept/page.html jpeg images)

1a. HTTP client initiates TCP 1b. HTTP server at host


connection to HTTP server at www.someSchool.edu
host www.someSchool.edu waiting for TCP connection at
on port 80 port 80; “ accepts”
connection, notify client
2. HTTP client sends HTTP
request message (containing 3. HTTP server receives request
URL) into TCP connection socket message,
Message indicates that client forms response message
wants the object containing the object,
SomeDept/page.html and sends message into its
time socket
7
Non-persistent HTTP

4. HTTP server closes TCP


connection
5. HTTP client receives response
message containing html file,
displays html
Parses html file, finds 10
referenced jpeg objects
time

6. Steps 1- 5 repeated for each of


10 jpeg objects

8
Non-persistent HTTP: response time
RTT : time for a small packet to travel from client to server, & back

HTTP response time:


 1 RTT to initiate TCP conn
initiate TCP
 1 RTT for HTTP request & connection
first few bytes of HTTP RTT
response to return request
file
 file Tx time time
RTT to
 Non-persistent HTTP response Tx
file
time = file
received
2RTT+ file Tx time
time time

9
Persistent HTTP
Persistent HTTP:
Non-persistent HTTP
issues:  server leaves TCP connection
open after sending response
 requires 2 RTTs per object
 subsequent HTTP messages
 OS overhead for each TCP between same client/server sent
connection over open connection
 browsers often open  client sends requests as soon as it
parallel TCP connections to encounters a referenced object
fetch referenced objects
 as little as 1 RTT for all the
referenced objects

10
HTTP request message
 Two types of HTTP messages: Request, Response
 HTTP Request Message general format

11
HTTP request message
 HTTP Request message - Example:
 ASCII (human-readable format)
 If user enters URL: www.someSchool.edu/someDept/page.html

carriage return character


line-feed character
request line
(GET, POST,
HEAD methods) GET /someDept/page.html HTTP/1.1\r\n
Host: www.someSchool.edu\r\n
headerConnection: close\r\n
lines
User-Agent: Mozilla/4.0\r\n
carriage return, Accept-Language: fr\r\n
line feed at start
of line indicates \r\n
end of header lines

12
HTTP Methods
 Some of the common HTTP request methods…

13
Uploading form input
POST method:
 web page often includes form input (e.g, user input data)
 input is uploaded to server in entity body

URL method:
 uses GET method
 input is uploaded in URL field of request line:
www.somesite.com/animalsearch?monkeys&banana

14
Method types
HTTP/1.0: HTTP/1.1:
 GET  GET, POST, HEAD
 POST  PUT
 HEAD  uploads file in entity body to
path specified in URL field
 DELETE
 deletes file specified in the
URL field

15
HTTP response message: general format

16
HTTP response message
status line
(version,
status code,
status phrase) HTTP/1.1 200 OK\r\n
Connection: close\r\n
Date: Sat, 07 Jul 2007 12:00:15 GMT\r\n
header Server: Apache/1.3.0 (Unix)\r\n
lines
Last-Modified: Sun, 06 May 2007 09:23:24 GMT\r\n
Content-Length: 6821\r\n
Content-Type: text/html\r\n
\r\n
data, e.g., data data data data data ...
requested
HTML file

17
HTTP response status codes
 status code appears in 1st line in server-to-client response message
 some sample codes:

 200 OK
request succeeded, requested object later in this msg
 301 Moved Permanently
requested object moved, new location specified later in
this msg (Location:)
 400 Bad Request
request msg not understood by server
 404 Not Found
requested document not found on this server
 505 HTTP Version Not Supported
18
Cookies
 HTTP server is stateless
 Web sites often need to identify users
 to restrict access
 to serve content as function of user identity
 HTTP uses Cookies (unique ID): allow sites to track users
 used by most major web sites

Cookie Components:
1) cookie header line in HTTP response message
2) cookie header line in next HTTP request message
3) cookie file kept on user’s host, managed by user’s browser
4) back-end database at Web site
19
Cookies: keeping “ state”
Example:
 User visits a specific e-commerce site for first time
 When initial HTTP request arrives at site, it creates:
 unique ID (cookie)
 entry in backend database for ID
 sends ID back to user

 User’s browser adds the cookie to cookie file


 Now, as User accesses the web site, cookie is sent in HTTP
Request message
 site identifies the user
 takes cookie specific action

20
Cookies: keeping “ state”

21
Cookies
What cookies can be used
for:
cookies and privacy:
authorization
 cookies permit sites to learn
shopping carts about you…
 you may supply name, e-
recommendations
mail, account info, to sites
usersession state  info may be misused
(Web e-mail)

22
Web caches (proxy server)
Goal: satisfy client request without involving origin server
 user sets browser:
web access via cache
 browser sends all HTTP HT proxy
TP ue st
requests to cache req server req
HT ues P se
client TP t H TT p on
res res origin
 if, object in cache: pon
se TP server
HT
cache returns object u est
req e
T P o ns
 else, cache requests object HT
res
p
TP
from origin server, then H T
returns object to client
client origin
server

23
More about Web caching
 Cache acts as both client and Why Web caching?
server  reduce response time
 as server, to original for client request
requesting client  reduce traffic
 as client, to origin server on an institution’s access
 Typically cache is installed link
by ISP (university, company,
residential ISP)
 Limitation: copy of cached
object may be stale…

24
More about Web caching

Bottleneck between institutional Cache added to institutional network


network & Internet
25
Conditional GET
cache server
client
 Goal: don’t send object if
cache has up-to-date cached
version
HTTP request msg
 no object Tx delay If-modified-since: <date> object
not
 better link utilization modified
HTTP response since
 Cache: specify date of cached HTTP/1.0 <date>
copy in HTTP request 304 Not Modified

If-modified-since: <date>

 Server: response contains no


object if cached copy is up-to- HTTP request msg
If-modified-since: <date> object
date: modified
HTTP/1.0 304 Not Modified since
HTTP response
<date>
HTTP/1.0 200 OK
<data>
26

You might also like