HTTPS should be on if there are no misconfiguration. SERVER_PORT check dropped cause it's not a reliable value.
Uncommented the SSL redirection
RestResponse content property access replaced by getContents method use.
witched db driver to getContents for internal resources