diff --git a/django/contrib/syndication/views.py b/django/contrib/syndication/views.py
index b99f3f9..b287544 100644
a
|
b
|
from django.utils import feedgenerator, tzinfo
|
8 | 8 | from django.utils.encoding import force_unicode, iri_to_uri, smart_unicode |
9 | 9 | from django.utils.html import escape |
10 | 10 | |
11 | | def add_domain(domain, url): |
| 11 | def add_domain(domain, url, secure=False): |
12 | 12 | if not (url.startswith('http://') |
13 | 13 | or url.startswith('https://') |
14 | 14 | or url.startswith('mailto:')): |
15 | 15 | # 'url' must already be ASCII and URL-quoted, so no need for encoding |
16 | 16 | # conversions here. |
17 | | url = iri_to_uri(u'http://%s%s' % (domain, url)) |
| 17 | if secure: |
| 18 | protocol = 'https' |
| 19 | else: |
| 20 | protocol = 'http' |
| 21 | url = iri_to_uri(u'%s://%s%s' % (protocol, domain, url)) |
18 | 22 | return url |
19 | 23 | |
20 | 24 | class FeedDoesNotExist(ObjectDoesNotExist): |
… |
… |
class Feed(object):
|
97 | 101 | current_site = RequestSite(request) |
98 | 102 | |
99 | 103 | link = self.__get_dynamic_attr('link', obj) |
100 | | link = add_domain(current_site.domain, link) |
| 104 | link = add_domain(current_site.domain, link, request.is_secure()) |
101 | 105 | |
102 | 106 | feed = self.feed_type( |
103 | 107 | title = self.__get_dynamic_attr('title', obj), |
… |
… |
class Feed(object):
|
105 | 109 | link = link, |
106 | 110 | description = self.__get_dynamic_attr('description', obj), |
107 | 111 | language = settings.LANGUAGE_CODE.decode(), |
108 | | feed_url = add_domain(current_site.domain, |
109 | | self.__get_dynamic_attr('feed_url', obj) or request.path), |
| 112 | feed_url = add_domain( |
| 113 | current_site.domain, |
| 114 | self.__get_dynamic_attr('feed_url', obj) or request.path, |
| 115 | request.is_secure(), |
| 116 | ), |
110 | 117 | author_name = self.__get_dynamic_attr('author_name', obj), |
111 | 118 | author_link = self.__get_dynamic_attr('author_link', obj), |
112 | 119 | author_email = self.__get_dynamic_attr('author_email', obj), |
… |
… |
class Feed(object):
|
140 | 147 | description = description_tmp.render(RequestContext(request, {'obj': item, 'site': current_site})) |
141 | 148 | else: |
142 | 149 | description = self.__get_dynamic_attr('item_description', item) |
143 | | link = add_domain(current_site.domain, self.__get_dynamic_attr('item_link', item)) |
| 150 | link = add_domain( |
| 151 | current_site.domain, |
| 152 | self.__get_dynamic_attr('item_link', item), |
| 153 | request.is_secure(), |
| 154 | ) |
144 | 155 | enc = None |
145 | 156 | enc_url = self.__get_dynamic_attr('item_enclosure_url', item) |
146 | 157 | if enc_url: |
diff --git a/tests/regressiontests/syndication/tests.py b/tests/regressiontests/syndication/tests.py
index 7911657..9939f70 100644
a
|
b
|
class SyndicationFeedTest(FeedTestCase):
|
235 | 235 | for link in doc.getElementsByTagName('link'): |
236 | 236 | if link.getAttribute('rel') == 'self': |
237 | 237 | self.assertEqual(link.getAttribute('href'), 'http://example.com/customfeedurl/') |
| 238 | |
| 239 | def test_secure_urls(self): |
| 240 | """ |
| 241 | Test URLs are prefixed with https:// when feed is requested over HTTPS. |
| 242 | """ |
| 243 | response = self.client.get('/syndication/rss2/', **{ |
| 244 | 'wsgi.url_scheme': 'https', |
| 245 | }) |
| 246 | doc = minidom.parseString(response.content) |
| 247 | chan = doc.getElementsByTagName('channel')[0] |
| 248 | self.assertEqual( |
| 249 | chan.getElementsByTagName('link')[0].firstChild.wholeText[0:5], |
| 250 | 'https' |
| 251 | ) |
| 252 | atom_link = chan.getElementsByTagName('atom:link')[0] |
| 253 | self.assertEqual(atom_link.getAttribute('href')[0:5], 'https') |
| 254 | for link in doc.getElementsByTagName('link'): |
| 255 | if link.getAttribute('rel') == 'self': |
| 256 | self.assertEqual(link.getAttribute('href')[0:5], 'https') |
238 | 257 | |
239 | 258 | def test_item_link_error(self): |
240 | 259 | """ |
… |
… |
class SyndicationFeedTest(FeedTestCase):
|
271 | 290 | 'http://example.com/foo/?arg=value' |
272 | 291 | ) |
273 | 292 | self.assertEqual( |
| 293 | views.add_domain('example.com', '/foo/?arg=value', True), |
| 294 | 'https://example.com/foo/?arg=value' |
| 295 | ) |
| 296 | self.assertEqual( |
274 | 297 | views.add_domain('example.com', 'http://djangoproject.com/doc/'), |
275 | 298 | 'http://djangoproject.com/doc/' |
276 | 299 | ) |