当前位置:网站首页>Simply test the two different data transmission methods of content length and chunked
Simply test the two different data transmission methods of content length and chunked
2022-07-02 07:59:00 【Silent discrimination】
List of articles
Content-Length: Data transmission according to data length
Chunk: Data transmission by block
The sample request shown in the following figure , It's just at this time Content-length Is in the response header

One 、 Code testing
This article will use ApiPost Test two different methods of carrying data
1、 Preparation
1、 Prepare one ApiPost( Their own use postman When testing , Unable to test successfully )

2、 Write the corresponding test class
public class TestServerSocket {
public static void main(String[] args) throws IOException {
ServerSocket socket = new ServerSocket(8089);
Socket accept = socket.accept();
InputStream inputStream = accept.getInputStream();
while (true) {
byte[] bytes = new byte[100000];
int readLength = inputStream.read(bytes);
System.out.println(new String(bytes, 0, readLength));
System.out.println("---- Complete a data reception over----");
}
}
}
2、 test Content-length
1、 Send a message to 8089 port , The carried parameter is name and age

2、 View the data information of the console

We will find that the default parameter carried is content-length, And the length is 269 Bytes .
3、 test Transfer-Encoding:chunked
1、 modify ApiPost Request header for , Add corresponding Transfer-Encoding Parameters

2、 The parameters carried and remain unchanged , Again using ApiPost test , View console data

At this time, the requested parameter information , It includes Content-length, Also contains the Transfer-Encoding:chunked. But the data below seems different , Use chunked after , The data consists of the previous single line string mobian, It becomes multi row data . And mobian Ahead 6 just mobian Length of string ,23 Ahead 2 just 23 The length of , Finally 0 ending .
summary :
namely content-length It is transmitted based on the total length of data , and chunked It is transmitted in blocks , Each piece is internally transmitted according to the previous length , Until the length is 0 after , Stop data transfer . If two exist at the same time , be content-length invalid .
Two 、tomcat Source code
tomcat Chinese vs Content-length and Transfer-Encoding Data processing of .
1、Request The process
A request is in tomcat The internal call logic of is not repeated here , For those who don't know, please refer to my previous blog : Talking about Tomcat The internal execution process after receiving a request ( Source code )
It will eventually call prepareRequest() Method
1、prepareRequest Method until after the position in the figure below
- First, I will get transfer-encoding attribute
- Then according to the parameters configured later , Pass to addInputFilter Method

2、 If the following parameter is chunked, It will be contentDelimitation Set to true

3、 The analysis is finished transfer-encoding after
- First of all get contentLength
- When the content length is greater than 0 after , Will judge contentDelimitation The state of , If we configure it chunked Then change the value to true
- contentDelimitation by true after , Will remove content-length node , That is, both exist at the same time ,contentlength invalid

2、 other
If you want to know contentlength and chunked There are two ways to read the logic code of data , You can check InputFilter Two implementation classes of the interface , namely IdentityInputFilter(contentlength) and ChunkedInputFilter(chunked) Two kinds of doRead Method .

边栏推荐
- E-R画图明确内容
- What if the notebook computer cannot run the CMD command
- C # connect to MySQL database
- Organigramme des activités
- Sorting out dialectics of nature
- Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
- Real world anti sample attack against semantic segmentation
- Business architecture diagram
- open3d学习笔记三【采样与体素化】
- JVM instructions
猜你喜欢

Execution of procedures

Embedding malware into neural networks

针对tqdm和print的顺序问题

静态库和动态库
![Open3d learning note 4 [surface reconstruction]](/img/9d/c1c3f2f3d4acd74a2c043571a120b3.png)
Open3d learning note 4 [surface reconstruction]

Dynamic extensible representation for category incremental learning -- der

Replace self attention with MLP

用全连接层替代掉卷积 -- RepMLP

Open3D学习笔记一【初窥门径,文件读取】

Correction binoculaire
随机推荐
应对长尾分布的目标检测 -- Balanced Group Softmax
【Programming】
Jetson nano installation tensorflow stepping pit record (scipy1.4.1)
The hystrix dashboard reported an error hystrix Stream is not in the allowed list of proxy host names solution
[multimodal] clip model
C#与MySQL数据库连接
【DIoU】《Distance-IoU Loss:Faster and Better Learning for Bounding Box Regression》
静态库和动态库
用MLP代替掉Self-Attention
【Hide-and-Seek】《Hide-and-Seek: A Data Augmentation Technique for Weakly-Supervised Localization xxx》
A brief analysis of graph pooling
Memory model of program
利用超球嵌入来增强对抗训练
[Sparse to Dense] Sparse to Dense: Depth Prediction from Sparse Depth samples and a Single Image
Using super ball embedding to enhance confrontation training
简易打包工具的安装与使用
最长等比子序列
【Cascade FPD】《Deep Convolutional Network Cascade for Facial Point Detection》
open3d环境错误汇总
【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》