HTTP Protocol02021
HTTP Protocol02021
Page 2
World Wide Web (WWW, Web)
response
Client Web
Browser Server
On-demand
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
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
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
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
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
Page 12
Non-persistent connections (continued)
Client Server
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)
Page 16
HTTP request message
Page 17
Format of HTTP request message
~
~ ~
~ header lines
~
~ 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
POST method:
Input is uploaded to server in entity body
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
~
~ ~
~ header lines
~
~ body of the document ~
~ body
Page 23
Status code
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
Page 28
Question
Cookies in HTTP
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
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
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
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
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
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
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
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
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
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
Page 49
Thanks!
工科类 20 号
教师:唐晓岚
Page 50