Apache, cgi script run twice when ssl, once when not ssl

I have interesting problem.
https:/host/some/x.cgi

  • this script has run twice when I call this url
    But
    http:/host/some/x.cgi
    work fine, only once.

Output is text/plain.

If I change output format to the Content-type text/html,
then both urls works fine - executed only once.

On first glance I would say that it depends what's in the script - it is possible that apache will redirect the https request to a plain http, thus executing it twice. Please share more info on the OS and the env. in general.

Debian, Apache 2. No proxy.
Why redirect plain, but not html ? I have tried to find this kind of conf, but not so lucky.
And we have mod_jk in use. Is that the problem ? ssl url 1st handled by Tomcat and after that forward to the apache even apache is the front server ?

Twice (https), once http:

echo "Content-type: text/plain"
echo 
env

Once (https and http)

echo "Content-type: text/html"
echo 
echo "<html><body>"
env
echo "</body></html>"