HTTP
- Stands for Hyper Text Transfer Protocol
- Web Server is HTTP server.
- Web Browser is HTTP client.
- HTTP protocol generally takes place over TCP connection.
- It listens on port 80.
- In HTTP, clients sends a HTTP request and server sends backs HTTP response.
- HTTP is stateless.
Client Server Model
- A server is a process that offers some service.
- A client is a process that is requesting the service.
- Server waits for clients to get the request.
HTTP Request and Response Message
a. HTTP Request Message
- Request Line
- Headers
- A blank Line
- Body
a. HTTP Response Message
- Status Line
- Headers
- A blank Line
- Body
HTTP Methods
- Get - Requests data from the server
- HEAD - Requests information about a data but not the data itself.
- POST - Sends some data to the server
- PUT - Updates some data to the server
- TRACE - Echoes the incoming request
- CONNECT - Reserved
- OPTION - Inquires about available options
HTTP Status Code
-
Informational
-
100 - Continue
-
101 - Switching
-
Success
-
200 - OK : The request is successful
- 201 - Created : A new URL is created.
- 202 - Accepted : The request is accepted but it - is not immediately acted upon.
-
204 - No content : There is no content in the body.
-
Redirection
-
301 - Moved Permanently : The requested URL is no longer used by the server.
- 302 - Moved Temporarily : The requested URL has moved temporarily.
-
304 - Not modified : The document has not been modified.
-
Client Error
-
400 - Bad Request : There is a error in the request.
- 401 - Unauthorized : The request lacks proper authorization.
- 403 - Forbidden : Service is denied.
- 404 - Not Found : The document is not found.
- 405 - Method not allowed : This method is not supported in the URL.
-
406 - Not acceptable : The format reqested is not acceptable.
-
Server Error
-
500 - Internal Server Error : There is an error at the server side.
- 501 - Not implemented : The action requeted cannot be performed.
- 503 - Service unavaible : The service is temporarily unavailable, but may be requested in the future.
HTTP Request Header
- Cache-control : Specifies information about caching.
- Connection : Shows whether the connection should be closed or not.
- Date : Shows the current date.
- MIME-version : Shows the MIME version used.
- Upgrade : Specifies the preferred communication protocol.
- Accept
- Accept-charset
- Accept-language
- Authorization
- User-agent, etc
HTTP Response Headers
- Accept-range
- Age
- Public
- Retry-after
- Server
HTTP Entity Headers
- Allow
- Content-encoding
- Content-language
- Content-length
- Content-range
- Content-type
- Expires
- Last-modified
- Location
HTTP1 vs HTTP2
- HTTP2 is much faster and more reliable than HTTP1.
- HTTP1 loads a single request for every TCP connection, while HTTP2 avoids network delay by using multiplexing.
Features of HTTP2
- Binary Protocol - While HTTP/1.x was a text based protocol, HTTP/2 is a binary protocol resulting in less error during data transfer process.
- Multiplexed Streams - All HTTP/2 connections are multiplexed streams meaning multiple files can be transferred in a single stream of binary data.
- Compressed Header - HTTP/2 compresses header data in responses resulting in faster transfer of data.
- Server Push - This capability allows the server to send linked resources to the client automatically, greatly reducing the number of requests to the server.
- Stream Prioritization - HTTP/2 can prioritize data streams based on their type resulting in better bandwidth allocation where necessary.