@@ -37,15 +37,20 @@ def httpclient_log(*args):
37
37
38
38
def get_actual_request_data (log_stream ):
39
39
boundary_pattern = r"(?<=boundary=)(.\w*)"
40
+ content_length_pattern = r"(?<=Content-Length: )(.\d*)"
40
41
41
42
boundary = ""
42
43
actual_request_post = ""
44
+ content_length = ""
43
45
for log in log_stream :
44
46
for log_arg in log :
45
47
boundary_search = re .findall (boundary_pattern , log_arg )
48
+ content_length_search = re .findall (content_length_pattern , log_arg )
46
49
if boundary_search :
47
50
boundary = boundary_search [0 ]
48
- elif "Content-Disposition" in log_arg :
51
+ if content_length_search :
52
+ content_length = content_length_search [0 ]
53
+ if "Content-Disposition" in log_arg :
49
54
# this will look like:
50
55
# b\'{content}\'
51
56
# and escapped characters look like:
@@ -55,7 +60,7 @@ def get_actual_request_data(log_stream):
55
60
post_unescaped = post_bytes .decode ("unicode_escape" )
56
61
actual_request_post = post_unescaped .encode ("latin1" )
57
62
58
- return boundary , actual_request_post
63
+ return boundary , content_length , actual_request_post
59
64
60
65
61
66
def test_post_files_text ( # pylint: disable=unused-argument
@@ -66,7 +71,7 @@ def test_post_files_text( # pylint: disable=unused-argument
66
71
}
67
72
68
73
python_requests .post (post_url , files = file_data )
69
- boundary , actual_request_post = get_actual_request_data (log_stream )
74
+ boundary , content_length , actual_request_post = get_actual_request_data (log_stream )
70
75
71
76
requests ._build_boundary_string = mock .Mock (return_value = boundary )
72
77
requests .post ("http://" + mocket .MOCK_HOST_1 + "/post" , files = file_data )
@@ -84,7 +89,7 @@ def test_post_files_text( # pylint: disable=unused-argument
84
89
[
85
90
mock .call (b"Content-Length" ),
86
91
mock .call (b": " ),
87
- mock .call (b"131" ),
92
+ mock .call (content_length . encode () ),
88
93
mock .call (b"\r \n " ),
89
94
]
90
95
)
@@ -111,7 +116,9 @@ def test_post_files_file( # pylint: disable=unused-argument
111
116
}
112
117
113
118
python_requests .post (post_url , files = file_data )
114
- boundary , actual_request_post = get_actual_request_data (log_stream )
119
+ boundary , content_length , actual_request_post = get_actual_request_data (
120
+ log_stream
121
+ )
115
122
116
123
requests ._build_boundary_string = mock .Mock (return_value = boundary )
117
124
requests .post ("http://" + mocket .MOCK_HOST_1 + "/post" , files = file_data )
@@ -129,7 +136,7 @@ def test_post_files_file( # pylint: disable=unused-argument
129
136
[
130
137
mock .call (b"Content-Length" ),
131
138
mock .call (b": " ),
132
- mock .call (b"347" ),
139
+ mock .call (content_length . encode () ),
133
140
mock .call (b"\r \n " ),
134
141
]
135
142
)
@@ -164,7 +171,9 @@ def test_post_files_complex( # pylint: disable=unused-argument
164
171
}
165
172
166
173
python_requests .post (post_url , files = file_data )
167
- boundary , actual_request_post = get_actual_request_data (log_stream )
174
+ boundary , content_length , actual_request_post = get_actual_request_data (
175
+ log_stream
176
+ )
168
177
169
178
requests ._build_boundary_string = mock .Mock (return_value = boundary )
170
179
requests .post ("http://" + mocket .MOCK_HOST_1 + "/post" , files = file_data )
@@ -182,7 +191,7 @@ def test_post_files_complex( # pylint: disable=unused-argument
182
191
[
183
192
mock .call (b"Content-Length" ),
184
193
mock .call (b": " ),
185
- mock .call (b"796" ),
194
+ mock .call (content_length . encode () ),
186
195
mock .call (b"\r \n " ),
187
196
]
188
197
)
0 commit comments