Skip to content

Commit 4dea23f

Browse files
committed
post-tests: Determine multipart boundary size dynamically
This determines the multipart boundary size based on the version of curl currently being used.
1 parent 2303137 commit 4dea23f

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

tests/post.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use curl::Version;
12
use std::time::Duration;
23

34
macro_rules! t {
@@ -23,24 +24,35 @@ fn handle() -> Easy {
2324
e
2425
}
2526

26-
#[cfg(feature = "static-curl")]
27+
fn multipart_boundary_size() -> usize {
28+
// Versions before 8.4.0 used a smaller multipart mime boundary, so the
29+
// exact content-length will differ between versions.
30+
if Version::get().version_num() >= 0x80400 {
31+
148
32+
} else {
33+
136
34+
}
35+
}
36+
2737
#[test]
2838
fn custom() {
39+
multipart_boundary_size();
2940
let s = Server::new();
30-
s.receive(
41+
s.receive(&format!(
3142
"\
3243
POST / HTTP/1.1\r\n\
3344
Host: 127.0.0.1:$PORT\r\n\
3445
Accept: */*\r\n\
35-
Content-Length: 154\r\n\
46+
Content-Length: {}\r\n\
3647
Content-Type: multipart/form-data; boundary=--[..]\r\n\
3748
\r\n\
3849
--[..]\r\n\
3950
Content-Disposition: form-data; name=\"foo\"\r\n\
4051
\r\n\
4152
1234\r\n\
4253
--[..]\r\n",
43-
);
54+
multipart_boundary_size() + 6
55+
));
4456
s.send("HTTP/1.1 200 OK\r\n\r\n");
4557

4658
let mut handle = handle();
@@ -55,12 +67,12 @@ fn custom() {
5567
#[test]
5668
fn buffer() {
5769
let s = Server::new();
58-
s.receive(
70+
s.receive(&format!(
5971
"\
6072
POST / HTTP/1.1\r\n\
6173
Host: 127.0.0.1:$PORT\r\n\
6274
Accept: */*\r\n\
63-
Content-Length: 193\r\n\
75+
Content-Length: {}\r\n\
6476
Content-Type: multipart/form-data; boundary=--[..]\r\n\
6577
\r\n\
6678
--[..]\r\n\
@@ -69,7 +81,8 @@ fn buffer() {
6981
\r\n\
7082
1234\r\n\
7183
--[..]\r\n",
72-
);
84+
multipart_boundary_size() + 45
85+
));
7386
s.send("HTTP/1.1 200 OK\r\n\r\n");
7487

7588
let mut handle = handle();
@@ -105,7 +118,7 @@ fn file() {
105118
{}\
106119
\r\n\
107120
--[..]\r\n",
108-
211 + formdata.len(),
121+
multipart_boundary_size() + 63 + formdata.len(),
109122
formdata
110123
)
111124
.as_str(),

0 commit comments

Comments
 (0)