Skip to content
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

Add environment variable NO_BUFFERING to disable output buffering #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fcgiwrap.8
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ FCGI_CHDIR
By default fcgiwrap changes to the directory containing the CGI script before executing it (per CGI spec).
You may override this behaviour by passing FCGI_CHDIR containing the script's expected working directory
or \- to skip the directory change completely.
.RE
NO_BUFFERING
.RS
When set (e.g., to ""), disables output buffering.

.SH EXAMPLE
The fastest way to see \fBfcgiwrap\fP do something is to launch it at the command line
Expand Down
6 changes: 6 additions & 0 deletions fcgiwrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ struct fcgi_context {
int fd_stderr;
unsigned int reply_state;
pid_t cgi_pid;
int unbuffered;
};

static void fcgi_finish(struct fcgi_context *fc, const char* msg)
Expand Down Expand Up @@ -256,6 +257,10 @@ static const char * fcgi_pass_fd(struct fcgi_context *fc, int *fdp, FCGI_FILE *f
return "writing CGI reply";
}
}

if (fc->unbuffered && FCGI_fflush(ffp)) {
return "flushing CGI reply";
}
} else {
if (nread < 0) {
return "reading CGI reply";
Expand Down Expand Up @@ -590,6 +595,7 @@ static void handle_fcgi_request(void)
fc.fd_stderr = pipe_err[0];
fc.reply_state = REPLY_STATE_INIT;
fc.cgi_pid = pid;
fc.unbuffered = !!getenv("NO_BUFFERING");

fcgi_pass(&fc);
}
Expand Down