Repository: boto/botocore (python)

Issue:
Region redirect does not honor scheme
Bucket in us-west-2
```
$ aws s3api get-bucket-location --bucket jamesls-test-sync
{
    "LocationConstraint": "us-west-2"
}
```

Specifying an http endpoint to us standard instead of us-west-2:


```
aws s3 cp /tmp/foo.txt s3://jamesls-test-sync/ --endpoint-url http://s3.amazonaws.com/ --debug
```

I can see we have the redirect logic now, but I can see it getting redirected from http to https:

```
2016-07-08 08:57:31,621 - Updating URI from http://s3.amazonaws.com/jamesls-test-sync to https://s3-us-west-2.amazonaws.com/jamesls-test-sync
```

I would expect that if we're going to change the URl we should still honor the scheme they've requested right?

cc @JordonPhillips 

Pull request:
Honor old scheme when redirecting S3 requests
If the old URL was using http over https, we will no continue to
use http.

Fixes #976
Closes #984

cc @kyleknap @jamesls

Patch:
diff --git a/.changes/next-release/bugfix-s3-36114.json b/.changes/next-release/bugfix-s3-36114.json
new file mode 100644
index 000000000..c15f29889
--- /dev/null
+++ b/.changes/next-release/bugfix-s3-36114.json
@@ -0,0 +1,5 @@
+{
+  "description": "S3 region redirector will now honor the orginial url scheme.",
+  "category": "s3",
+  "type": "bugfix"
+}
diff --git a/botocore/utils.py b/botocore/utils.py
index bf36041a6..4223ed864 100644
--- a/botocore/utils.py
+++ b/botocore/utils.py
@@ -922,7 +922,7 @@ class S3RegionRedirector(object):
     def set_request_url(self, params, context, **kwargs):
         endpoint = context.get('signing', {}).get('endpoint', None)
         if endpoint is not None:
-            params['url'] = _get_new_endpoint(params['url'], endpoint)
+            params['url'] = _get_new_endpoint(params['url'], endpoint, False)
 
     def redirect_from_cache(self, params, context, **kwargs):
         """


Test patch:
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index 2757ca5e2..68c878726 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -1000,6 +1000,15 @@ class TestS3RegionRedirector(unittest.TestCase):
         self.assertEqual(
             params['url'], 'https://us-west-2.amazonaws.com/foo')
 
+    def test_set_request_url_keeps_old_scheme(self):
+        params = {'url': 'http://us-west-2.amazonaws.com/foo'}
+        context = {'signing': {
+            'endpoint': 'https://eu-central-1.amazonaws.com'
+        }}
+        self.redirector.set_request_url(params, context)
+        self.assertEqual(
+            params['url'], 'http://eu-central-1.amazonaws.com/foo')
+
     def test_sets_signing_context_from_cache(self):
         signing_context = {'endpoint': 'bar'}
         self.cache['foo'] = signing_context