cloudflare / cloudflared

Cloudflare Tunnel client (formerly Argo Tunnel)
https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide
Apache License 2.0
8.69k stars 767 forks source link

Header `Content-Length: 0` not sent to origin, present on original request #544

Open eliezedeck opened 2 years ago

eliezedeck commented 2 years ago

Hi,

We're running cloudflared and tunneling APIs thru it. Things are running smoothly in general.

But today, we have noticed a weird error on several PUT requests, it's only now that we have noticed about it.

First, we got 502 error, and we seem to receive header Transfer-Encoding: chunked, something that was not in the original request (this encoding is not supported by the origin). So, I have set disableChunkedEncoding: true.

Now the error is 411 Length Required error. I can confirm that I do send the Content-Length: 0 on the PUT request.

Here is the redacted output of the cloudflared running in debug mode:

2022-01-10T12:18:38Z DBG CF-RAY: 6cb5d95f9aff747c-LHR PUT http://localhost:8080/cards/toggle-contactless HTTP/2.0
2022-01-10T12:18:38Z DBG Inbound request CF-RAY=6cb5d95f9aff747c-LHR Header="map[Accept:[*/*] Accept-Encoding:[gzip] Authorization:[Bearer xxxxxxxxxxx] Cdn-Loop:[cloudflare] Cf-Connecting-Ip:[xxxxxxxxxx] Cf-Ipcountry:[GB] Cf-Ray:[6cb5d95f9aff747c-LHR] Cf-Visitor:[{\"scheme\":\"http\"}] Cf-Warp-Tag-Id:[b94c86d2-5894-492b-bd97-7a28798f5001] Content-Length:[0] Postman-Token:[f124e0b5-b210-449e-a1de-bfe6b42dadcd] User-Agent:[PostmanRuntime/7.28.4] X-Forwarded-For:[xxxxxxxxxx] X-Forwarded-Proto:[http]]" host=staging-mobile-api.xxxxxxxxx.fr path=/cards/toggle-contactless rule=0
2022-01-10T12:18:38Z DBG CF-RAY: 6cb5d95f9aff747c-LHR Request content length 0
2022-01-10T12:18:38Z DBG CF-RAY: 6cb5d95f9aff747c-LHR Status: 411 Length Required served by ingress 0
2022-01-10T12:18:38Z DBG CF-RAY: 6cb5d95f9aff747c-LHR Response Headers map[Content-Length:[0] Date:[Mon, 10 Jan 2022 12:18:38 GMT] Server:[Kestrel]]
2022-01-10T12:18:38Z DBG CF-RAY: 6cb5d95f9aff747c-LHR Response content length 0

I've tested the tunnel to my local machine, and see the exact request that is sent to the origin, and I conclude that Content-Length: 0 is actually removed from the original request and never sent to the origin server. That sounds like a bug to me.

I have no idea what's going on, and with the 411 error, the API is actually never called. Anyone has any idea how to solve this? Thanks.

NOTE: We would like to keep using disableChunkedEncoding: true if it's possible

aehlke commented 1 year ago

ever resolve? I seem to be hitting this maybe

eliezedeck commented 1 year ago

@aehlke I think not. I believe I patched the origin to handle this case instead. To be honest, I don't really remember how we managed to solve this, but it may be possible that we changed the API signature.

aehlke commented 1 year ago

I resolved by disabling chunked transfer resp