From d376cc553f1c354ec31d114409d31d425f320267 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Fri, 10 Dec 2021 21:07:46 -0500 Subject: [PATCH] avoid changing the stdout mode unless that function is actually called - no need so do it in a static ctor anyway --- cgi.d | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cgi.d b/cgi.d index 55b06ad..1566721 100644 --- a/cgi.d +++ b/cgi.d @@ -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);