prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  plone-upgrade to 5.0.3 shows plain text as result
  This is caused by https://github.com/plone/plone.app.upgrade/pull/67 by @vangheem, though this change looks fine to me.
  
  With the above change, when running `@@plone-upgrade`, even with dry-run selected, the result page is shown as text: you see plain html. Very strange. Reported here: https://community.plone.org/t/plone-5-0-3-soft-released/1699/4
  When I empty the registry.xml, keeping only the main `registry` tags for safety, it all works fine. Keeping one of the two changed records, it again shows as text.
  
  To check it:
  - Use current coredev 5.0
  - Create a Plone Site.
  - Simulate a Plone 5.0.2 site: in portal_setup, Upgrades, select Products.CMFPlone:plone, and run the to502 upgrade profile.
  - Go to @@plone-upgrade, optionally select dry-run, and run the upgrade.
  
  Result: it will show as plain text.
  BTW, afterwards, all is fine: the migration has succeeded and it looks like all pages show up fine.
  
  Any idea?
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `Products/CMFPlone/resources/exportimport/bundles.py`
  Content:
  ```
  1 from plone.registry.interfaces import IRegistry
  2 from zope.component import queryUtility
  3 
  4 from ..browser.combine import combine_bundles
  5 
  6 
  7 def combine(context):
  8 
  9     logger = context.getLogger('bundles')
  10     registry = queryUtility(IRegistry)
  11 
  12     if registry is None:
  13         logger.info("Cannot find registry")
  14         return
  15 
  16     body = context.readDataFile('registry.xml')
  17     if body and "IBundleRegistry" in body:
  18         site = context.getSite()
  19         combine_bundles(site)
  20
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/Products/CMFPlone/resources/exportimport/bundles.py b/Products/CMFPlone/resources/exportimport/bundles.py
  --- a/Products/CMFPlone/resources/exportimport/bundles.py
  +++ b/Products/CMFPlone/resources/exportimport/bundles.py
  @@ -1,5 +1,6 @@
   from plone.registry.interfaces import IRegistry
   from zope.component import queryUtility
  +from zope.globalrequest import getRequest
   
   from ..browser.combine import combine_bundles
   
  @@ -16,4 +17,20 @@
       body = context.readDataFile('registry.xml')
       if body and "IBundleRegistry" in body:
           site = context.getSite()
  +        # Calling combine_bundles will have as side effect that the
  +        # Content-Type header of the response is set to application/javascript,
  +        # which we do not want.  So we reset it to the original at the end.
  +        site = context.getSite()
  +        request = getattr(site, 'REQUEST', getRequest())
  +        if request is not None:
  +            # Easily happens in tests.
  +            orig_header = request.response.getHeader('Content-Type')
           combine_bundles(site)
  +        if request is not None:
  +            new_header = request.response.getHeader('Content-Type')
  +            if new_header != orig_header:
  +                if orig_header is None:
  +                    # Setting it to None would result in the string 'None'.
  +                    # So pick a saner one.
  +                    orig_header = 'text/html'
  +                request.response.setHeader('Content-Type', orig_header)
  
verification_info: {"golden_diff": "diff --git a/Products/CMFPlone/resources/exportimport/bundles.py b/Products/CMFPlone/resources/exportimport/bundles.py\n--- a/Products/CMFPlone/resources/exportimport/bundles.py\n+++ b/Products/CMFPlone/resources/exportimport/bundles.py\n@@ -1,5 +1,6 @@\n from plone.registry.interfaces import IRegistry\n from zope.component import queryUtility\n+from zope.globalrequest import getRequest\n \n from ..browser.combine import combine_bundles\n \n@@ -16,4 +17,20 @@\n     body = context.readDataFile('registry.xml')\n     if body and \"IBundleRegistry\" in body:\n         site = context.getSite()\n+        # Calling combine_bundles will have as side effect that the\n+        # Content-Type header of the response is set to application/javascript,\n+        # which we do not want.  So we reset it to the original at the end.\n+        site = context.getSite()\n+        request = getattr(site, 'REQUEST', getRequest())\n+        if request is not None:\n+            # Easily happens in tests.\n+            orig_header = request.response.getHeader('Content-Type')\n         combine_bundles(site)\n+        if request is not None:\n+            new_header = request.response.getHeader('Content-Type')\n+            if new_header != orig_header:\n+                if orig_header is None:\n+                    # Setting it to None would result in the string 'None'.\n+                    # So pick a saner one.\n+                    orig_header = 'text/html'\n+                request.response.setHeader('Content-Type', orig_header)\n", "issue": "plone-upgrade to 5.0.3 shows plain text as result\nThis is caused by https://github.com/plone/plone.app.upgrade/pull/67 by @vangheem, though this change looks fine to me.\n\nWith the above change, when running `@@plone-upgrade`, even with dry-run selected, the result page is shown as text: you see plain html. Very strange. Reported here: https://community.plone.org/t/plone-5-0-3-soft-released/1699/4\nWhen I empty the registry.xml, keeping only the main `registry` tags for safety, it all works fine. Keeping one of the two changed records, it again shows as text.\n\nTo check it:\n- Use current coredev 5.0\n- Create a Plone Site.\n- Simulate a Plone 5.0.2 site: in portal_setup, Upgrades, select Products.CMFPlone:plone, and run the to502 upgrade profile.\n- Go to @@plone-upgrade, optionally select dry-run, and run the upgrade.\n\nResult: it will show as plain text.\nBTW, afterwards, all is fine: the migration has succeeded and it looks like all pages show up fine.\n\nAny idea?\n\n", "before_files": [{"content": "from plone.registry.interfaces import IRegistry\nfrom zope.component import queryUtility\n\nfrom ..browser.combine import combine_bundles\n\n\ndef combine(context):\n\n    logger = context.getLogger('bundles')\n    registry = queryUtility(IRegistry)\n\n    if registry is None:\n        logger.info(\"Cannot find registry\")\n        return\n\n    body = context.readDataFile('registry.xml')\n    if body and \"IBundleRegistry\" in body:\n        site = context.getSite()\n        combine_bundles(site)\n", "path": "Products/CMFPlone/resources/exportimport/bundles.py"}], "after_files": [{"content": "from plone.registry.interfaces import IRegistry\nfrom zope.component import queryUtility\nfrom zope.globalrequest import getRequest\n\nfrom ..browser.combine import combine_bundles\n\n\ndef combine(context):\n\n    logger = context.getLogger('bundles')\n    registry = queryUtility(IRegistry)\n\n    if registry is None:\n        logger.info(\"Cannot find registry\")\n        return\n\n    body = context.readDataFile('registry.xml')\n    if body and \"IBundleRegistry\" in body:\n        site = context.getSite()\n        # Calling combine_bundles will have as side effect that the\n        # Content-Type header of the response is set to application/javascript,\n        # which we do not want.  So we reset it to the original at the end.\n        site = context.getSite()\n        request = getattr(site, 'REQUEST', getRequest())\n        if request is not None:\n            # Easily happens in tests.\n            orig_header = request.response.getHeader('Content-Type')\n        combine_bundles(site)\n        if request is not None:\n            new_header = request.response.getHeader('Content-Type')\n            if new_header != orig_header:\n                if orig_header is None:\n                    # Setting it to None would result in the string 'None'.\n                    # So pick a saner one.\n                    orig_header = 'text/html'\n                request.response.setHeader('Content-Type', orig_header)\n", "path": "Products/CMFPlone/resources/exportimport/bundles.py"}]}