mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
feat: option to enable full duplex for HTTP/1 connections (#692)
* found another spot that was preventing http1 writes * remove full-duplex from caddyfile * update documentation * fix: update http name Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * fix: update http name Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * fix: names Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * fix: update caddyfile name Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * Add caution to docs Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * Update config.md Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * fix lint --------- Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
This commit is contained in:
@@ -129,6 +129,32 @@ php_server [<matcher>] {
|
||||
}
|
||||
```
|
||||
|
||||
### 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: WebSocket, Server-Sent Events, etc.)
|
||||
|
||||
This is an opt-in configuration that needs to be added to the global options in the `Caddyfile`:
|
||||
|
||||
```caddyfile
|
||||
{
|
||||
servers {
|
||||
enable_full_duplex
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> ![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:
|
||||
|
||||
```sh
|
||||
CADDY_GLOBAL_OPTIONS="servers { 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
|
||||
|
||||
The following environment variables can be used to inject Caddy directives in the `Caddyfile` without modifying it:
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user