user

advertisement
HTTP response status codes
In first line in server->client response message.
A few sample codes:
200 OK

request succeeded, requested object later in this message
301 Moved Permanently

requested object moved, new location specified later in
this message (Location:)
400 Bad Request

request message not understood by server
404 Not Found

requested document not found on this server
505 HTTP Version Not Supported
2: Application Layer
1
Trying out HTTP (client side) for yourself
1. Telnet to your favorite Web server:
telnet www.eurecom.fr 80 Opens TCP connection to port 80
(default HTTP server port) at www.eurecom.fr.
Anything typed in sent
to port 80 at www.eurecom.fr
2. Type in a GET HTTP request:
GET /~ross/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!
2: Application Layer
2
User-server interaction: authorization
Authorization : control access to
server
client
server content
usual http request msg
ˆ authorization credentials:
typically name, password
401: authorization req.
WWW authenticate:
ˆ stateless: client must present
authorization in each request
 authorization: header line in
usual http request msg
+ Authorization: <cred>
each request
 if no authorization: header,
usual http response msg
server refuses access,
sends
WWW authenticate:
header line in response
usual http request msg
+ Authorization: <cred>
usual http response msg
time
2: Application Layer
3
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 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
2: Application Layer
4
Cookies: keeping “state” (cont.)
client
usual http request msg
usual http response +
ebay: 8734
Cookie file
amazon: 1678
ebay: 8734
Set-cookie: 1678
usual http request msg
cookie: 1678
usual http response msg
Cookie file
amazon: 1678
ebay: 8734
e
cookiespecific
action
ac ce
ss
ac
ce
one week later:
n
server
da try i
tab n b
creates ID
as ac
e
ke
nd
1678 for user
ss
Cookie file
server
usual http request msg
cookie: 1678
usual http response msg
cookiespectific
action
2: Application Layer
5
Cookies (continued)
What cookies can bring:
ˆ authorization
ˆ shopping carts
ˆ recommendations
ˆ user session state
(Web e-mail)
aside
Cookies and privacy:
ˆ cookies permit sites to
learn a lot about you
ˆ you may supply name
and e-mail to sites
ˆ search engines use
redirection & cookies
to learn yet more
ˆ advertising companies
obtain info across
sites
2: Application Layer
6
Conditional GET: client-side caching
ˆ Goal: don’t send object if
client has up-to-date cached
version
ˆ client: specify date of
cached copy in HTTP request
If-modified-since:
<date>
ˆ server: response contains no
object if cached copy is upto-date:
HTTP/1.0 304 Not
Modified
server
client
HTTP request msg
If-modified-since:
<date>
HTTP response
object
not
modified
HTTP/1.0
304 Not Modified
HTTP request msg
If-modified-since:
<date>
HTTP response
object
modified
HTTP/1.0 200 OK
<data>
2: Application Layer
7
Chapter 2 outline
ˆ
2.1 Principles of app
layer protocols


clients and servers
app requirements
2.2 Web and HTTP
ˆ 2.3 FTP
ˆ 2.4 Electronic Mail
ˆ

ˆ
SMTP, POP3, IMAP
2.5 DNS
2.6 Socket programming
with TCP
ˆ 2.7 Socket programming
with UDP
ˆ 2.8 Building a Web
server
ˆ 2.9 Content distribution
ˆ



Network Web caching
Content distribution
networks
P2P file sharing
2: Application Layer
8
FTP: the file transfer protocol
user
at host
FTP
FTP
user
client
interface
file transfer
local file
system
FTP
server
remote file
system
ˆ transfer file to/from remote host
ˆ client/server model

client: side that initiates transfer (either to/from
remote)
 server: remote host
