Initial attempt to fix #11 (my C is a bit rusty).
Merge pull request #11 from webfactory/issue-11

Look at X-Forwarded-Proto for the HTTPS environment variable