SSL/HTTPS Detection fix

Should be a more reliable way to fix #5.

Props to @emilbjorklund for reporting the initial problem.

@emilbjorklund, does this solution work for you? Thanks.