Add environment variable NO_BUFFERING to disable output buffering
Closes: #863478
Thanks: Peter Michael Green
Peter Colberg
5 years ago
0 | Description: Add environment variable NO_BUFFERING to disable output buffering | |
1 | Origin: https://github.com/notr1ch/fcgiwrap/commit/84c8b63fef6e400894ccc3c67f350ef868ab2e14.patch | |
2 | Author: Richard Stanway <r.stanway@gmail.com> | |
3 | Author: Peter Colberg <peter@colberg.org> | |
4 | Bug: https://github.com/gnosek/fcgiwrap/issues/36 | |
5 | Bug-Debian: https://bugs.debian.org/863478 | |
6 | Forwarded: https://github.com/gnosek/fcgiwrap/pull/48 | |
7 | Last-Update: 2018-12-08 | |
8 | ||
9 | --- a/fcgiwrap.8 | |
10 | +++ b/fcgiwrap.8 | |
11 | @@ -65,6 +65,10 @@ | |
12 | SCRIPT_FILENAME | |
13 | .RS | |
14 | complete path to CGI script. When set, overrides DOCUMENT_ROOT and SCRIPT_NAME | |
15 | +.RE | |
16 | +NO_BUFFERING | |
17 | +.RS | |
18 | +When set (e.g., to ""), disables output buffering. | |
19 | ||
20 | .SH EXAMPLE | |
21 | The fastest way to see \fBfcgiwrap\fP do something is to launch it at the command line | |
22 | --- a/fcgiwrap.c | |
23 | +++ b/fcgiwrap.c | |
24 | @@ -191,6 +191,7 @@ | |
25 | int fd_stderr; | |
26 | unsigned int reply_state; | |
27 | pid_t cgi_pid; | |
28 | + int unbuffered; | |
29 | }; | |
30 | ||
31 | static void fcgi_finish(struct fcgi_context *fc, const char* msg) | |
32 | @@ -256,6 +257,10 @@ | |
33 | return "writing CGI reply"; | |
34 | } | |
35 | } | |
36 | + | |
37 | + if (fc->unbuffered && FCGI_fflush(ffp)) { | |
38 | + return "flushing CGI reply"; | |
39 | + } | |
40 | } else { | |
41 | if (nread < 0) { | |
42 | return "reading CGI reply"; | |
43 | @@ -583,6 +588,7 @@ | |
44 | fc.fd_stderr = pipe_err[0]; | |
45 | fc.reply_state = REPLY_STATE_INIT; | |
46 | fc.cgi_pid = pid; | |
47 | + fc.unbuffered = !!getenv("NO_BUFFERING"); | |
48 | ||
49 | fcgi_pass(&fc); | |
50 | } |