The unit test for cgi fails under Windows, and I think it is because of cgi_open behavior. Somewhere deep in packages/http/cgi_stream.c, a hook is created that does several useful things, but, on Windows, replaces \n by \r\n even in the data segment. This causes some of the unit tests to fail, since they pipe an atom with ascii codes from 1 to 128 through the test and check if it returns exactly like that.
One can observe the problem by tracing through packages/http/test_cgi_stream.pl and investigating the temporary file using a hexeditor right here:
test(traditional,
[ forall(current_data(Name)),
Reply == Data,
setup(open_dest(TmpF, Out)),
cleanup(free_dest(TmpF))
]) :-
data(Name, Data, ContentType),
cgi_open(Out, CGI, cgi_hook, []),
format(CGI, 'Content-type: ~w\n\n', [ContentType]),
format(CGI, '~w', [Data]),
close(CGI),
close(Out),
here!,
http_read_mf(TmpF, Header, Reply),
assert_header(Header, status(_, ok, _)).
It has the numbers 01 02 03 … 09, then 0D 0A 0B etc. The 0D is the \r. The problem can be fixed by telling the hook to use NL_POSIX, see below:
packages/http/cgi_stream.c
static foreign_t pl_cgi_open(term_t org, term_t new, term_t closure, term_t options)
{
...skipping a few lines...
line 800ff:
s2->encoding = ENC_ASCII; /* Header is ASCII only */
s2->newline = SIO_NL_POSIX; /* added this! */
ctx->parent_encoding = s->encoding;
s->encoding = ENC_OCTET;
ctx->cgi_stream = s2;
if ( PL_unify_stream(new, s2) )
{ Sset_filter(s, s2);
silent_release_stream(s);
LOCK();
ctx->id = ++current_id;
UNLOCK();
return TRUE;
} else
{ return instantiation_error();
}
}
Thank you for your consideration.