Add automatic SSE detection and support to backend template
All checks were successful
HAProxy Manager Build and Push / Build-and-Push (push) Successful in 1m27s
All checks were successful
HAProxy Manager Build and Push / Build-and-Push (push) Successful in 1m27s
Changes: - Detect SSE via Accept header (text/event-stream) or ?action=stream parameter - Disable http-server-close to allow long-lived SSE connections - Enable http-no-delay for immediate event delivery - Set 1-hour timeouts for SSE support (also fine for normal requests) - Force Connection: keep-alive for detected SSE requests Benefits: - SSE now works automatically without special backend configuration - Fixes transcription server display disconnection issues - Normal HTTP requests still work perfectly - No need for separate SSE-specific backends Fixes: Server-Sent Events timing out through HAProxy
This commit is contained in:
@@ -1,5 +1,25 @@
|
|||||||
|
|
||||||
backend {{ name }}-backend
|
backend {{ name }}-backend
|
||||||
|
# Detect Server-Sent Events (SSE) connections
|
||||||
|
# SSE uses Accept: text/event-stream or ?action=stream query parameter
|
||||||
|
acl is_sse hdr(accept) -i -m sub text/event-stream
|
||||||
|
acl is_sse_url urlp(action) -i -m str stream
|
||||||
|
|
||||||
|
# Disable http-server-close from defaults to allow SSE long-lived connections
|
||||||
|
# Normal HTTP requests still work fine without this option
|
||||||
|
no option http-server-close
|
||||||
|
|
||||||
|
# Enable http-no-delay for immediate data transmission (good for SSE and general performance)
|
||||||
|
option http-no-delay
|
||||||
|
|
||||||
|
# Extended timeouts to support SSE long-lived connections
|
||||||
|
# These values also work fine for normal HTTP requests
|
||||||
|
timeout server 1h
|
||||||
|
timeout http-keep-alive 1h
|
||||||
|
|
||||||
|
# Ensure keep-alive connection for SSE requests
|
||||||
|
http-response set-header Connection keep-alive if is_sse or is_sse_url
|
||||||
|
|
||||||
option forwardfor
|
option forwardfor
|
||||||
# Pass the real client IP to backend (from proxy headers or direct connection)
|
# Pass the real client IP to backend (from proxy headers or direct connection)
|
||||||
# This is crucial for container-level logging and security tools
|
# This is crucial for container-level logging and security tools
|
||||||
@@ -7,9 +27,8 @@ backend {{ name }}-backend
|
|||||||
http-request set-header X-Real-IP %[var(txn.real_ip)]
|
http-request set-header X-Real-IP %[var(txn.real_ip)]
|
||||||
http-request set-header X-Forwarded-For %[var(txn.real_ip)]
|
http-request set-header X-Forwarded-For %[var(txn.real_ip)]
|
||||||
{% if ssl_enabled %}http-request set-header X-Forwarded-Proto https if { ssl_fc }{% endif %}
|
{% if ssl_enabled %}http-request set-header X-Forwarded-Proto https if { ssl_fc }{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% for server in servers %}
|
{% for server in servers %}
|
||||||
server {{ server.server_name }} {{ server.server_address }}:{{ server.server_port }} {{ server.server_options }}
|
server {{ server.server_name }} {{ server.server_address }}:{{ server.server_port }} {{ server.server_options }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
Reference in New Issue
Block a user