ˆ ftp: RFC 959
ˆ ftp server: port 21
2: Application Layer
9
FTP: separate control, data connections
TCP control connection
port 21
ˆ FTP client contacts FTP
ˆ
ˆ
ˆ
ˆ
server at port 21, specifying
TCP as transport protocol
Client obtains authorization
over control connection
Client browses remote
directory by sending
commands over control
connection.
When server receives a
command for a file transfer,
the server opens a TCP data
connection to client
After transferring one file,
server closes connection.
FTP
client
TCP data connection
port 20
FTP
server
ˆ Server opens a second TCP
data connection to transfer
another file.
ˆ Control connection: “out of
band”
ˆ FTP server maintains “state”:
current directory, earlier
authentication
2: Application Layer
10
FTP commands, responses
Sample commands:
Sample return codes
ˆ sent as ASCII text over
ˆ status code and phrase (as
control channel
ˆ USER username
ˆ PASS password
ˆ LIST return list of file in
ˆ
ˆ
current directory
ˆ RETR filename retrieves
ˆ
ˆ STOR filename stores
ˆ
(gets) file
(puts) file onto remote
host
in HTTP)
331 Username OK,
password required
125 data connection
already open;
transfer starting
425 Can’t open data
connection
452 Error writing
file
2: Application Layer
11
Chapter 2 outline
ˆ
2.1 Principles of app
layer protocols


clients and servers
app requirements
2.2 Web and HTTP
ˆ 2.3 FTP
ˆ 2.4 Electronic Mail
ˆ

ˆ
SMTP, POP3, IMAP
2.5 DNS
2.6 Socket programming
with TCP
ˆ 2.7 Socket programming
with UDP
ˆ 2.8 Building a Web
server
ˆ 2.9 Content distribution
ˆ



Network Web caching
Content distribution
networks
P2P file sharing
2: Application Layer
12
Electronic Mail
outgoing
message queue
user mailbox
user
agent
Three major components:
ˆ user agents
ˆ mail servers
mail
server
SMTP
ˆ simple mail transfer
protocol: SMTP
User Agent
ˆ a.k.a. “mail reader”
ˆ composing, editing, reading
mail messages
ˆ e.g., Eudora, Outlook, elm,
Netscape Messenger
ˆ outgoing, incoming messages
stored on server
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
2: Application Layer
13
Electronic Mail: mail servers
user
agent
Mail Servers
ˆ mailbox contains incoming
messages for user
ˆ message queue of outgoing
(to be sent) mail messages
ˆ SMTP protocol between mail
servers to send email
messages
 client: sending mail
server
 “server”: receiving mail
server
mail
server
SMTP
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
2: Application Layer
14
Electronic Mail: SMTP [RFC 2821]
ˆ uses TCP to reliably transfer email message from client
to server, port 25
ˆ direct transfer: sending server to receiving server
ˆ three phases of transfer
 handshaking (greeting)
 transfer of messages
 closure
ˆ command/response interaction
 commands: ASCII text
 response: status code and phrase
ˆ
messages must be in 7-bit ASCII
2: Application Layer
15
Scenario: Alice sends message to Bob
1) Alice uses UA to compose
message and “to”
bob@someschool.edu
2) Alice’s UA sends message
to her mail server; message
placed in message queue
3) Client side of SMTP opens
TCP connection with Bob’s
mail server
1
user
agent
2
mail
server
3
4) SMTP client sends Alice’s
message over the TCP
connection
5) Bob’s mail server places the
message in Bob’s mailbox
6) Bob invokes his user agent
to read message
mail
server
4
5
6
user
agent
2: Application Layer
16
Sample SMTP interaction
S:
C:
S:
C:
S:
C:
S:
C:
S:
C:
C:
C:
S:
C:
S:
220 hamburger.edu
HELO crepes.fr
250 Hello crepes.fr, pleased to meet you
MAIL FROM: <alice@crepes.fr>
250 alice@crepes.fr... Sender ok
RCPT TO: <bob@hamburger.edu>
250 bob@hamburger.edu ... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Do you like ketchup?
How about pickles?
.
250 Message accepted for delivery
QUIT
221 hamburger.edu closing connection
2: Application Layer
17
Try SMTP interaction for yourself:
ˆ
telnet servername 25
ˆ see 220 reply from server
ˆ enter HELO, MAIL FROM, RCPT TO, DATA, QUIT
commands
above lets you send email without using email client
(reader)
2: Application Layer
18
SMTP: final words
ˆ SMTP uses persistent
connections
ˆ SMTP requires message
(header & body) to be in 7bit ASCII
ˆ SMTP server uses
CRLF.CRLF to determine
end of message
Comparison with HTTP:
ˆ HTTP: pull
ˆ SMTP: push
ˆ both have ASCII
command/response
interaction, status codes
ˆ HTTP: each object
encapsulated in its own
response msg
ˆ SMTP: multiple objects
sent in multipart msg
2: Application Layer
19
Mail message format
SMTP: protocol for
exchanging email msgs
RFC 822: standard for text
message format:
ˆ header lines, e.g.,



