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: 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:
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: 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:
HTTP response
object not modified
HTTP/1.0 304 Not Modified
HTTP request msg If-modified-since:
HTTP response
object modified
HTTP/1.0 200 OK
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”
[email protected] 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: 250
[email protected]... Sender ok RCPT TO: 250
[email protected] ... 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:
[email protected] To:
[email protected] 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:
[email protected] To:
[email protected] 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 . dele 1 retr 2 . 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