From 9648303509735d5f705099e40e44e75eae46dea1 Mon Sep 17 00:00:00 2001 From: Robert Landers Date: Thu, 28 Mar 2024 20:10:05 +0100 Subject: [PATCH 01/10] found another spot that was preventing http1 writes --- caddy/frankenphp/Caddyfile | 4 ++++ frankenphp.go | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/caddy/frankenphp/Caddyfile b/caddy/frankenphp/Caddyfile index ae2e5c5ad..5b52806d1 100644 --- a/caddy/frankenphp/Caddyfile +++ b/caddy/frankenphp/Caddyfile @@ -5,6 +5,10 @@ #worker /path/to/your/worker.php {$FRANKENPHP_CONFIG} } + + servers { + enable_full_duplex + } # https://caddyserver.com/docs/caddyfile/directives#sorting-algorithm order mercure after encode diff --git a/frankenphp.go b/frankenphp.go index 6272d12a3..8df3ee434 100644 --- a/frankenphp.go +++ b/frankenphp.go @@ -720,13 +720,6 @@ func go_sapi_flush(rh C.uintptr_t) bool { return true } - if r.ProtoMajor == 1 { - if _, err := r.Body.Read(nil); err != nil { - // Don't flush until the whole body has been read to prevent https://github.com/golang/go/issues/15527 - return false - } - } - if err := http.NewResponseController(fc.responseWriter).Flush(); err != nil { fc.logger.Error("the current responseWriter is not a flusher", zap.Error(err)) } From 5537040c1944f401162413c85a6acaad7989bc15 Mon Sep 17 00:00:00 2001 From: Robert Landers Date: Tue, 9 Apr 2024 10:33:23 +0200 Subject: [PATCH 02/10] remove full-duplex from caddyfile --- caddy/frankenphp/Caddyfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/caddy/frankenphp/Caddyfile b/caddy/frankenphp/Caddyfile index 5b52806d1..ae2e5c5ad 100644 --- a/caddy/frankenphp/Caddyfile +++ b/caddy/frankenphp/Caddyfile @@ -5,10 +5,6 @@ #worker /path/to/your/worker.php {$FRANKENPHP_CONFIG} } - - servers { - enable_full_duplex - } # https://caddyserver.com/docs/caddyfile/directives#sorting-algorithm order mercure after encode From 6635eed68ad634764b00eb677125294619acc006 Mon Sep 17 00:00:00 2001 From: Robert Landers Date: Tue, 9 Apr 2024 10:42:09 +0200 Subject: [PATCH 03/10] update documentation --- docs/config.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/config.md b/docs/config.md index 8350581c7..286d5817f 100644 --- a/docs/config.md +++ b/docs/config.md @@ -129,6 +129,30 @@ php_server [] { } ``` +### Full Duplex (h1) + +When using http 1.x, it may be desirable to enable full-duplex mode to allow writing a response before the entire body +has been read. (for example: websockets, SSE, etc.) + +This is an opt-in configuration that needs to be added to the global options in the caddyfile: + +```caddyfile +{ + servers { + enable_full_duplex + } +} +``` + +This can also be configured using the `CADDY_GLOBAL_OPTIONS` environment config: + +``` +ENV CADDY_GLOBAL_OPTIONS="servers { enable_full_duplex }" +``` + +You can find more information about this setting in Caddy documentation: +https://caddyserver.com/docs/caddyfile/options#enable-full-duplex + ## Environment Variables The following environment variables can be used to inject Caddy directives in the `Caddyfile` without modifying it: From 7f2184539c76d66e48f41e025453ec501020bedd Mon Sep 17 00:00:00 2001 From: Rob Landers Date: Tue, 9 Apr 2024 14:38:27 +0200 Subject: [PATCH 04/10] fix: update http name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin Dunglas --- docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index 286d5817f..60c87c272 100644 --- a/docs/config.md +++ b/docs/config.md @@ -129,7 +129,7 @@ php_server [] { } ``` -### Full Duplex (h1) +### Full Duplex (HTTP/1) When using http 1.x, it may be desirable to enable full-duplex mode to allow writing a response before the entire body has been read. (for example: websockets, SSE, etc.) From 605abb713e7e62401398ba8054f4a1e175f6093d Mon Sep 17 00:00:00 2001 From: Rob Landers Date: Tue, 9 Apr 2024 14:38:44 +0200 Subject: [PATCH 05/10] fix: update http name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin Dunglas --- docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index 60c87c272..e45ae4ecb 100644 --- a/docs/config.md +++ b/docs/config.md @@ -131,7 +131,7 @@ php_server [] { ### Full Duplex (HTTP/1) -When using http 1.x, it may be desirable to enable full-duplex mode to allow writing a response before the entire body +When using HTTP/1.x, it may be desirable to enable full-duplex mode to allow writing a response before the entire body has been read. (for example: websockets, SSE, etc.) This is an opt-in configuration that needs to be added to the global options in the caddyfile: From 3db0e498ca2efaaa4abe72db559c2994686d5776 Mon Sep 17 00:00:00 2001 From: Rob Landers Date: Tue, 9 Apr 2024 14:39:55 +0200 Subject: [PATCH 06/10] fix: names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin Dunglas --- docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index e45ae4ecb..88c432eb0 100644 --- a/docs/config.md +++ b/docs/config.md @@ -132,7 +132,7 @@ php_server [] { ### Full Duplex (HTTP/1) When using HTTP/1.x, it may be desirable to enable full-duplex mode to allow writing a response before the entire body -has been read. (for example: websockets, SSE, etc.) +has been read. (for example: WebSocket, Server-Sent Events, etc.) This is an opt-in configuration that needs to be added to the global options in the caddyfile: From dddeb4da779a2c2900cbb1f67bd6c15f01b0fc2a Mon Sep 17 00:00:00 2001 From: Rob Landers Date: Tue, 9 Apr 2024 14:40:22 +0200 Subject: [PATCH 07/10] fix: update caddyfile name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin Dunglas --- docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index 88c432eb0..4e0d84945 100644 --- a/docs/config.md +++ b/docs/config.md @@ -134,7 +134,7 @@ php_server [] { When using HTTP/1.x, it may be desirable to enable full-duplex mode to allow writing a response before the entire body has been read. (for example: WebSocket, Server-Sent Events, etc.) -This is an opt-in configuration that needs to be added to the global options in the caddyfile: +This is an opt-in configuration that needs to be added to the global options in the `Caddyfile`: ```caddyfile { From cc259e80272f06509f282419322469966ffcedf6 Mon Sep 17 00:00:00 2001 From: Rob Landers Date: Tue, 9 Apr 2024 14:40:41 +0200 Subject: [PATCH 08/10] Add caution to docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin Dunglas --- docs/config.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/config.md b/docs/config.md index 4e0d84945..bff752d5c 100644 --- a/docs/config.md +++ b/docs/config.md @@ -144,6 +144,9 @@ This is an opt-in configuration that needs to be added to the global options in } ``` +> ![CAUTION] +> +> Enabling this option may cause old HTTP/1.x clients that don't support full-duplex to deadlock. This can also be configured using the `CADDY_GLOBAL_OPTIONS` environment config: ``` From b8c9951a0849c02e1b01ee5e0510f5ac5c846f87 Mon Sep 17 00:00:00 2001 From: Rob Landers Date: Tue, 9 Apr 2024 14:40:54 +0200 Subject: [PATCH 09/10] Update config.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin Dunglas --- docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index bff752d5c..1bf380490 100644 --- a/docs/config.md +++ b/docs/config.md @@ -150,7 +150,7 @@ This is an opt-in configuration that needs to be added to the global options in This can also be configured using the `CADDY_GLOBAL_OPTIONS` environment config: ``` -ENV CADDY_GLOBAL_OPTIONS="servers { enable_full_duplex }" +CADDY_GLOBAL_OPTIONS="servers { enable_full_duplex }" ``` You can find more information about this setting in Caddy documentation: From 47cd6363120bfdf563137bfc2e44e114ca48a68b Mon Sep 17 00:00:00 2001 From: Robert Landers Date: Tue, 9 Apr 2024 22:39:55 +0200 Subject: [PATCH 10/10] fix lint --- docs/config.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/config.md b/docs/config.md index 1bf380490..31df71d52 100644 --- a/docs/config.md +++ b/docs/config.md @@ -149,12 +149,11 @@ This is an opt-in configuration that needs to be added to the global options in > Enabling this option may cause old HTTP/1.x clients that don't support full-duplex to deadlock. This can also be configured using the `CADDY_GLOBAL_OPTIONS` environment config: -``` +```sh CADDY_GLOBAL_OPTIONS="servers { enable_full_duplex }" ``` -You can find more information about this setting in Caddy documentation: -https://caddyserver.com/docs/caddyfile/options#enable-full-duplex +You can find more information about this setting in the [Caddy documentation](https://caddyserver.com/docs/caddyfile/options#enable-full-duplex). ## Environment Variables