Web and HTTP
Web and HTTP
A base HTML file links to these objects, all of which are accessible via
URLs (e.g., www.example.com/image.jpg ).
What is HTTP?
HTTP overview
HTTP: hypertext transfer protocol
Client: A browser (like Firefox, Safari) that requests, receives, and displays
web objects.
Server: A web server (like Apache) that sends web objects when
requested.
Steps:
1. The client creates a connection to the server.
2. HTTP messages are exchanged (requests from the client, responses from
the server).
TCP Connection: This is like a phone call between your browser and the
web server, where they exchange information.
Your browser (client) starts a connection to the web server. This is like
picking up the phone and calling the server.
The browser connects to the server using port 80, which is the
standard port for HTTP.
Once the server receives the connection request, it accepts the call,
and the connection is established.
Request message: The browser asks the server for specific content
(like a web page).
This is like hanging up the phone call after the conversation is finished.
Statelessness of HTTP
Stateless: HTTP doesn’t remember previous interactions.
Why?
2. Persistent HTTP:
RTT is the time it takes for a small packet of data to travel from your
browser (client) to the web server and back.
1. First RTT: To start the connection, a packet travels from the client to
the server and back.
2. Second RTT: The client sends the request for the object, and the
server sends the first few bytes of the response (another RTT).
3. File transmission: The time it takes to actually send the file (like
downloading it).
Total Time:
With persistent HTTP, the connection stays open after the first
response.
This means that multiple HTTP requests and responses can happen
over the same TCP connection without needing to open a new one
How it works:
After the first object is fetched, the server keeps the connection open.
The client can send more requests as soon as it finds new objects to
load (like images or scripts) without waiting for new connections.
Advantage:
Only 1 RTT for all objects: Once the connection is open, all objects on
the page can be fetched with just 1 RTT (instead of 2 RTTs for each
object like in non-persistent HTTP).
This reduces the delay and improves loading speed for web pages.
Common Methods:
GET: Retrieve a resource.
What it is: The POST method is used when you submit data (like a form
input) to a server.
Where the data goes: The form data is included in the body of the
HTTP request (called the entity body).
Example: If you fill out a contact form and click submit, your information
is sent in the body of the request.
What it is: The GET method is used when you send data via the URL.
Where the data goes: The data is attached directly to the URL of the
request. For example:
www.somesite.com/animalsearch?monkeys&banana
Here, monkeys and banana are sent as part of the URL, and they are
considered query parameters.
Note: GET is typically used for searches or simple data retrieval, and
the data is visible in the URL.
HTTP/1.0 Methods:
1. GET:
What it is: Used to retrieve data from the server (e.g., a webpage or
file).
2. POST:
What it is: Used to send data to the server, often for forms or
submitting information.
3. HEAD:
HTTP/1.1 Methods:
In addition to the methods in HTTP/1.0, HTTP/1.1 introduces:
1. PUT:
What it is: Used to upload a file or data to the server. The file is
included in the request body and sent to the path specified in the URL.
2. DELETE:
Key Differences:
POST vs GET:
POST sends data in the body of the request, so it is more secure and
allows for larger amounts of data (like form submissions).
GET sends data in the URL, which is visible to everyone and is typically
used for retrieving information (like searches).
PUT and DELETE are used for modifying or removing resources on the
server, respectively.
1. Status line:
Example:
HTTP/1.1 200 OK
505 HTTP Version Not Supported: Server doesn’t support the request's
HTTP version.
Small pieces of data stored by your browser, used to track your session
state.
Four components:
2. Shopping Carts:
What it means: When you add items to your online shopping cart,
cookies can remember what you’ve added even if you leave the site
and come back later.
3. Recommendations:
Cookies can store a lot of information about you, such as your name,
email address, and online activity.
How cookies help: Normally, HTTP (the protocol websites use) is stateless,
meaning it doesn’t remember anything from one request to the next.
Cookies allow websites to remember things across different visits (e.g.,
keeping you logged in or remembering your shopping cart items).
Other ways to keep state: Websites can also use other methods like
session variables or database entries to remember your state during
interactions.
Web Caching
What is caching?
Benefits:
1. Faster response for clients.
2. Local Cache: Common requests are served from the cache → Faster and
cheaper.
When you try to access a website, your browser sends the request to
the web cache instead of the original server.
If the object isn’t in the cache, the cache fetches it from the original
server, saves a copy, and sends it to your browser.
The cache is usually closer to the user than the original server, so
fetching content is much faster.
As a Server: When the cache has the requested object, it acts as a server
and sends the content directly to the user.
Browsers:
Even your browser has a small cache to store recently visited content
for quicker access.
The cache includes the date of the stored version in the HTTP request
using the If-Modified-Since header.
3. Server Responds:
The server replies with HTTP/1.0 304 Not Modified (No new content
sent).
If-Modified-Since: An HTTP header used to tell the server when the cache
last received the content.
HTTP/1.0 304 Not Modified: A response indicating that the cached content
is still up-to-date, so no new data is sent.
Quick Example:
1. Cache: "I have this page stored from Oct 1. Has it changed since then?"
Key Takeaways
1. HTTP is stateless, meaning each request is independent.