Transcript module_21
Module 2.1: Application Layer
• Application-level protocols provide high-level services
–
–
–
–
–
–
–
–
–
K. Salah
Web and HTTP
DNS
Electronic mail
Remote login
FTP
telnet
SNMP
Multimedia - VoIP
All of these applications use client-server
architecture
1
World Wide Web
• Hypertext model (HTML)
• Use of hypertext in World Wide Web (WWW)
• WWW client-server model
• Use of TCP/IP protocols in WWW
• Nice tutorials on HTML and HTTP can be found on
course web source in resources section.
K. Salah
2
Identifying a page
•
•
Page identified by:
– Protocol used to access page
– Computer on which page is stored
– TCP port to access page
– Pathname of file on server
Specific syntax for Uniform Resource Locator (URL):
protocol://computer_name:port/document_name
– Protocol can be http, ftp, file, mailto
– Computer name is DNS name
– (Optional) port is TCP port
– document_name is path on computer to page
K. Salah
3
Client Architecture
•
Browser has the following
components:
Display driver for painting
screen
HTML interpreter for
HTML-formatted documents
Other interpreters (e.g.,
Shockwave, JVM, VB
runtime environment) for
other items
HTTP client to fetch HTML
documents from WWW
server
Other clients for other
protocols (e.g., ftp, telnet)
Controller to accept input
from user
– Must be multi-threaded
K. Salah
4
HTTP overview
HTTP: hypertext transfer
protocol
•
•
•
•
Web’s application layer
protocol
PC running
Explorer
client/server model
– client: browser that
requests, receives,
“displays” Web objects
– server: Web server sends
objects in response to
requests
Server
running
Apache Web
server
HTTP 1.0: RFC 1945
HTTP 1.1: RFC 2068
K. Salah
Mac running
Navigator
5
HTTP overview (continued)
Uses TCP (socket programming):
•
•
•
•
•
•
•
Server listens on port 80 or 8080 for
accepting connections from client
HTTP is “stateless”
client initiates TCP connection (creates
socket) to server, port 80
•
server accepts TCP connection from client,
and creates thread to handle accepted
connection
Connection is established now between client
and server thread
HTTP messages between Client and Server
are exchanged
•
TCP connection closed
•
Meanwhile server keeps listening for new
connections
• We will illustrate this
aside
further in TCP layer.
K. Salah
6
server maintains no
information about past
client requests, as each
request is process
independently, without
knowledge of the old
requests.
Server does not know who
the client is?
Or is it?
Sample HTTP1.0 Exchange
To retrieve the file at the URL http://www.somehost.com/path/file.html
first open a socket to the host www.somehost.com, port 80 (use the default port of 80
because none is specified in the URL). Then, send something like the following through
the socket:
GET /path/file.html HTTP/1.0
From: [email protected]
User-Agent: HTTPTool/1.0
[blank line here]
The server should respond with something like the following, sent back through
the same socket:
HTTP/1.0 200 OK
Date: Fri, 31 Dec 1999 23:59:59 GMT
Content-Type: text/html Content-Length: 1354
<html>
<body>
<h1>Happy New Millennium!</h1>
(more file contents)
.
.
</body>
</html>
After sending the response, the server closes the socket servicing only one request per connection.
K. Salah
7
HTTP request message: general format
K. Salah
8
HTTP request message
• two types of HTTP messages: request, response
• 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
header Connection: close
lines Accept-language:fr
Carriage return,
line feed
indicates end
of message
K. Salah
(extra carriage return, line feed)
9
HTTP response message
status line
(protocol
status code
status phrase)
header
lines
data, e.g.,
requested
HTML file
K. Salah
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 ...
10
HTTP connections
Nonpersistent HTTP
Persistent HTTP
• At most one object is
• Multiple objects can be sent
sent over a TCP
connection.
over single TCP connection
between client and server.
• HTTP/1.0 uses
• HTTP/1.1 uses persistent
nonpersistent HTTP
connections in default mode
with pipelining.
• Without pipelining client has to
•
•
issue one request at a time. It
can not issue a new request until
it receives the response of the
previous one.
What is?
• With pipelining client doesn’t
HTTP Transaction
– HTTP request and response
have to wait for first response.
Client can request multiple
objects.
HTTP Hit
– For server statistics
– Server sends one object to client
K. Salah
11
HTTP 1.1 and higher
•
•
As of early 1997, the Web is moving from HTTP 1.0 to HTTP 1.1. Whenever
practical, use HTTP 1.1. It's more efficient overall. WHY?
HTTP1.0 Client Request
telnet www.ccse.kfupm.edu.sa 80
GET http://www.ccse.kfupm.edu.sa/~salah/ics432/index.html
•
HTTP1.1 Client Request
telnet www.ccse.kfupm.edu.sa 80
GET http://www.ccse.kfupm.edu.sa/~salah/ics432/index.html HTTP/1.1
Host: www.ccse.kfupm.edu.sa:80
•
HTTP1.2 Client Request
telnet www.ccse.kfupm.edu.sa 80
GET http://www.ccse.kfupm.edu.sa/~salah/ics432/index.html HTTP/1.2
No need to have Host: field for every request.
K. Salah
12
Uploading form input
Post method:
• Web page often includes
form input
• 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
K. Salah
13
Method types
HTTP/1.0
HTTP/1.1
• GET
• POST
• HEAD
• GET, POST, HEAD
• PUT
– asks server to leave
requested object out
of the response.
Headers is only sent.
Used for debugging.
K. Salah
14
– uploads file in entity
body to path
specified in URL
field
• DELETE
– deletes file
specified in the URL
field
Cookies: keeping “state”
Many major Web sites use
cookies
Example:
– Susan access Internet
always from same PC
– She visits a specific ecommerce 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
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
K. Salah
15
Cookies: keeping “state” (cont.)
client
Cookie file
ebay: 8734
Cookie file
amazon: 1678
ebay: 8734
one week later:
Cookie file
amazon: 1678
ebay: 8734
K. Salah
server
usual http request msg
usual http response +
Set-cookie: 1678
usual http request msg
cookie: 1678
usual http response msg
usual http request msg
cookie: 1678
usual http response msg
16
Amazon server
creates ID
1678 for user
cookiespecific
action
cookiespectific
action
Cookies (continued)
Cookies and privacy:
What cookies can bring:
aside
• cookies permit sites to learn
• authorization
• shopping carts
• recommendations
• user session state (Web e-
a lot about you
• you may supply name and email to sites
• search engines use
mail)
redirection & cookies to
learn yet more
• advertising
companies
obtain info across sites
K. Salah
17
Web caches (proxy server)
Goal: satisfy client request without involving origin server
•
•
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
Web proxies can be multipurpose:
•
•
•
•
client
client
cache,
Firewall
Monitor and log activites
NAT
K. Salah
18
origin
server
Proxy
server
origin
server
More about Web caching
•
•
•
•
•
Local cache can be used to
hold copies of visited pages
Why Web caching?
•
Cache acts as both client and
server
•
Cache can do up-to-date
check using If-modifiedsince HTTP header
HTTP response messages has
Age header.
– Specifies how long the
info is valid for.
•
Typically cache is installed by
ISP (university, company,
residential ISP)
K. Salah
19
Reduce response time for
client request.
Downloading HTML
documents from servers may
be slow
– Internet congested
– Dialup connection
– Server busy
Reduce traffic on an
institution’s access link.
Conditional GET: client-side caching
•
•
•
Goal: don’t send object if
client has up-to-date cached
version
server
client
HTTP request msg
client: specify date of cached
copy in HTTP request
If-modified-since: <date>
If-modified-since:
<date>
server: response contains no
object if cached copy is up-todate:
HTTP/1.0 304 Not
Modified
HTTP/1.0
304 Not Modified
HTTP response
HTTP request msg
If-modified-since:
<date>
This is basically what happens
when you hit “Refresh” or
“update” button on the
browser, I.e. GET with Ifmodified-since of current
date.
K. Salah
object
not
modified
HTTP response
HTTP/1.0 200 OK
<data>
20
object
modified