Currently, http:// is hardcoded in the constructor of AmazonS3StreamWrapper. To avoid warnings about insecure URLs, I would like to be able to change this to https://. I can make a patch for this if you want.

Comments

Jorrit’s picture

Status: Active » Needs review
StatusFileSize
new2.13 KB

Here is a patch for this feature.

tomfilepp’s picture

You saved the day, thanks for this.

alfaguru’s picture

I think it would be better to use protocol relative URLs and avoid any requirement for an extra variable. We serve some pages over SSL and some not, so the approach in the above patch won't help us. Here's how this can be done, instead:

--- a/sites/all/modules/contrib/amazons3/AmazonS3StreamWrapper.inc
+++ b/sites/all/modules/contrib/amazons3/AmazonS3StreamWrapper.inc
@@ -98,14 +98,14 @@ class AmazonS3StreamWrapper implements DrupalStreamWrapperInterface {
     if (variable_get('amazons3_cname', 0)) {
       $domain = variable_get('amazons3_domain', '');
       if(strlen($domain) > 0) {
-        $this->domain = 'http://' . $domain;
+        $this->domain = '//' . $domain;
       }
       else {
-        $this->domain = 'http://' . $this->bucket;
+        $this->domain = '//' . $this->bucket;
       }
     }
     else {
-      $this->domain = 'http://' . $this->bucket . '.s3.amazonaws.com';
+      $this->domain = '//' . $this->bucket . '.s3.amazonaws.com';
     }

     // Check whether local file caching is turned on
Jorrit’s picture

That is also fine for me, thanks for improving on the patch.

tripper54’s picture

I'm wondering if this should change the URL for https from

[bucket-name].s3.amazonaws.com

to

s3.amazonaws.com/[bucket-name]

Reason being if your bucket has dots in the name (eg files.mydomain.com) then amazon's *.s3.amazonaws.com certificate will not validate.

Or did you guys figure out another way around this problem?

geerlingguy’s picture

geerlingguy’s picture

StatusFileSize
new823 bytes

A patch-ified version of #3 attached.

geerlingguy’s picture

Title: Add option to use https:// for external urls » Serve files over SSL (https://) protocol if page is served via SSL.
StatusFileSize
new954 bytes

Updating title, new patch. Looking into this further, I found that emails (specifically) and other non-web contexts require an explicit protocol definition (like http://), and don't work with a simple //. Therefore, the attached patch detects whether the current page is being served over SSL or non-SSL, and defines the protocol appropriately.

[Edit: Of course, I hadn't tested this patch before posting it... therefore I didn't realize it didn't work :P. Back to patch in comment above until a better way can be found.]

davidwbarratt’s picture

Shouldn't you use $is_https instead of the $_SERVER super global?

Thanks!

davidwbarratt’s picture

Status: Needs review » Needs work

I tested the most recent patch and it works! The only thing that probably should be changed is using the $is_https unless someone has a reason why using the global is a bad idea in this context?

Thanks!

bkonetzny’s picture

Status: Needs work » Needs review
StatusFileSize
new1.06 KB

Attached patch uses the same logic Drupal core uses to set the current scheme (http or https) based on the $is_https global.

j.branson’s picture

Issue summary: View changes
StatusFileSize
new1.7 KB

This builds on #11 to permanently add https support for pre-signed and torrent urls as it seems if it is a pre-signed url then it should be served via https no matter. Uses AWS get_object_url $opts array().

justafish’s picture

Status: Needs review » Needs work

I would prefer the solution in #3

I don't think presigned and torrented URLs should be hardcoded to use ssl

justafish’s picture

Status: Needs work » Needs review
StatusFileSize
new9.36 KB

please review!

justafish’s picture

StatusFileSize
new9.03 KB

eww, whitespace

justafish’s picture

StatusFileSize
new9.09 KB

Fix some warnings when using "*" as the path

justafish’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.