-
Notifications
You must be signed in to change notification settings - Fork 41
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
#291 fix error when using reverse proxy #292
Conversation
@@ -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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
191cc6d
to
6f23874
Compare
…curity reasons. Setting the length to 0 and activate keepAlive and chunkedEncoding will solve the problem.
6f23874
to
b42dbcf
Compare
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