Defines and connects how clients talk to servers and how servers transfers the pages back to clients.
clients = browsers
Request – Response Protocol
Send req to server
Server responds
HTTP = stateless
Server doesn’t keep any past transaction information of requests.
Every request is on its own.
HTTP Requests to Servers
[Source Pic: Dr Liu Zehua lecture notes 2]
Method: GET / POST / HEAD
Headers is one per row (name and value pair). Meaningful to the server.
Entity body is usually empty data.
How long of the session is dependent on the content and headers.
Most of the request a response will be returned which is usually a document.
HTTP Response to Servers
[Source Pic: Dr Liu Zehua lecture notes 2]
Phrase = Status message
Header lines consumed by the client and are relevant to the client.
Entity body contains the content which the client requested (eg HTML text)
5 cats
1 – informational
2 – success
3 – redirection
4 – client error
5 – server error
Eg
200 ok
404 client error
500 server error
Some browsers look at the response message header “Last-Modified” to be used as a caching process. This is to identify whether there has been any changes made last to the content type.
Headers that may be important to client is “Contect-Type” for it to know how to interpret the data. “Content-Length” determines the session – standard counting is bytes.
*Above situation is referred as synchronous communication. If multiple browsers communicate to server, multiple sessions will be opened accordingly for each browsers.
HTTP sits on top of the TCP.
HTTP 1.0
Mostly at that time was “nonpersistent connections”.
Q) What is “nonpersistent connections”?
Each time you want to make a request you have to establish a channel of communication before the HTTP Request and HTTP Response can happen. Once the HTTP Response is finished, it then has TCP/IP disconnection.
Designed for not so many requests. If requesting a HTML document for 20 images in this case will have 20 HTTP requests.
HTTP 1.1
Has “persistent connections” – server keeps connection open after the first request. Connection closed via client or server passing a header or time-out.
For multiple requests can use “pipeline”. Server will send the response based on the request order. However, server has to be intelligent enough to hold on responses if the previous response will take much longer.
Persistent connection advantages
Latency is reduced. Time and memory resources use is reduced.
eg Sometimes if the computers are very far. The cost for connection to establish could be high. For persistent connection only pay one time connection than nonpersistent.
Methods of Requests
GET is most common.
Allow one to retrieve a document.
Entity body section is empty.
Conditional GET has the caching part in the header field (If-Modified-Since <date>, If-Unmodified-Since, If-Match, If-Range)
Partial GET get to requests a document in parts. Has the Range in header field.
POST also allows to retrieve a document. “Stated purpose”.
Attaching some data to your request to server whereby the server will use the data to replace, append, etc.
HEAD same as GET but the server doesn’t return an entity body in the response.
HTTP Headers
General headers is in both request and response.
Desired to have some form of authentication before servers respond to client requests = Basic Authentication Type.
Client authenticates user name, password
Server responds only if can validate the Clients information.
Header is: Authorization:
Uses Base64 encoding
The popup window of user name and password box is done by the browser side inclusive of “Remember my Password”. Ticking of this box will cache the username and password in a local store and not on the Server side.
State Management
To maintain and remember the state, it can be done by using Cookies.
Client requests.
Server responds using Set-Cookie response header:
Set-Cookie:; Max-Age=seconds; Path=PATH; Domain=DOMAIN_NAME; secure
Client stores in the browser on the local machine.
To send valid cookies client to server,
Cookie: NAME1=VALUE1; NAME2=VALUE2;
Cookie: user=diongoh; shoppingid=ABC123
Server will then check this information of the Cookie
[Source Pic: Dr Liu Zehua lecture notes 2]