HTTP i.e. Hyper Text Transfer Protocol is a client-server network protocol which has been in use by the World-Wide Web global information initiative since 1990. Whenever we surf the web, our browser sends HTTP request messages for HTML pages, images, scripts and styles sheets. These requests are handled by returning response messages which contain the requested resource.
- It is an application-level protocol for distributed, collaborative, hypermedia information systems.
- The first version of HTTP, known as HTTP/0.9, was a simple protocol for raw data transfer across the Internet.
- The HTTP protocol is a request/response protocol.
- Most HTTP communication is initiated by a user agent and consists of a request to be applied to a resource on some origin server. This can be accomplished simply via a single connection between the user agent and the origin server.
- HTTP communication typically takes place over TCP/IP connections. The default port is TCP 80 , but other ports can be used. This does not prohibit HTTP from being implemented on top of any other protocol on the Internet, or on other networks.
- HTTP only presumes a reliable transport hence any protocol providing such guarantees can be used.
- HTTP is designed to be simple and outstandingly fast.
HTTP is a request/response standard of a client and a server. A client is the end-user and the server is the web site. The client making a HTTP request using a web browser, spider, or other end-user tool is known as the user agent and the responding server which stores or creates resources such as HTML files and images is called the origin server. A client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a connection with a server. The server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity metainformation, and possible entity-body content.
HTTP Request Message
It has a simple text based structure. The request message consists of the following:
- Request line, For example: GET /images/logo.gif HTTP/1.1 which means a resource called /images/logo.gif is requested from server
- Headers like Accept-Language: en
- An empty line
- An optional message body
The request line and headers must all end with <CR><LF> i.e. a carriage return followed by a line feed. The empty line must consist of only <CR><LF> and no other whitespace. In the HTTP/1.1 protocol, all headers except Host are optional.
The web server's response message has a similar structure, but is followed by the contents of the HTML page.
HTTP defines following eight methods for indicating the preferred action to be performed on the identified resource
- HEAD: This method asks for the response identical to the one that would correspond to a GET request, but without the response body. This method is useful for retrieving meta-information written in response headers, without transporting the entire content.
- GET: This method is used for requesting a representation of the specified resource. GET should not be used for operations that cause side-effects, such as using it for taking actions in web applications.
- POST: It submits data to be processed to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both.
- PUT: Used for uploading a representation of the specified resource.
- DELETE: It is used for deleting the specified resource.
- TRACE: Use of this method echoes back the received request, so that a client can see what intermediate servers are adding or changing in the request.
- OPTIONS: This request method returns the HTTP methods supported by the server for specified URL. This can be used to check the functionality of a web server by requesting '*' instead of a specific resource.
- CONNECT: It converts the request connection to a transparent TCP/IP tunnel, generally to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.
HTTP servers are required to implement at least the GET and HEAD methods and, whenever possible, also the OPTIONS method.