当前位置:网站首页>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 .

边栏推荐
- What if the laptop can't search the wireless network signal
- Target detection for long tail distribution -- balanced group softmax
- 联邦学习下的数据逆向攻击 -- GradInversion
- Remplacer l'auto - attention par MLP
- MySQL优化
- Business architecture diagram
- It's great to save 10000 pictures of girls
- Rhel7 operation level introduction and switching operation
- 【Hide-and-Seek】《Hide-and-Seek: A Data Augmentation Technique for Weakly-Supervised Localization xxx》
- 利用超球嵌入来增强对抗训练
猜你喜欢
利用Transformer来进行目标检测和语义分割
【MobileNet V3】《Searching for MobileNetV3》
open3d学习笔记三【采样与体素化】
What if the laptop task manager is gray and unavailable
Timeout docking video generation
jetson nano安装tensorflow踩坑记录(scipy1.4.1)
SQLyog远程连接centos7系统下的MySQL数据库
【Batch】learning notes
Several methods of image enhancement and matlab code
简易打包工具的安装与使用
随机推荐
Ppt skills
Open3D学习笔记一【初窥门径,文件读取】
Memory model of program
【MobileNet V3】《Searching for MobileNetV3》
What if the notebook computer cannot run the CMD command
Comparison of chat Chinese corpus (attach links to various resources)
AR system summary harvest
【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》
Eklavya -- infer the parameters of functions in binary files using neural network
【BiSeNet】《BiSeNet:Bilateral Segmentation Network for Real-time Semantic Segmentation》
Summary of solving the Jetson nano installation onnx error (error: failed building wheel for onnx)
静态库和动态库
Proof and understanding of pointnet principle
用全连接层替代掉卷积 -- RepMLP
Remplacer l'auto - attention par MLP
CPU register
Network metering - transport layer
E-R draw clear content
JVM instructions
使用C#语言来进行json串的接收