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

HTTP Protocol02021

The document summarizes the HTTP protocol. It discusses how HTTP uses the client-server model over TCP/IP networks to deliver web pages and objects from servers to browsers. It describes key aspects of HTTP including connections, requests, responses and methods. Persistent connections allow multiple objects on a page to be retrieved over a single TCP connection rather than opening a new connection for each object.

Uploaded by

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

HTTP Protocol02021

The document summarizes the HTTP protocol. It discusses how HTTP uses the client-server model over TCP/IP networks to deliver web pages and objects from servers to browsers. It describes key aspects of HTTP including connections, requests, responses and methods. Persistent connections allow multiple objects on a page to be retrieved over a single TCP connection rather than opening a new connection for each object.

Uploaded by

HuidoQuinoQuino
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

HTTP Protocol

Applications of TCP/IP network


Xiaolan Tang
Outline
1. Web 5. Cookies
2. HTTP overview 6. Web caching
3. HTTP connections 7. Conditional request
4. HTTP messages 8. Streaming multimedia

Page 2
World Wide Web (WWW, Web)

response
Client Web
Browser Server

On-demand

Web is a distributed client-server service.


A client using a browser can access a service using a server.

Page 3
Web objects and URL
 can bWeb object e HTML file, JPEG image, Java applet,
audio file, video file, …
 Each object is addressable by a Uniform Resource
Locator (URL)
• protocol://host/path Used most of the time
• protocol://host:port/path Used when port number if needed
https://www.vmall.com/product/Mate30.html

protocol host path


For HTTP protocol, the well-known port number is 80

Page 4
Web documents
 Static documents
• Fixed-content documents, created and stored in a server
• HTML, XML, XSL, XHTML, …

 Dynamic documents
• Created by a server whenever a browser requests the doc
• e.g., retrieval of the time and date from a server, query in database
• JSP, ASP, PHP, …

 Active documents
• A program or script to be run at the client side
• Java applet, JavaScript, …

Page 5
Web page
 Web page consists of objects

 Web page typically is a base HTML-file which includes several


referenced objects

Page 6
Outline
1. Web 5. Cookies
2. HTTP overview 6. Web caching
3. HTTP connections 7. Conditional request
4. HTTP messages 8. Streaming multimedia

Page 7
HTTP overview

HTTP: HyperText Transfer Protocol


 Web’s application layer protocol
PC running
 Client/Server (C/S) model IE browser
• Client uses HTTP protocol to
request and receive Web objects,
and displays them in browser Server
• Server sends Web objects to client running
Apache Web
by using HTTP response server
Cellphone running
Huawei browser

Page 8
HTTP uses TCP
Process of HTTP using TCP
 Client initiates TCP connection by creating a socket to server, port 80
 Server accepts TCP connection from client
 Client (browser) and server exchange HTTP messages
 TCP connection is closed

 HTTP is stateless
• Server maintains no information about past client requests
• Reason: Too complex to maintain past states and reconcile
inconsistent states

Page 9
Outline
1. Web 5. Cookies
2. HTTP overview 6. Web caches
3. HTTP connections 7. Conditional request
4. HTTP messages 8. Streaming multimedia

Page 10
HTTP connections

Question: If several objects embedded in a Web page are located on the


same server, how to retrieve them?

To retrieve each object using a To make a TCP connection and


new TCP connection retrieve them all
Non-persistent connections Persistent connections

 Browsers often open parallel TCP


Default connection
conn to fetch referenced objects
in HTTP/1.1
 High overhead on the server

Page 11
Non-persistent connections
Amy (client) enters URL: contains text and references to
10 JPEG images
www.someUniv.edu/someDept/home.html
Client Server

1. The client initiates TCP 2. Web server at host


connection to Web server at www.someUniv.edu accepts TCP
host www.someUniv.edu on connection at port 80 from the
port 80 client and notifies client

3. The client sends HTTP 4. Web server receives request


request message (containing message, creates HTTP response
URL /someDept/home.html) message containing the
into TCP connection requested object (html file), and
sends it into TCP connection
time time

Page 12
Non-persistent connections (continued)

Client Server

5. Web server closes TCP


6. The client receives response connection
message containing html file,
and displays html. Parsing html
file, find 10 referenced JPEG
objects
7. Repeat the steps 1-6 for each of
10 JPEG images

