Internet Technology
04. Web and HTTP
Adhi Rizal
1
HTTP Basics
• HTTP: Hypertext Transfer Protocol (RFC 2616)
– Web’s application-layer protocol
– Client-server model
– TCP-based protocol
• Client connects to port 80 on the server
• HTTP messages are exchanged
HTTP Server
• Client closes the connection (e.g., Apache)
• HTTP is stateless
– Server does not store state
on previous requests
– Simplifies design
• Easier failure recovery HTTP Client
• Simplifies load balancing (e.g., Safari)
34
URLs
• Requests for objects are URLs
• URL = Uniform Resource Locator
[Link]
protocol server port # path to object object
[Link]
35
Types of connections
• Non-persistent HTTP (HTTP 1.0)
– At most one object is sent over a TCP connection
– Request/response
• Persistent HTTP (HTTP 1.1)
– Multiple objects can be sent over a single connection
36
Non-persistent HTTP
• [Link]/[Link] is one file that references:
– Five CSS (cascading style sheet) files
– Four image files
HTTP client connects to [Link] on port 80
1a
HTTP server accepts the connection
1b
HTTP client sends a request message to get the
2 object [Link]
HTTP server forms a response message containing
3 the requested object and sends it to the client
HTTP client receives the response & parses it. HTTP server closes the connection
4 Realizes that it needs to get 9 more objects.
5
Repeat steps 1-5
37
Non-persistent HTTP: Response time
• Round-trip time (RTT)
– Time for a small packet to travel from the
client to the server & back to the client
Connect
• Response time
RTT
– One RTT to initiate the connection
– One RTT for request & start of response Request file
Time to
– File transmission time RTT
transmit
file
• Total time =
File received
# objects × (2×RTT + transit_time) Connect
RTT
Request file
RTT Time to
transmit
file
File received
38
Persistent HTTP: Response time
• Server leaves connection open after sending
response
– Subsequent HTTP messages are sent over the same
open connection Connect
– One RTT for each referenced object once the RTT
connection is set up
Request file
• Response time Time to
RTT
– One RTT to initiate the connection transmit
file
– One RTT for request & start of response per
File received
object
– File transmission time per object RTT Time to
transmit
file
• Total timepersistent =
RTT + # objects × (RTT + transit_time) File received
• Versus Total timenon-persistent =
# objects × (2×RTT + transit_time)
39
HTTP Request Message
• Two classes of messages: request & response
• HTTP request messages are human-readable ASCII text
Browser request for a URL (Uniform Resource Locator):
[Link]
Creates an HTTP request Request line: GET, POST, HEAD, … commands
GET /this/is/a/[Link] HTTP/1.1
Host: [Link]
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.17
(KHTML, like Gecko) Version/6.0.2 Safari/536.26.17
headers
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive
40
HTTP Methods
HTTP/1.0 HTTP/1.1
• GET • GET, POST, HEAD
– Request a resource • PUT
• POST – Update data/resource to the
– Create data/resource path specified in the URL field
• DELETE
• HEAD – Deletes the file specified in
– Like GET, but only send the the URL field
headers
43
Some HTTP response codes
• 200 OK
– Request succeeded; requested object is in the message
• 301 Moved Permanently
– Requested object moved; new location specified in a Location:
header in the list of headers
• 400 Bad Request
– The server could not understand the request
• 404 Not Found
– The requested content is not found on the server
• 505 HTTP Version Not Supported
– Unsupported version
44
Cache dan Cookie
Cache ➔
• File berisi data situs web yang disimpan browser pengguna
• File tersimpan digunakan untuk akses berikutnya (tanpa
proses re-download)
• Contoh→ foto profil, audio, icon, dsb
Cookie ➔
• File berisi preferensi pengguna
• Disimpan di browser dan server web
• Contoh → autentikasi (login account), cart (tanpa login),
tema/mode situs, bahasa dan jenis huruf, dsb
Keeping state: cookies
• HTTP is stateless
• Cookies provide a mechanism for web servers to store state
• Cookies are small pieces of data, stored in text files, that are
stored on your computer or other device when websites are
loaded in a browser.
• They are widely used to “remember” you and your
preferences, either for a single visit (through a “session
cookie”) or for multiple repeat visits (using a “persistent
cookie”).
• Example an entry in
– You visit an e-commerce site
– When the site receives your request, it creates a unique ID and
the database identified by that ID.
– The HTTP response tells your browser to set a cookie. The cookie is sent
with future messages to that server
46
Cookies in use
client server
[Link]: 9123
HTTP request
[Link]
creates an ID 2244
for the request
[Link]: 9123 HTTP response
[Link]: 2244 Set-cookie: 2244
HTTP request Cookie-specific
Database
Cookie: 2244 action
Future session
[Link]: 9123
[Link]: 2244
HTTP request Cookie-specific
Cookie: 2244 action
47
Maintaining state with cookies
• Cookies can help a server store & access
– Shopping cart info
– Login name, authorization credentials
– Preferences (e.g., town name for weather)
– Session state (e.g., web-based email)
– History of web pages you visited on the site
• First-party cookies
– Placed by the website you visit
• Third-party cookies
– Placed by sites other than the one you visit – mostly ads
48
Web caching: proxy servers
• Caching proxy
• User sends all HTTP requests to a proxy server
• Proxy server:
– Checks its cache
– If the response is cached, it returns an HTTP response
– If not, it contacts the server Caching proxy Web server
acts as both a
• Server sends a response client & server
• Proxy caches it
• Proxy forwards the response to the requesting client
• Advantages Proxy
– Reduce response time if proxy
is closer/faster
– Reduce traffic on the web server
– Reduce traffic on the organization’s link
49
FTP: File Transfer Protocol
58
FTP: File Transport Protocol
• Transfer files between computers
• Client/server model
• Client: accepts commands from the user and initiates requests to get
or put files on the server
• Defined in RFC 959
– Original version RFC 765 – June 1980
– First proposal dates back to 1971
FTP Send/receive files FTP
client server
files
59
Separate data & control connections
• Client connects to an FTP server
on TCP port 21 connect
files
– This is the command channel commands
Port N Port 21
– Client port = some port ≥ 1024 = N
FTP FTP
client data server
• Commands are user requests and Port N+1 Port 20
include authentication info
connect
• When the server receives a
command to transfer data, it
initiates a TCP connection to the
client on port N+1 from its local
data port (20)
• After transferring one file, the
server closes the data connection
Sample FTP Commands
• Sent as ASCII text over the • Error messages
control channel – Similar to HTTP:
• Status code & text
• Access commands
– 331 User name okay, need password.
– USER: identify yourself
– 200 Command okay.
– PASS: supply your password
– 230 User logged in, proceed.
– CWD (CD): change working directory
– 502 Command not implemented.
– CDUP (CD ..): change to parent
– 125 Data connection already open;
– QUIT: log out
transfer starting.
• Control commands
– RETR (GET): retrieve a file
– STORE (PUT): store a file
– APPEND: append to a file
– DELETE: delete a file
– LIST (DIR): list files
61
The end
63