you are right. Your examples work as I would expect.
I'm right to limino has a bug.
Something has changed between the version of openwrt I developed the scripts on and the current version and I'm happy to tell you that I know what.
Basically a CGI script must output a blank line. Everything before the blank line is removed.
The flowing shows this nicely as it has no content line and a blank space in the middle of the content
root@marvin2:/www/cgi-bin# cat test
root@marvin2:/www/cgi-bin# curl -vv http://localhost/cgi-bin/test
> GET /cgi-bin/test HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost
> Accept: */*
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Transfer-Encoding: chunked
< Keep-Alive: timeout=20
As you can see line 1 and 2 have been removed.
I call this a bug.