time time

Page 13
HTTP response time
Round Trip Time (RTT):
Time for a small packet to travel from Client Server
client to server and back
initiate TCP
Non-persistent connections connection
 1 RTT to establish TCP conn RTT
 1 RTT for HTTP request and first few
bytes of HTTP response to return request file
 File transmission time time to
RTT
 HTTP response time per object = transmit file
2 RTT + file transmission time file received
Persistent connections
 As little as 1 RTT + file trans time for
time time
each object

Page 14
Outline
1. Web 5. Cookies
2. HTTP overview 6. Web caching
3. HTTP connections 7. Conditional request
4. HTTP messages 8. Streaming multimedia

Page 15
HTTP request message
 Two types of HTTP messages: request, response
• ASCII (human-readable format)

 HTTP request message


http://gaia.cs.umass.edu/wireshark-labs/HTTP-wireshark-file1.html
GET /wireshark-labs/HTTP-wireshark-file1.html HTTP/1.1\r\n
Host: gaia.cs.umass.edu\r\n
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0)\r\n
Accept: */*\r\n
Accept-Language: en-US\r\n
Accept-Encoding: gzip, deflate\r\n
Connection: Keep-Alive\r\n
\r\n

Page 16
HTTP request message

carriage return line-feed


character character
request line
(method, URL, GET /wireshark-labs/HTTP-wireshark-file1.html HTTP/1.1\r\n
version) Host: gaia.cs.umass.edu\r\n
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0)\r\n
header Accept: */*\r\n
lines Accept-Language: en-US\r\n
Accept-Encoding: gzip, deflate\r\n
carriage return Connection: Keep-Alive\r\n
and line feed at
start of line \r\n
indicates end
of header lines

Page 17
Format of HTTP request message

method sp URL sp version cr lf request line


header field name : sp value cr lf

~
~ ~
~ header lines

header field name : sp value cr lf


cr lf blank line

~
~ entity body ~
~ body

Page 18
Methods
HTTP/1.0: HTTP/1.1:
 GET  GET, HEAD, POST
• Request a document  PUT
(host+URL) from server • Upload file in entity body to
 HEAD path specified in URL field
• Request information about a  DELETE
document (host+URL) but not • Delete file specified in the URL
the document itself field
 POST
• Send information in entity body
from client to server

Page 19
Form input uploading

Web page often includes form input.

POST method:
 Input is uploaded to server in entity body

GET method (URL method):


 Input is uploaded in URL field of request line

www.someZoo.com/animalSearch?monkeys&banana

Page 20
Request header names
Header Description
Host The host and port number of the client
User-agent Identify the client program
Accept The media format the client can accept
Accept-charset The character set the client can handle
Accept-encoding The encoding scheme the client can handle
Accept-language The language the client can accept
Connection keep-alive: persistent conn; close: non-persistent conn
Date The current date (date + time)
Cookie The cookie to the server (explained later)
If-modified-since If the file is modified since a specific date (explained later)

Page 21
HTTP response message
status line
(protocol, HTTP/1.1 200 OK\r\n
status code, Date: Mon, 29 Jun 2020 10:21:29 GMT\r\n
status phrase) Server: Apache/2.4.6 (CentOS)\r\n
Last-Modified: Mon, 29 Jun 2020 05:59:02 GMT\r\n
header Accept-Ranges: bytes\r\n
lines Content-Length: 128\r\n
Keep-Alive: timeout=5, max=100\r\n
Connection: Keep-Alive\r\n
Content-Type: text/html; charset=UTF-8\r\n
data, e.g., \r\n
requested data data data data data ...
HTML file

Page 22
Format of HTTP response message

version sp status code sp phrase cr lf status line


header field name : sp value cr lf

~
~ ~
~ header lines

header field name : sp value cr lf


cr lf blank line

~
~ body of the document ~
~ body

Page 23
Status code

Status code appears in the 1st line of HTTP response message

Value Meaning
100 range Only informational
200 range Indicate a successful request
300 range Redirect the client to another URL
400 range Indicate an error at the client side
500 range Indicate an error at the server side

