avoid changing the stdout mode unless that function is actually called - no need so do it in a static ctor anyway

This commit is contained in:
Adam D. Ruppe 2021-12-10 21:07:46 -05:00
parent 48b2516415
commit d376cc553f
1 changed files with 10 additions and 8 deletions

18
cgi.d
View File

@ -573,14 +573,6 @@ private struct stdin {
import core.sys.windows.windows;
static:
shared static this() {
// Set stdin to binary mode
version(Win64)
_setmode(std.stdio.stdin.fileno(), 0x8000);
else
setmode(std.stdio.stdin.fileno(), 0x8000);
}
T[] rawRead(T)(T[] buf) {
uint bytesRead;
auto result = ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf.ptr, cast(int) (buf.length * T.sizeof), &bytesRead, null);
@ -4044,6 +4036,16 @@ void cgiMainImpl(alias fun, CustomCgi = Cgi, long maxContentLength = defaultMaxC
//version(plain_cgi)
void handleCgiRequest(alias fun, CustomCgi = Cgi, long maxContentLength = defaultMaxContentLength)() {
// standard CGI is the default version
// Set stdin to binary mode if necessary to avoid mangled newlines
version(Windows) {
version(Win64)
_setmode(std.stdio.stdin.fileno(), 0x8000);
else
setmode(std.stdio.stdin.fileno(), 0x8000);
}
Cgi cgi;
try {
cgi = new CustomCgi(maxContentLength);