• This paper is participating in theNetwork protocols must be known and must be known”Essay campaign

What is HTTP?

HTTP(Hypertext Transfer Protocol) is a set of rules for transferring files (such as text, images, sound, video, and other multimedia files) over a network. Once users open their web browsers, they use HTTP indirectly. HTTP is an application protocol that runs on top of TCP/IP, the set of protocols that form the foundation of the Internet. The latest version of HTTP is HTTP/2, which was released in May 2015. It is an alternative to its predecessor, HTTP 1.1, but it is not obsolete.

How does HTTP work

Resources are exchanged between client devices and servers on the Internet over the HTTP protocol. The client device sends a resource request to the server to load the web page. The server sends the response back to the client to complete the request. Requests and responses share subdocuments — for example, data about images, text, text layout, and so on — that are stitched together by the client Web browser to display the complete Web page file.

In addition to the web page files it can serve, the Web server contains an HTTP daemon, which is a program that waits for HTTP requests and processes them as they arrive. A Web browser is an HTTP client that sends requests to the server. When a browser user enters a file request by typing a URL or clicking a hypertext link to “open” a Web file, the browser constructs an HTTP request and sends it to the Internet protocol address (IP address) indicated by the URL. The HTTP daemon in the target server receives the request and sends back the requested file or the file associated with the request.

A user wants to access juejin.com. A user enters a web address, and the computer sends a “GET” request to the server hosting the address. The GET request is sent using HTTP and tells the Juejin server that the user is looking for HTML(Hypertext Markup Language) code to construct the login page and provide its appearance. The text of the login page is contained in the HTML response, but the rest of the page — especially images and video — is made up of separate HTTP requests and response requests. The more requests that are made (for example, calling a page with a lot of images), the longer it takes for the server to respond to those requests and for the user system to load the page.

When these request/response pairs are sent, they use TCP/IP to reduce and transmit information in small packets consisting of binary sequences 1 and 0. These packets are physically transmitted over wires, fiber-optic cables and wireless networks.

Requests and responses that servers and clients use to share data with each other consist of ASCII codes. The request indicates what information the client is seeking from the server. The response contains code that the client browser will convert to a web page.

HTTP and HTTPS

HTTPS uses secure Sockets Layer (SSL) or transport layer security (TLS) as a sublayer below the regular HTTP application layer. HTTPS encrypts and decrypts HTTP page requests and pages returned by the Web server. It also protects against eavesdropping and man-in-the-middle (MitM) attacks. HTTPS was developed by Netscape. Moving from HTTP to HTTPS is considered beneficial because it provides an additional layer of security and trust.

HTTP requests and responses

Every interaction between the client and server is called a message. HTTP messages are requests or responses. The client device submits an HTTP request to the server, and the server responds by sending an HTTP response to the client.

HTTP request This is when a client device, such as an Internet browser, asks a server for information needed to load a Web site. This request provides the server with the information it needs to fine-tune its response to the client device. Each HTTP request contains encoded data with the following information:

  • HTTP and HTTP/2 are two versions.

  • A URL that points to a resource on the network.

  • HTTP method This indicates the specific action that the request expects to receive from the server in its response.

  • HTTP request headers this includes data such as what type of browser is being used and what data the request is seeking from the server. It can also include cookies, which display information previously sent from the server processing the request.

  • HTTP Body This is optional information that the server needs from requests such as user forms — username/password logins, short responses and file uploads — that are being submitted to the site.

HTTP Response An HTTP response message is the data that the client device receives from the Web server. As the name implies, a response is the server’s response to an HTTP request. The information contained in the HTTP response is adjusted based on the context the server receives from the request. HTTP responses typically include the following data:

  • The HTTP status code indicates the status of the requesting client device. The response may indicate success, informational response, redirection, or an error on the server or client.

  • The HTTP response header is used to send information about the server and the requested resource.

  • HTTP body (optional) If a request is successful, this contains the request data in the form of HTML code, which is translated into a web page by the client browser.

HTTP status code

In response to an HTTP request, the server typically issues a response code indicating that the request is being processed, that there is an error in the request, or that the request is being redirected. Common response codes include:

  • 200 OK This means that the request (such as GET or POST) has worked and is being executed.

  • 300 Permanently moving this response code means that the URL of the requested resource has been permanently changed.

  • 401 Unauthorized clients or users making requests to the server have not been authenticated.

  • 403 The identity of the forbidden client is known, but access is not authorized.

  • 404 Not found This is the most common error code. This means that the unrecognized URL or the resource at that location does not exist.

  • 500 Internal server error The server encountered a situation that it did not know how to handle.

The agent of HTTP

A proxy, or proxy server, is a client device and server between an application layer server, computer, or other machine. The proxy relays HTTP requests and responses between the client and server. Typically, each client-server interaction has one or more agents.

The agent can be transparent or opaque. The transparent proxy does not modify the client’s request, but sends it to the server in its original form. An opaque proxy modifies the client’s request to some extent. Opaque proxies can be used for other services, typically to speed up server retrieval.

Web developers can use proxies for the following purposes:

  • Caching Caching servers can store web pages or other Internet content locally for faster content retrieval and reduce the need for web site bandwidth.

  • Authentication controls access to applications and online information.

  • Records the store of historical data, such as the IP address of the client sending requests to the server.

  • Web filtering controls access to web pages that may compromise security or contain inappropriate content.

  • Load balancing client-to-server requests can be handled by multiple servers instead of just one.

The last

If it is helpful to you, I hope to give you a 👍 comment/collection/three even!

Bloggers are honest and answer questions for free ❤