Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#291 fix error when using reverse proxy #292

Conversation

P1tt187
Copy link
Contributor

@P1tt187 P1tt187 commented Jan 12, 2025

Reverse proxies like traefik will block invalid content length for security reasons.

Setting the length to 0 and activate keepAlive and chunkedEncoding will solve the problem.

This should fix the issue #291

@@ -28,7 +28,6 @@ error_t handleApiSse(HttpConnection *connection, const char_t *uri, const char_t
mutex_unlock(MUTEX_SSE_CTX);
TRACE_ERROR("All slots full, in total %" PRIu8 " clients\r\n", sseSubscriptionCount);
httpInitResponseHeader(connection);
connection->response.contentLength = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content length is zero, as there is no body. Or did I miss something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I readded the content length for the 503 code

As I understand the function, it is providing a stream of events.
A stream has no explizit size, so we can omit the content length entirely

Why This Works:

  • Chunked Transfer Encoding: This allows the server to send data in chunks without specifying the total length upfront. The client (or reverse proxy) knows to keep the connection open and process each chunk as it arrives.
  • No Misleading Content-Length: By not setting Content-Length, you avoid confusing the client or reverse proxy about the nature of the response.

when i run this code my browser constantly receives keep-alive { "type":"keep-alive", "data":"" }

Currently I haven't connected a real box to the setup. Is this nessesary or is there a way to emulate a box?

Copy link
Contributor

@SciLor SciLor Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a 503, there is no chunked encoding. To simulate a connection, you can just open the SSE endpoint. If you spam it, the error should occur if all slots are used.

As there are keep-alives, no need for a real box to the the sse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of a 503 i changed the chunkedEncoding to false

is there something else need to be done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spamming the enpoint works, got a 503

@P1tt187 P1tt187 force-pushed the bugfix/291-unable-to-activate-rtnl-when-using-reverse-proxy branch from 191cc6d to 6f23874 Compare January 13, 2025 21:44
…curity reasons.

Setting the length to 0 and activate keepAlive and chunkedEncoding will solve the problem.
@P1tt187 P1tt187 force-pushed the bugfix/291-unable-to-activate-rtnl-when-using-reverse-proxy branch from 6f23874 to b42dbcf Compare January 14, 2025 23:04
@SciLor SciLor merged commit 83d3b29 into toniebox-reverse-engineering:master Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants