Skip to content

Commit

Permalink
Merge pull request #286 from plone/frapell-ical
Browse files Browse the repository at this point in the history
Make sure to include the 'Content-Length' header for ical exports
  • Loading branch information
thet authored Sep 14, 2018
2 parents 0ca8a7f + 28c562b commit 4d3eda8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ New features:

Bug fixes:

- Make sure to include the 'Content-Length' header for ical exports
[frapell]

- Update plone.app.event resources. Requires plonetheme.barceloneta >= 1.9.
[agitator]

Expand Down
4 changes: 3 additions & 1 deletion plone/app/event/browser/event_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ def ical(self):
batch=False)
cal = construct_icalendar(self.context, events)
name = '%s.ics' % self.context.getId()
contents = cal.to_ical()
self.request.response.setHeader('Content-Type', 'text/calendar')
self.request.response.setHeader(
'Content-Disposition',
'attachment; filename="%s"' % name
)
self.request.response.write(cal.to_ical())
self.request.response.setHeader('Content-Length', len(contents))
self.request.response.write(contents)

@property
def ical_url(self):
Expand Down
2 changes: 1 addition & 1 deletion plone/app/event/ical/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,6 @@ def __call__(self):
'Content-Disposition',
'attachment; filename="{0}"'.format(name)
)
self.request.response.setHeader('Content-Length', len(ical))
self.request.response.setHeader('Pragma', 'no-cache')
self.request.response.setHeader('Content-Length', len(ical))
self.request.response.write(ical)
3 changes: 2 additions & 1 deletion plone/app/event/tests/test_event_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def test_events_listing_ical(self):
headers, output, request = make_fake_response(self.request)
view = self._listing_view(name='@@event_listing_ical')
view()
self.assertEqual(len(headers), 2)
self.assertEqual(len(headers), 3)
self.assertEqual(headers['Content-Type'], 'text/calendar')
self.assertTrue('Content-Length' in headers)
icalstr = ''.join(output)
self.assertTrue('Long Event' in icalstr)

Expand Down
11 changes: 9 additions & 2 deletions plone/app/event/tests/test_icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_event_ical(self):
view()
self.assertEqual(len(headers), 4)
self.assertEqual(headers['Content-Type'], 'text/calendar')
self.assertTrue('Content-Length' in headers)
icalstr = ''.join(output)

self.checkOrder(
Expand Down Expand Up @@ -94,6 +95,7 @@ def test_event_occurrence_ical(self):
view()
self.assertEqual(len(headers), 4)
self.assertEqual(headers['Content-Type'], 'text/calendar')
self.assertTrue('Content-Length' in headers)
icalstr = ''.join(output)
self.assertTrue('Now Event' in icalstr)
self.assertTrue('RRULE' not in icalstr)
Expand All @@ -104,6 +106,7 @@ def test_portal_ical(self):
view()
self.assertEqual(len(headers), 4)
self.assertEqual(headers['Content-Type'], 'text/calendar')
self.assertTrue('Content-Length' in headers)
icalstr = ''.join(output)

# No occurrences in export. Otherwise count would be 8.
Expand Down Expand Up @@ -195,8 +198,9 @@ def test_event_listing_ical_portal(self):
)
view.mode = 'all'
view()
self.assertEqual(len(headers), 2)
self.assertEqual(len(headers), 3)
self.assertEqual(headers['Content-Type'], 'text/calendar')
self.assertTrue('Content-Length' in headers)
icalstr = ''.join(output)
# No occurrences in export. Otherwise count would be 8.
self.assertEqual(icalstr.count('BEGIN:VEVENT'), 4)
Expand All @@ -213,8 +217,9 @@ def test_event_listing_ical_portal__specific_date(self):
view.mode = 'day'
view._date = '2013-04-27'
view()
self.assertEqual(len(headers), 2)
self.assertEqual(len(headers), 3)
self.assertEqual(headers['Content-Type'], 'text/calendar')
self.assertTrue('Content-Length' in headers)
icalstr = ''.join(output)
self.assertEqual(icalstr.count('BEGIN:VEVENT'), 2)
self.assertTrue('Past Event' in icalstr)
Expand All @@ -231,6 +236,7 @@ def test_collection_ical(self):
view()
self.assertEqual(len(headers), 4)
self.assertEqual(headers['Content-Type'], 'text/calendar')
self.assertTrue('Content-Length' in headers)
icalstr = ''.join(output)
self.assertEqual(icalstr.count('BEGIN:VEVENT'), 4)

Expand All @@ -252,6 +258,7 @@ def test_collection_all_ical(self):
view()
self.assertEqual(len(headers), 4)
self.assertEqual(headers['Content-Type'], 'text/calendar')
self.assertTrue('Content-Length' in headers)
icalstr = ''.join(output)
self.assertEqual(icalstr.count('BEGIN:VEVENT'), 4)

Expand Down

0 comments on commit 4d3eda8

Please sign in to comment.