Page 24
Samples of status code
200 OK
A successful request; requested object is in the body
301 Moved Permanently
Requested object has been moved to a new location in the header
line “Location:”
400 Bad Request
Request message cannot be understood by server
404 Not Found
Requested document cannot be found on server
505 HTTP Version Not Supported

Page 25
Response header names
Header Description
Date The current date
Server Information about the server
Set-cookie The sever asks the client to save a cookie
Content-language The language
Content-length The length of the document
Content-type The media type
Location Ask the client to send the request to another site
Accept-ranges The server will accept the requested byte-ranges
Last-modified The date and time of the last change
Keep-alive The timeout (s) and maximum number of requests in a conn

Page 26
Outline
1. Web 5. Cookies
2. HTTP overview 6. Web caching
3. HTTP connections 7. Conditional request
4. HTTP messages 8. Streaming multimedia

Page 27
Web needs to remember the clients

 Some Web sites are electronic stores that allow users to browse and
select items, put them in cart, and pay with a card
 Some Web sites allow access to registered clients only

 Some Web sites are used as portals: the user selects the Web pages
they want to see

 Some Web sites are just advertising agency


 …

Page 28
Question

How does a Web site remember some


information about the clients?

Cookies in HTTP

Many Web sites use cookies

Page 29
Creating, storing and using cookies
Server: When receiving a HTTP request from a client, it stores
information about the client in the back-end database
Where?
Server: Set cookie header line in HTTP response message
Client: When receiving a response, the browser stores the cookie file in
the cookie directory on the user’s host
Client: The browser includes cookie header line in next HTTP request
message
Authorization Shopping carts Recommendations

User session state (Web e-mail)

Page 30
An example of cookie use
Amy VMALL Server
cookie file
taobao 6158 HTTP request msg
Create ID 2034
HTTP response msg for Amy Back-end
taobao 6158
vmall 2034 set-cookie: 2034 database
HTTP request msg
cookie: 2034 Cookie relevant
action
HTTP response msg
one day later:
taobao 6158 HTTP request msg
vmall 2034 cookie: 2034 Cookie relevant
action
HTTP response msg

Page 31
Cookies and privacy
 You may supply name and e-mail to sites
 Cookies permit sites to learn a lot about you

 Basic personal information


 Gender, age, home, workplace, married or not, …
 Your interests
 Favorite movie, restaurant, dressing style, beer, …
 Your life
 Home decorating, having a baby, fitness, …

Page 32
Question

For those popular Web pages visited frequently in a local area, how to
improve the Web service?

Web caching

Page 33
Outline
1. Web 5. Cookies
2. HTTP overview 6. Web caching
3. HTTP connections 7. Conditional request
4. HTTP messages 8. Streaming multimedia

Page 34
Web caching
Goal: satisfying HTTP request without involving origin server
 A proxy server keeps copies of
Web objects that are requested
recently
Amy
 Browser sends all HTTP requests Client
to proxy server response
 Requested object is in cache: proxy Proxy Origin
server returns object server server
 Otherwise, proxy server requests
object from origin server, then returns Bob
it to client Client
browser setting

Page 35
Proxy server
 Proxy server acts as both
client and server
 Server for original Amy
requesting client Client
 Client to origin server response
Proxy Origin
 Proxy servers are usually server server
located at the client side
 Installed by ISP (university, Bob
Client
company, residential ISP)

Page 36
Why Web caching?
Advantages of Web caching Cache update
 Shorten response time for client request  Update the cache according
 Reduce traffic on an institution’s access to the origin server’s update
link policy

 Use the header about the


Content Distribution Networks, CDNs last modification time of the
 Many distributed caches information to guess how
 Localize large amounts of traffic long it would be valid

Internet dense with caches

Page 37
Web caching example
Scenario:
 Average object size: 1M bits
Origin
 Average request rate from browsers to origin servers
servers:15/sec
 Average data rate to browsers: 15 Mbps Public Internet
 Size of HTTP request message is negligible
 RTT from institutional router to any origin
server: 2 sec 15Mbps
access link
Result: Institutional
 LAN utilization: 15% network 100Mbps
 Access link utilization = 100% LAN
 Total delay = Internet delay + access delay
+ LAN delay = 2 sec + minutes + msecs
Local Web cache

Page 38
Outline
1. Web 5. Cookies
2. HTTP overview 6. Web caching
3. HTTP connections 7. Conditional request
4. HTTP messages 8. Streaming multimedia

