Converted direct use of http module to conditional http or https