I am using reqwest in rust to do a simple POST action:
let client = reqwest::blocking::Client::new();
let file = File::open("somefile");
let res = client
.post("http://127.0.0.1:5001/api/v0/add")
.body(file)
.send()?;
I got 400 response. So I used wireshark to check the request sent by reqwest. Interestingly, there was none. All I got was the 400 response.
So I used strace
, and compared with cURL.
For cURL, I got:
socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP) = 3
socketpair(AF_UNIX, SOCK_STREAM, 0, [3, 4]) = 0
socket(AF_INET, SOCK_STREAM, IPPROTO_IP) = 5
setsockopt(5, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(5, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
setsockopt(5, SOL_TCP, TCP_KEEPIDLE, [60], 4) = 0
setsockopt(5, SOL_TCP, TCP_KEEPINTVL, [60], 4) = 0
connect(5, {sa_family=AF_INET, sin_port=htons(5001), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
getsockopt(5, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
getpeername(5, {sa_family=AF_INET, sin_port=htons(5001), sin_addr=inet_addr("127.0.0.1")}, [128 => 16]) = 0
getsockname(5, {sa_family=AF_INET, sin_port=htons(59784), sin_addr=inet_addr("127.0.0.1")}, [128 => 16]) = 0
sendto(5, "POST /api/v0/add HTTP/1.1\r\nHost: 127.0.0.1:5001\r\nUser-Agent: curl/7.80.0\r\nAccept: */*\r\nContent-Length: 1720244\r\nContent-Type: multipart/form-data; boundary=------------------------dfd2b9478efb2b2d\r\nExpect: 100-continue\r\n\r\n", 222, MSG_NOSIGNAL, NULL, 0) = 222
recvfrom(5, "HTTP/1.1 100 Continue\r\n\r\n", 102400, 0, NULL, NULL) = 25
and more after.
But for my app, I got:
socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP) = 7
connect(7, {sa_family=AF_INET, sin_port=htons(5001), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
getsockopt(7, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
setsockopt(7, SOL_TCP, TCP_NODELAY, [0], 4) = 0
getpeername(7, {sa_family=AF_INET, sin_port=htons(5001), sin_addr=inet_addr("127.0.0.1")}, [128 => 16]) = 0
recvfrom(7, "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain; charset=utf-8\r\nVary: Origin\r\nX-Content-Type-Options: nosniff\r\nDate: Sat, 04 Dec 2021 13:02:05 GMT\r\nContent-Length: 33\r\n\r\nfile argument 'path' is required\n", 8192, 0, NULL, NULL) = 206
recvfrom(7, 0x7f923c0f0e00, 8192, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)
So why is there no sendto
call?
The strace calls are the same: strace -f -e trace=network -s 10000 $cmd
.