Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How http requests determine boundaries

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces you how to determine the boundary of http request, the content is very detailed, interested friends can refer to it, I hope it can help you.

S3 upload has two methods PUT request: this upload request upload object protocol explicitly carries Content-length;POST request: this does not require a well-known Content-length, but through a streaming data transmission, but always want to know where the boundary is? There are several ways to let the server know the boundaries of the data; how does HTTP data determine boundaries?

S3 is an HTTP-based protocol, HTTP is an application layer protocol based on TCP, and TCP is a data stream-oriented protocol that has no boundaries. HTTP as an application layer protocol requires its own explicit definition of data boundaries.

HTTP boundary determination HTTP can be a keep-alive, can be a streaming protocol since the HTTP 1.1 protocol. So we need a way to identify body boundaries in three ways:

HTTP packet header explicitly sets Content-LengthHTTP transmission encoding method with Transfer-Encoding: chunked short connection (connection disconnection)(the third case, generally regarded as an abnormal scenario. So below we discuss the first two cases)

Both cases depend on whether the client's protocol is followed. Normally, if Content-Length is transmitted, it should be consistent with body. If the header does not have this field, then the client can also use Transfer-Encoding: chunked to transmit the body, which also allows the server to correctly identify the boundaries of the body.

Discussion in four cases

Case 1: What if only Content-Length is set, but body is not allowed?

Content-Length greater than body? Server implementations typically set a timeout. The server actively disconnects and reports timeout. This current online system is done by nginx, 1 minute timeout. The client itself ctrl+c, the client actively disconnects the service is generally the card owner, and the server waits to read the data declared by the client. There are two solutions: Content-Length is smaller than body? Request successful, data truncation

Case 2: If there is no Content-Length, Transfer-Encoding: Chunked is set.

At this time, the boundary can be correctly identified, subject to Chunked mode. Content-Length does not make a difference. Even if Content-Length is set, it does not depend on this value. It does not matter if it is not allowed. As long as it follows the chunked pattern, the actual body taken shall prevail.

Case 3: Content-Length and Transfer-Encoding are both set?

subject to chunked transmission.

Case 4: Content-Length and Transfer-Encoding are not set?

This is the same as Content-Length=0.

Screenshot example Chunked's package

Content-Length package

How to determine the boundary of http request is shared here. I hope the above content can be of some help to everyone and learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report