Page 39
Conditional request
Goal: Server will send the requested object if the condition is met

 Condition in HTTP request message


 Most common condition:
Since a specified date and time, the object is modified

Advantages
 No object transmission delay
 Lower link utilization

Page 40
Conditional request (continued)
• Client (Cache): specify date of Client Server
cached copy in HTTP request
HTTP request msg
If-modified-since: <date> If-modified-since: Mon, 29 Object not
Jun 2020 00:00:00 GMT
modified
• Server: HTTP response HTTP response msg after <date>
message contains no object if HTTP/1.1 304 Not Modified

cached copy is up-to-date:


HTTP request msg
HTTP/1.1 304 Not Modified If-modified-since : Mon, 29
Jun 2020 00:00:00 GMT Object
modified
Otherwise, the object is sent HTTP response msg after <date>
to client HTTP/1.1 200 OK
<data>

Page 41
Outline
1. Web 5. Cookies
2. HTTP overview 6. Web caching
3. HTTP connections 7. Conditional request
4. HTTP messages 8. Streaming multimedia

Page 42
Video traffic
 Video traffic: major consumer of Internet bandwidth
• Video is 60% of total Internet downstream traffic
(Sandvine, 2019)

 Challenge
 Scale: how to reach so many clients?
Single server cannot work!
 Heterogeneity: Different clients have different
capabilities (e.g., wired vs. wireless, bandwidth rich vs.
bandwidth poor)

 Solution:
application protocol + distributed servers like caches

Page 43
Characteristics of video

Video Image Pixel


A sequence of images Array of pixels Represented by bits
displayed at constant
rate (e.g., 24fps, 30fps)

 Coding: decrease the number of bits to encode image by using redundancy


 Spatial redundancy within an image color value and number of repeated values
 Temporal redundancy between two consecutive images only differences from last frame

Page 44
Video encoding bit rate
 Constant Bit Rate (CBR): fixed video encoding rate
 Variable Bit Rate (VBR): variable video encoding rate with different
amount of spatial and temporal coding

Video encoding bit rate


Low High

< 1 Mbps 1.5 Mbps 3-6 Mbps 10 Mbps


MPEG4 MPEG 1 MPEG2 4K Ultra HD
(often used in Internet) (CD-ROM) (DVD)

Low quality High quality


Smooth Not smooth

Page 45
Streaming multimedia over HTTP
 Retrieve multimedia file via HTTP request msg with GET method
 Transmit data at maximum possible rate of TCP
variable
Internet rate

Video TCP sending TCP receiving Application


file buffer buffer playout buffer
Server Client
 Fill rate fluctuation: TCP congestion control, retransmissions (in-
order delivery)
 HTTP/TCP passes more easily through firewalls
Problem: Different users or the same user at different times have different
bandwidths, but the videos they retrieved are encoded at the same bit rate

Page 46
Dynamic Adaptive Streaming over HTTP (DASH)
Server: Client:
 A video file  multiple chunks  Measure server-to-client bandwidth
(each lasts several seconds) periodically
 Multiple versions of video  Choose maximum coding rate that
adapts to current bandwidth
(chunks) with different coding
rates  Select and request one chunk at a
time (getting URL from manifest file)
 Manifest file includes URLs for
chunks with different coding A large number of buffered chunks, a
rates high bandwidth  chunk with high bit
rate
A small number of buffered chunks, a low
bandwidth  chunk with low bit rate

Page 47
Summary

HTTP: HyperText Transfer Protocol

 Web
 HTTP overview  Cookies
 HTTP connections  Web caching
 Non-persistent connections  Conditional request
 Persistent connections  Streaming multimedia
 HTTP messages  HTTP
 HTTP request msg  DASH
 HTTP response msg

Page 48
Quiz

1. When an HTTP server receives a request message from an


HTTP client, how does the server know when all headers have
arrived and the body of the message is to follow?
2. Which method in HTTP request message uploads the form
input in entity body?
3. HTTP version 1.1 defines the persistent connection as the
default connection. Using RFC 2616, find out how a client or
server can change the default situation to non-persistent.

Page 49
Thanks!

工科类 20 号
教师:唐晓岚

Page 50

You might also like