To:
From:
Subject:
header
blank
line
body
different from SMTP
commands!
ˆ body

the “message”, ASCII
characters only
2: Application Layer
20
Message format: multimedia extensions
ˆ MIME: multimedia mail extension, RFC 2045, 2056
ˆ additional lines in msg header declare MIME content
type
MIME version
method used
to encode data
multimedia data
type, subtype,
parameter declaration
encoded data
From: alice@crepes.fr
To: bob@hamburger.edu
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data .....
.........................
......base64 encoded data
2: Application Layer
21
MIME types
Content-Type: type/subtype; parameters
Text
Video
ˆ example subtypes: plain,
ˆ example subtypes: mpeg,
html
Image
ˆ example subtypes: jpeg,
gif
Audio
ˆ exampe subtypes: basic
quicktime
Application
ˆ other data that must be
processed by reader
before “viewable”
ˆ example subtypes:
msword, octet-stream
(8-bit mu-law encoded),
32kadpcm (32 kbps
coding)
2: Application Layer
22
Multipart Type
From: alice@crepes.fr
To: bob@hamburger.edu
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=StartOfNextPart
--StartOfNextPart
Dear Bob, Please find a picture of a crepe.
--StartOfNextPart
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data .....
.........................
......base64 encoded data
--StartOfNextPart
Do you want the reciple?
2: Application Layer
23
Mail access protocols
user
agent
SMTP
SMTP
sender’s mail
server
access
protocol
user
agent
receiver’s mail
server
ˆ SMTP: delivery/storage to receiver’s server
ˆ Mail access protocol: retrieval from server



POP: Post Office Protocol [RFC 1939]
• authorization (agent <-->server) and download
IMAP: Internet Mail Access Protocol [RFC 1730]
• more features (more complex)
• manipulation of stored msgs on server
HTTP: Hotmail , Yahoo! Mail, etc.
2: Application Layer
24
POP3 protocol
authorization phase
ˆ client commands:
user: declare username
 pass: password
ˆ server responses
 +OK


-ERR
transaction phase, client:
ˆ list: list message numbers
ˆ retr: retrieve message by
number
ˆ dele: delete
ˆ quit
S:
C:
S:
C:
S:
+OK POP3 server ready
user bob
+OK
pass hungry
+OK user successfully logged
C:
S:
S:
S:
C:
S:
S:
C:
C:
S:
S:
C:
C:
S:
list
1 498
2 912
.
retr 1
<message 1 contents>
.
dele 1
retr 2
<message 1 contents>
.
dele 2
quit
+OK POP3 server signing off
2: Application Layer
on
25
POP3 (more) and IMAP
More about POP3
ˆ Previous example uses
“download and delete”
mode.
ˆ Bob cannot re-read email if he changes
client
ˆ “Download-and-keep”:
copies of messages on
different clients
ˆ POP3 is stateless
across sessions
IMAP
ˆ Keep all messages in
one place: the server
ˆ Allows user to
organize messages in
folders
ˆ IMAP keeps user state
across sessions:

names of folders and
mappings between
message IDs and folder
name
2: Application Layer
26
Download