Use the correct protocol for S3 attachment URLs based on the request security level

Problem: the generated URL for S3 attachments always uses the HTTP protocol. In the context of secure requests (made over HTTPS), the generated URL should use the HTTPS protocol instead.

Solution: Chosing the URL protocol during persistence of the attachment is not ideal because the attachment may be used in secured and unsecured contexts later. The correct protocol should be determined during the URL generation. This patch replaces the HTTP protocol and removes the port (:80) from the generated URL whenever the request is secure.
Fix the attachment URL only if the attachment is not proxied
Merge pull request #528 from hprange/bugfix/erattachment-s3-secure-url

Use the correct protocol for S3 attachment URLs based on the request security level