brightprogrammer
brightprogrammer
CDCloudflare Developers
Created by brightprogrammer on 12/24/2024 in #general-help
Client Request body Empty
Background: I'm using a cloudflare tunnel. I'm writing an API. Problem: When I try to reach the API endpoints using my domain name as host, through the tunnel, I don't get the request body from client at all! This is present in neither the logs that the API backend generates, nor the logs stream on cloudflare tunnels log stream dashboard. The API backend receives and sends responses correctly when I access it on localhost directly. Example:
curl -X GET https://api.brightprogrammer.in/list_users \
-H "Content-Type: application/json" -H "Content-Length: 24" \
-d '{"user_type": "student"}'

{"error": "Bad Request."}
curl -X GET https://api.brightprogrammer.in/list_users \
-H "Content-Type: application/json" -H "Content-Length: 24" \
-d '{"user_type": "student"}'

{"error": "Bad Request."}
vs
curl -X GET http://localhost:1337/list_users \
-H "Content-Type: application/json" -H "Content-Length: 24" \
-d '{"user_type": "student"}'

{
"user_list": [
{
"user_name": "john_doe",
"user_type": "admin"
},
],
"has_more": false
}
curl -X GET http://localhost:1337/list_users \
-H "Content-Type: application/json" -H "Content-Length: 24" \
-d '{"user_type": "student"}'

{
"user_list": [
{
"user_name": "john_doe",
"user_type": "admin"
},
],
"has_more": false
}
Logs Generated:
[INFO] [2024-12-24 11:38:06] [main:352] REQUEST :GET /list_users HTTP/1.1
Host: api.brightprogrammer.in
User-Agent: curl/8.7.1
Content-Length: 24
Accept: */*
Accept-Encoding: gzip, br
Cdn-Loop: cloudflare; loops=1
Cf-Connecting-Ip: 2405:201:a408:e81b:fc94:99bc:bc8:604a
Cf-Ipcountry: IN
Cf-Ray: 8f6e6a37ce6b667a-AMS
Cf-Visitor: {"scheme":"https"}
Cf-Warp-Tag-Id: 2127ba3f-3f68-4f00-9b4e-ee67ef924542
Connection: keep-alive
Content-Type: application/json
X-Forwarded-For: 2405:201:a408:e81b:fc94:99bc:bc8:604a
X-Forwarded-Proto: https


[INFO] [2024-12-24 11:38:06] [HttpRequestParse:272] request ended while 24 bytes were left to read.
[INFO] [2024-12-24 11:38:06] [main:356] failed to parse http request
[INFO] [2024-12-24 11:38:06] [main:352] REQUEST :GET /list_users HTTP/1.1
Host: api.brightprogrammer.in
User-Agent: curl/8.7.1
Content-Length: 24
Accept: */*
Accept-Encoding: gzip, br
Cdn-Loop: cloudflare; loops=1
Cf-Connecting-Ip: 2405:201:a408:e81b:fc94:99bc:bc8:604a
Cf-Ipcountry: IN
Cf-Ray: 8f6e6a37ce6b667a-AMS
Cf-Visitor: {"scheme":"https"}
Cf-Warp-Tag-Id: 2127ba3f-3f68-4f00-9b4e-ee67ef924542
Connection: keep-alive
Content-Type: application/json
X-Forwarded-For: 2405:201:a408:e81b:fc94:99bc:bc8:604a
X-Forwarded-Proto: https


[INFO] [2024-12-24 11:38:06] [HttpRequestParse:272] request ended while 24 bytes were left to read.
[INFO] [2024-12-24 11:38:06] [main:356] failed to parse http request
vs
[INFO] [2024-12-24 11:39:02] [main:352] REQUEST :GET /list_users HTTP/1.1
Host: localhost:1337
User-Agent: curl/8.7.1
Accept: */*
Content-Type: application/json
Content-Length: 24

{"user_type": "student"}
[INFO] [2024-12-24 11:39:02] [main:352] REQUEST :GET /list_users HTTP/1.1
Host: localhost:1337
User-Agent: curl/8.7.1
Accept: */*
Content-Type: application/json
Content-Length: 24

{"user_type": "student"}
Expected: The backend through tunnel receives full request body, like it happens when not using the tunnel.
17 replies