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

边栏推荐
- 【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
- What if a new window always pops up when opening a folder on a laptop
- 【C#笔记】winform中保存DataGridView中的数据为Excel和CSV
- Specification for package drawing
- How to turn on night mode on laptop
- 【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
- 業務架構圖
- Memory model of program
- 【MnasNet】《MnasNet:Platform-Aware Neural Architecture Search for Mobile》
- Sorting out dialectics of nature
猜你喜欢

open3d学习笔记三【采样与体素化】

Nacos service registration in the interface

【Batch】learning notes

jetson nano安装tensorflow踩坑记录(scipy1.4.1)

Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired

Target detection for long tail distribution -- balanced group softmax

【雙目視覺】雙目矯正

Memory model of program

Embedding malware into neural networks

MoCO ——Momentum Contrast for Unsupervised Visual Representation Learning
随机推荐
open3d学习笔记五【RGBD融合】
【雙目視覺】雙目矯正
【Random Erasing】《Random Erasing Data Augmentation》
Jetson nano installation tensorflow stepping pit record (scipy1.4.1)
WCF更新服务引用报错的原因之一
E-R draw clear content
【学习笔记】Matlab自编图像卷积函数
【BiSeNet】《BiSeNet:Bilateral Segmentation Network for Real-time Semantic Segmentation》
open3d学习笔记二【文件读写】
What if a new window always pops up when opening a folder on a laptop
浅谈深度学习模型中的后门
[binocular vision] binocular correction
Meta Learning 简述
简易打包工具的安装与使用
JVM instructions
【TCDCN】《Facial landmark detection by deep multi-task learning》
【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
【学习笔记】Matlab自编高斯平滑器+Sobel算子求导
【Random Erasing】《Random Erasing Data Augmentation》
[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video