What is Http?

By | June 15, 2020

Introduction to the HTTP protocol

The protocol HTTP (HyperText Transfer Protocol) is the protocol used on the Internet since 1990. Version 0.9 was only intended to transfer data over the Internet (in particular Web pages are written in HTML ] Version 1.0 of the protocol (the most used ) now allows you to transfer messages with headers describing the content of the message using MIME- type coding.
The purpose of the HTTP protocol is to allow the transfer of files (mainly in HTML format) located using a character string called URL between a browser (the client) and a Web server (also called httpd on UNIX machines ).

 

Communication between browser and server

Communication between the browser and the server is done in two stages:

  • The browser makes an HTTP request
  • The server processes the request then sends an HTTP response

In reality, the communication takes place in more time if we consider the processing of the request by the server. Since we are only interested in the HTTP protocol, server-side processing will not be explained in the context of this article … If this subject interests you, refer to the article on CGI processing.

 

HTTP request

An HTTP request is a set of lines sent to the server by the browser. She understands :

  • A request line: this is a line specifying the type of document requested, the method that must be applied, and the version of the protocol used. The line includes three elements that must be separated by a space:
    • The method
    • URL
    • The version of the protocol used by the client (usually HTTP / 1.0 )
  • Request header fields: this is a set of optional lines used to provide additional information on the request and/or the client (Browser, operating system, …). Each of these lines is composed of a name qualifying the type of header, followed by a colon (:) and the value of the header
  • The body of the request: it is a set of optional lines which must be separated from the preceding lines by an empty line and allowing, for example, a sending of data by a POST command when sending data to the server by a form

An HTTP request therefore has the following syntax ( <crlf> means carriage return or line feed ):

METHOD URL VERSION <crlf> HEADER
: Value <crlf>
.
.
. HEADER
: Value <crlf>
Empty line <crlf>
BODY OF THE REQUEST

Here is an example of an HTTP request:

GET [/ http://www.tops10.xyz ] HTTP / 1.0
Accept: text / html
If-Modified-Since: Saturday, 15-January-2000 14:37:11 GMT
User-Agent: Mozilla / 4.0 (compatible; MSIE 5.0; Windows 95)

Orders

Ordered Description
Get Request for the resource located at the specified URL
HEAD Request for the header of the resource located at the specified URL
POST Sending data to the program located at the specified URL
PUT Sending data to the specified URL
DELETE Removal of the resource located at the specified URL

 

Headers

Header name Description
Accept Type of content accepted by the browser (for example text / HTML ). See MIME types
Accept-Charset Character set expected by the browser
Accept-Encoding Data coding accepted by the browser
Accept-Language Language expected by the browser (English by default)
Authorization Identification of the browser with the server
Content-Encoding Type of coding of the body of the request
Content-Language Body language type of the request
Content-Length Length of the request body
Content-Type Content-type of the body of the request (for example text / HTML ). See MIME types
Dated Data transfer start date
Forwarded Used by intermediate machines between the browser and the server
From Allows you to specify the customer’s email address
From Allows you to specify that the document should be sent if it has been modified since a certain date
Link Relationship between two URLs
Orig-URL Request original URL
Refer URL of the link from which the request was made
User-Agent A string giving information about the client, such as browser name and version, of the operating system

 

HTTP response

An HTTP response is a set of lines sent to the browser by the server. She understands :

    • A status line: this is a line specifying the version of the protocol used and the status of processing the request using a code and an explanatory text. The line includes three elements that must be separated by a space:
        • The version of the protocol used

       

        • The status code

       

        • The meaning of the code

       

 

    • Response header fields: this is a set of optional lines used to provide additional information on the response and/or the server. Each of these lines is composed of a name qualifying the type of header, followed by a colon (:) and the value of the header

 

    • The body of the response: it contains the requested document

 

An HTTP response, therefore, has the following syntax ( <crlf> means carriage return or line feed ):

VERSION-HTTP CODE EXPLANATION <crlf> HEADER
: Value <crlf>
.
.
. HEADER
: Value <crlf>
Empty line <crlf>
RESPONSE BODY

Here is an example of an HTTP response:

HTTP / 1.0 200 OK Date: Sat, 15 Jan 2000 14:37:12 GMT Server: Microsoft-IIS / 2.0 Content-Type: text / HTML Content-Length: 1245 Last-Modified: Fri, 14 Jan 2000 08:25: 13 GMT

Response headers

Header name Description
Content-Encoding Response body coding type
Content-Language Response body language type
Content-Length Response body length
Content-Type Content-type of the body of the response (for example text / Html ). See MIME types
Dated Data transfer start date
Expires Deadline for data consumption
Forwarded Used by intermediate machines between the browser and the server
Rental Redirect to a new URL associated with the document
Server Characteristics of the server that sent the response

 

Response codes

These are the codes you see when the browser cannot provide you with the requested page. The response code consists of three digits: the first indicates the status class and the following the exact nature of the error.

Coded Message Description
10x Information message These codes are not used in version 1.0 of the protocol
20x Success These codes indicate the smooth running of the transaction
200 OK The request was completed correctly
201 CREATED It follows a POST command, it indicates success, the body of the rest of the document is supposed to indicate the URL where the newly created document should be.
202 ACCEPTED The request was granted, but the following procedure was not completed
203 PARTIAL INFORMATION When this code is received in response to a GET command, it indicates that the response is not complete.
204 NO RESPONSE The server has received the request but there is no information to return
205 RESET CONTENT The server tells the browser to delete the content of the fields of a form
206 PARTIAL CONTENT It is a response to a request with the range header. The server must specify content-Range header
30x Redirection These codes indicate that the resource is no longer in the indicated location
301 MOVED The requested data has been transferred to a new address
302 FOUND The requested data is at a new URL but may have been moved from …
303 METHOD This implies that the client must try a new address, preferably trying a method other than getting
304 NOT MODIFIED If the client has made a conditional GET command (asking if the document has been modified since the last time) and the document has not been modified, it returns this code.
40x Customer error These codes indicate that the request is incorrect
400 BAD REQUEST The syntax of the request is badly formulated or is impossible to satisfy
401 UNAUTHORIZED The message parameter provides specifications for acceptable forms of authorization. The customer must reformulate his request with the correct authorization data
402 PAYMENT REQUIRED The customer must reformulate his request with the correct payment data
403 FORBIDDEN Access to the resource is simply prohibited
404 NOT FOUND Classic! The server could not find anything at the specified address. Left without leaving an address … 🙂
50x Server error These codes indicate that there was an internal server error
500 INTERNAL ERROR The server encountered an unexpected condition which prevented it from responding to the request (such as something happening to the servers …)
501 NOT IMPLEMENTED The server does not support the requested service (we cannot know everything …)
502 BAD GATEWAY The server received an invalid response from the server it was trying to access by acting as a gateway or proxy
503 UNAVAILABLE SERVICE The server cannot answer you at the moment, because the traffic is too dense (all the lines of your correspondent are busy, please call again later)
504 GATEWAY TIMEOUT The server response was too long  the time during which the gateway was prepared to wait for it (the time allotted to you is now over …)

Leave a Reply

Your email address will not be published. Required fields are marked *