Why is the HTTP protocol a stateless protocol

Source: Internet
Author: User

From: https://www.cnblogs.com/Jadie/p/6877392.html

No status meaning:

 stateless means that the protocol has no memory function for transactional processing . A lack of state means that the preceding information must be re-transmitted if the subsequent processing requires the previous information, which may result in an increase in the amount of data sent per connection. On the other hand, when the server does not need the previous information, the response is faster. Intuitively, each request is independent and is not directly related to the previous request and the subsequent request.

Actual usage:

In the Web application, we use the HTTP protocol, but the web we need is stateful, so we have added a cookie, session and other mechanisms to implement the stateful web.

  Web=http Protocol + state Mechanism + other mechanisms

Why not improve the HTTP protocol to make it stateful:

The initial HTTP protocol is only used to browse static files, the stateless protocol is sufficient, so the burden of implementation is very light (relatively speaking, the cost of implementing a State is very high, to maintain the state, according to the state to operate. )。 With the development of the web, it needs to become stateful, but isn't it necessary to modify the HTTP protocol to make it stateful? is not needed. Because we often stay on one page for a long time before going into another page, it is very expensive to maintain state between the two pages. Second, history makes HTTP stateless, but now new requirements for HTTP, according to the usual practice in the field of software is to retain the historical experience, in the HTTP protocol plus a layer to achieve our purpose ("plus a layer, you can do anything"). Therefore, other mechanisms are introduced to achieve this stateful connection.

Which methods can implement stateful connections:

Cookies, Session, application

Some people will be in the Web App in a state of the situation, than the customer to go shopping scene.

Customer: Browser visitor;

Store: Web server;

One purchase: one HTTP access

We know that the last customer purchase does not mean that the customer will buy the next one hours (of course, it does not mean not). This means that the relationship between different purchases of the same customer is uncertain. So honestly, in this case, let the store keep all the information the customer buys, and wait until the next purchase can know the cost of the customer's previously purchased content is very high. So in order to avoid this price, the store thinks that each purchase is an independent new purchase. Shallow lines: Shops do not differentiate between old customers and new passers-by. This is the state of being stateless.

But stores are trying to improve their earnings. She wants to encourage the customer to buy it. So tell you, as long as you buy more than 5 bottles of beer in one months, give you a glass.

Let's see how we do that.

A, the customer issued a magnetic card, which contains the customer's past purchase information.

So the store can know. This is the cookie.

B, to give the customer a unique number, the number of the customer's consumer information, stored in the store's server. This is the session.

Finally, the store can determine the overall decision, whether it is 5 bottles for the wine or 6 bottles. This is application.

In fact, these mechanisms are in the stateless traditional purchase process to add a little something to make the whole process become state. This is the case with Web applications.

Why is the HTTP protocol a stateless protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.