We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
BadHeaderError: Header values can't contain newlines (got 'attachment; filename="vendor.js.map\r\n\n             ...
https://sentry.io/sentry/sentry/issues/202980928/

```
BadHeaderError: Header values can't contain newlines (got 'attachment; filename="vendor.js.map\r\n\n                "')
(1 additional frame(s) were not displayed)
...
  File "sentry/api/base.py", line 86, in handle_exception
    return super(Endpoint, self).handle_exception(exc)
  File "sentry/api/base.py", line 180, in dispatch
    response = handler(request, *args, **kwargs)
  File "sentry/api/endpoints/release_file_details.py", line 123, in get
    return self.download(releasefile)
  File "sentry/api/endpoints/release_file_details.py", line 83, in download
    response['Content-Disposition'] = 'attachment; filename="%s"' % posixpath.basename(releasefile.name)

BadHeaderError: Header values can't contain newlines (got 'attachment; filename="vendor.js.map\r\n\n                "')
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/sentry/api/endpoints/release_file_details.py`
Content:
```
1 from __future__ import absolute_import
2 import posixpath
3 
4 from rest_framework import serializers
5 from rest_framework.response import Response
6 
7 from sentry.api.base import DocSection
8 from sentry.api.bases.project import ProjectEndpoint, ProjectReleasePermission
9 from sentry.api.exceptions import ResourceDoesNotExist
10 from sentry.api.serializers import serialize
11 from sentry.models import Release, ReleaseFile
12 from sentry.utils.apidocs import scenario, attach_scenarios
13 from django.http import CompatibleStreamingHttpResponse
14 
15 
16 @scenario('RetrieveReleaseFile')
17 def retrieve_file_scenario(runner):
18     rf = runner.utils.create_release_file(
19         project=runner.default_project,
20         release=runner.default_release,
21         path='/demo/readme.txt',
22         contents='Hello World!'
23     )
24     runner.request(
25         method='GET',
26         path='/projects/%s/%s/releases/%s/files/%s/' % (
27             runner.org.slug, runner.default_project.slug,
28             runner.default_release.version, rf.id)
29     )
30 
31 
32 @scenario('UpdateReleaseFile')
33 def update_file_scenario(runner):
34     rf = runner.utils.create_release_file(
35         project=runner.default_project,
36         release=runner.default_release,
37         path='/demo/hello.txt',
38         contents='Good bye World!'
39     )
40     runner.request(
41         method='PUT',
42         path='/projects/%s/%s/releases/%s/files/%s/' % (
43             runner.org.slug, runner.default_project.slug,
44             runner.default_release.version, rf.id),
45         data={
46             'name': '/demo/goodbye.txt'
47         }
48     )
49 
50 
51 @scenario('DeleteReleaseFile')
52 def delete_file_scenario(runner):
53     rf = runner.utils.create_release_file(
54         project=runner.default_project,
55         release=runner.default_release,
56         path='/demo/badfile.txt',
57         contents='Whatever!'
58     )
59     runner.request(
60         method='DELETE',
61         path='/projects/%s/%s/releases/%s/files/%s/' % (
62             runner.org.slug, runner.default_project.slug,
63             runner.default_release.version, rf.id)
64     )
65 
66 
67 class ReleaseFileSerializer(serializers.Serializer):
68     name = serializers.CharField(max_length=200, required=True)
69 
70 
71 class ReleaseFileDetailsEndpoint(ProjectEndpoint):
72     doc_section = DocSection.RELEASES
73     permission_classes = (ProjectReleasePermission,)
74 
75     def download(self, releasefile):
76         file = releasefile.file
77         fp = file.getfile()
78         response = CompatibleStreamingHttpResponse(
79             iter(lambda: fp.read(4096), b''),
80             content_type=file.headers.get('content-type', 'application/octet-stream'),
81         )
82         response['Content-Length'] = file.size
83         response['Content-Disposition'] = 'attachment; filename="%s"' % posixpath.basename(releasefile.name)
84         return response
85 
86     @attach_scenarios([retrieve_file_scenario])
87     def get(self, request, project, version, file_id):
88         """
89         Retrieve a File
90         ```````````````
91 
92         Return details on an individual file within a release.  This does
93         not actually return the contents of the file, just the associated
94         metadata.
95 
96         :pparam string organization_slug: the slug of the organization the
97                                           release belongs to.
98         :pparam string project_slug: the slug of the project to retrieve the
99                                      file of.
100         :pparam string version: the version identifier of the release.
101         :pparam string file_id: the ID of the file to retrieve.
102         :auth: required
103         """
104         try:
105             release = Release.objects.get(
106                 project=project,
107                 version=version,
108             )
109         except Release.DoesNotExist:
110             raise ResourceDoesNotExist
111 
112         try:
113             releasefile = ReleaseFile.objects.get(
114                 release=release,
115                 id=file_id,
116             )
117         except ReleaseFile.DoesNotExist:
118             raise ResourceDoesNotExist
119 
120         download_requested = request.GET.get('download') is not None
121         if download_requested and (
122            request.access.has_scope('project:write')):
123             return self.download(releasefile)
124         elif download_requested:
125             return Response(status=403)
126         return Response(serialize(releasefile, request.user))
127 
128     @attach_scenarios([update_file_scenario])
129     def put(self, request, project, version, file_id):
130         """
131         Update a File
132         `````````````
133 
134         Update metadata of an existing file.  Currently only the name of
135         the file can be changed.
136 
137         :pparam string organization_slug: the slug of the organization the
138                                           release belongs to.
139         :pparam string project_slug: the slug of the project to update the
140                                      file of.
141         :pparam string version: the version identifier of the release.
142         :pparam string file_id: the ID of the file to update.
143         :param string name: the new name of the file.
144         :auth: required
145         """
146         try:
147             release = Release.objects.get(
148                 project=project,
149                 version=version,
150             )
151         except Release.DoesNotExist:
152             raise ResourceDoesNotExist
153 
154         try:
155             releasefile = ReleaseFile.objects.get(
156                 release=release,
157                 id=file_id,
158             )
159         except ReleaseFile.DoesNotExist:
160             raise ResourceDoesNotExist
161 
162         serializer = ReleaseFileSerializer(data=request.DATA)
163 
164         if not serializer.is_valid():
165             return Response(serializer.errors, status=400)
166 
167         result = serializer.object
168 
169         releasefile.update(
170             name=result['name'],
171         )
172 
173         return Response(serialize(releasefile, request.user))
174 
175     @attach_scenarios([delete_file_scenario])
176     def delete(self, request, project, version, file_id):
177         """
178         Delete a File
179         `````````````
180 
181         Permanently remove a file from a release.
182 
183         This will also remove the physical file from storage.
184 
185         :pparam string organization_slug: the slug of the organization the
186                                           release belongs to.
187         :pparam string project_slug: the slug of the project to delete the
188                                      file of.
189         :pparam string version: the version identifier of the release.
190         :pparam string file_id: the ID of the file to delete.
191         :auth: required
192         """
193         try:
194             release = Release.objects.get(
195                 project=project,
196                 version=version,
197             )
198         except Release.DoesNotExist:
199             raise ResourceDoesNotExist
200 
201         try:
202             releasefile = ReleaseFile.objects.get(
203                 release=release,
204                 id=file_id,
205             )
206         except ReleaseFile.DoesNotExist:
207             raise ResourceDoesNotExist
208 
209         file = releasefile.file
210 
211         # TODO(dcramer): this doesnt handle a failure from file.deletefile() to
212         # the actual deletion of the db row
213         releasefile.delete()
214         file.delete()
215 
216         return Response(status=204)
217
```
--- 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()

```

diff --git a/src/sentry/api/endpoints/release_file_details.py b/src/sentry/api/endpoints/release_file_details.py
--- a/src/sentry/api/endpoints/release_file_details.py
+++ b/src/sentry/api/endpoints/release_file_details.py
@@ -80,7 +80,7 @@
             content_type=file.headers.get('content-type', 'application/octet-stream'),
         )
         response['Content-Length'] = file.size
-        response['Content-Disposition'] = 'attachment; filename="%s"' % posixpath.basename(releasefile.name)
+        response['Content-Disposition'] = 'attachment; filename="%s"' % posixpath.basename(" ".join(releasefile.name.split()))
         return response
 
     @attach_scenarios([retrieve_file_scenario])

{"golden_diff": "diff --git a/src/sentry/api/endpoints/release_file_details.py b/src/sentry/api/endpoints/release_file_details.py\n--- a/src/sentry/api/endpoints/release_file_details.py\n+++ b/src/sentry/api/endpoints/release_file_details.py\n@@ -80,7 +80,7 @@\n             content_type=file.headers.get('content-type', 'application/octet-stream'),\n         )\n         response['Content-Length'] = file.size\n-        response['Content-Disposition'] = 'attachment; filename=\"%s\"' % posixpath.basename(releasefile.name)\n+        response['Content-Disposition'] = 'attachment; filename=\"%s\"' % posixpath.basename(\" \".join(releasefile.name.split()))\n         return response\n \n     @attach_scenarios([retrieve_file_scenario])\n", "issue": "BadHeaderError: Header values can't contain newlines (got 'attachment; filename=\"vendor.js.map\\r\\n\\n             ...\nhttps://sentry.io/sentry/sentry/issues/202980928/\n\n```\nBadHeaderError: Header values can't contain newlines (got 'attachment; filename=\"vendor.js.map\\r\\n\\n                \"')\n(1 additional frame(s) were not displayed)\n...\n  File \"sentry/api/base.py\", line 86, in handle_exception\n    return super(Endpoint, self).handle_exception(exc)\n  File \"sentry/api/base.py\", line 180, in dispatch\n    response = handler(request, *args, **kwargs)\n  File \"sentry/api/endpoints/release_file_details.py\", line 123, in get\n    return self.download(releasefile)\n  File \"sentry/api/endpoints/release_file_details.py\", line 83, in download\n    response['Content-Disposition'] = 'attachment; filename=\"%s\"' % posixpath.basename(releasefile.name)\n\nBadHeaderError: Header values can't contain newlines (got 'attachment; filename=\"vendor.js.map\\r\\n\\n                \"')\n```\n", "before_files": [{"content": "from __future__ import absolute_import\nimport posixpath\n\nfrom rest_framework import serializers\nfrom rest_framework.response import Response\n\nfrom sentry.api.base import DocSection\nfrom sentry.api.bases.project import ProjectEndpoint, ProjectReleasePermission\nfrom sentry.api.exceptions import ResourceDoesNotExist\nfrom sentry.api.serializers import serialize\nfrom sentry.models import Release, ReleaseFile\nfrom sentry.utils.apidocs import scenario, attach_scenarios\nfrom django.http import CompatibleStreamingHttpResponse\n\n\n@scenario('RetrieveReleaseFile')\ndef retrieve_file_scenario(runner):\n    rf = runner.utils.create_release_file(\n        project=runner.default_project,\n        release=runner.default_release,\n        path='/demo/readme.txt',\n        contents='Hello World!'\n    )\n    runner.request(\n        method='GET',\n        path='/projects/%s/%s/releases/%s/files/%s/' % (\n            runner.org.slug, runner.default_project.slug,\n            runner.default_release.version, rf.id)\n    )\n\n\n@scenario('UpdateReleaseFile')\ndef update_file_scenario(runner):\n    rf = runner.utils.create_release_file(\n        project=runner.default_project,\n        release=runner.default_release,\n        path='/demo/hello.txt',\n        contents='Good bye World!'\n    )\n    runner.request(\n        method='PUT',\n        path='/projects/%s/%s/releases/%s/files/%s/' % (\n            runner.org.slug, runner.default_project.slug,\n            runner.default_release.version, rf.id),\n        data={\n            'name': '/demo/goodbye.txt'\n        }\n    )\n\n\n@scenario('DeleteReleaseFile')\ndef delete_file_scenario(runner):\n    rf = runner.utils.create_release_file(\n        project=runner.default_project,\n        release=runner.default_release,\n        path='/demo/badfile.txt',\n        contents='Whatever!'\n    )\n    runner.request(\n        method='DELETE',\n        path='/projects/%s/%s/releases/%s/files/%s/' % (\n            runner.org.slug, runner.default_project.slug,\n            runner.default_release.version, rf.id)\n    )\n\n\nclass ReleaseFileSerializer(serializers.Serializer):\n    name = serializers.CharField(max_length=200, required=True)\n\n\nclass ReleaseFileDetailsEndpoint(ProjectEndpoint):\n    doc_section = DocSection.RELEASES\n    permission_classes = (ProjectReleasePermission,)\n\n    def download(self, releasefile):\n        file = releasefile.file\n        fp = file.getfile()\n        response = CompatibleStreamingHttpResponse(\n            iter(lambda: fp.read(4096), b''),\n            content_type=file.headers.get('content-type', 'application/octet-stream'),\n        )\n        response['Content-Length'] = file.size\n        response['Content-Disposition'] = 'attachment; filename=\"%s\"' % posixpath.basename(releasefile.name)\n        return response\n\n    @attach_scenarios([retrieve_file_scenario])\n    def get(self, request, project, version, file_id):\n        \"\"\"\n        Retrieve a File\n        ```````````````\n\n        Return details on an individual file within a release.  This does\n        not actually return the contents of the file, just the associated\n        metadata.\n\n        :pparam string organization_slug: the slug of the organization the\n                                          release belongs to.\n        :pparam string project_slug: the slug of the project to retrieve the\n                                     file of.\n        :pparam string version: the version identifier of the release.\n        :pparam string file_id: the ID of the file to retrieve.\n        :auth: required\n        \"\"\"\n        try:\n            release = Release.objects.get(\n                project=project,\n                version=version,\n            )\n        except Release.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        try:\n            releasefile = ReleaseFile.objects.get(\n                release=release,\n                id=file_id,\n            )\n        except ReleaseFile.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        download_requested = request.GET.get('download') is not None\n        if download_requested and (\n           request.access.has_scope('project:write')):\n            return self.download(releasefile)\n        elif download_requested:\n            return Response(status=403)\n        return Response(serialize(releasefile, request.user))\n\n    @attach_scenarios([update_file_scenario])\n    def put(self, request, project, version, file_id):\n        \"\"\"\n        Update a File\n        `````````````\n\n        Update metadata of an existing file.  Currently only the name of\n        the file can be changed.\n\n        :pparam string organization_slug: the slug of the organization the\n                                          release belongs to.\n        :pparam string project_slug: the slug of the project to update the\n                                     file of.\n        :pparam string version: the version identifier of the release.\n        :pparam string file_id: the ID of the file to update.\n        :param string name: the new name of the file.\n        :auth: required\n        \"\"\"\n        try:\n            release = Release.objects.get(\n                project=project,\n                version=version,\n            )\n        except Release.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        try:\n            releasefile = ReleaseFile.objects.get(\n                release=release,\n                id=file_id,\n            )\n        except ReleaseFile.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        serializer = ReleaseFileSerializer(data=request.DATA)\n\n        if not serializer.is_valid():\n            return Response(serializer.errors, status=400)\n\n        result = serializer.object\n\n        releasefile.update(\n            name=result['name'],\n        )\n\n        return Response(serialize(releasefile, request.user))\n\n    @attach_scenarios([delete_file_scenario])\n    def delete(self, request, project, version, file_id):\n        \"\"\"\n        Delete a File\n        `````````````\n\n        Permanently remove a file from a release.\n\n        This will also remove the physical file from storage.\n\n        :pparam string organization_slug: the slug of the organization the\n                                          release belongs to.\n        :pparam string project_slug: the slug of the project to delete the\n                                     file of.\n        :pparam string version: the version identifier of the release.\n        :pparam string file_id: the ID of the file to delete.\n        :auth: required\n        \"\"\"\n        try:\n            release = Release.objects.get(\n                project=project,\n                version=version,\n            )\n        except Release.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        try:\n            releasefile = ReleaseFile.objects.get(\n                release=release,\n                id=file_id,\n            )\n        except ReleaseFile.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        file = releasefile.file\n\n        # TODO(dcramer): this doesnt handle a failure from file.deletefile() to\n        # the actual deletion of the db row\n        releasefile.delete()\n        file.delete()\n\n        return Response(status=204)\n", "path": "src/sentry/api/endpoints/release_file_details.py"}], "after_files": [{"content": "from __future__ import absolute_import\nimport posixpath\n\nfrom rest_framework import serializers\nfrom rest_framework.response import Response\n\nfrom sentry.api.base import DocSection\nfrom sentry.api.bases.project import ProjectEndpoint, ProjectReleasePermission\nfrom sentry.api.exceptions import ResourceDoesNotExist\nfrom sentry.api.serializers import serialize\nfrom sentry.models import Release, ReleaseFile\nfrom sentry.utils.apidocs import scenario, attach_scenarios\nfrom django.http import CompatibleStreamingHttpResponse\n\n\n@scenario('RetrieveReleaseFile')\ndef retrieve_file_scenario(runner):\n    rf = runner.utils.create_release_file(\n        project=runner.default_project,\n        release=runner.default_release,\n        path='/demo/readme.txt',\n        contents='Hello World!'\n    )\n    runner.request(\n        method='GET',\n        path='/projects/%s/%s/releases/%s/files/%s/' % (\n            runner.org.slug, runner.default_project.slug,\n            runner.default_release.version, rf.id)\n    )\n\n\n@scenario('UpdateReleaseFile')\ndef update_file_scenario(runner):\n    rf = runner.utils.create_release_file(\n        project=runner.default_project,\n        release=runner.default_release,\n        path='/demo/hello.txt',\n        contents='Good bye World!'\n    )\n    runner.request(\n        method='PUT',\n        path='/projects/%s/%s/releases/%s/files/%s/' % (\n            runner.org.slug, runner.default_project.slug,\n            runner.default_release.version, rf.id),\n        data={\n            'name': '/demo/goodbye.txt'\n        }\n    )\n\n\n@scenario('DeleteReleaseFile')\ndef delete_file_scenario(runner):\n    rf = runner.utils.create_release_file(\n        project=runner.default_project,\n        release=runner.default_release,\n        path='/demo/badfile.txt',\n        contents='Whatever!'\n    )\n    runner.request(\n        method='DELETE',\n        path='/projects/%s/%s/releases/%s/files/%s/' % (\n            runner.org.slug, runner.default_project.slug,\n            runner.default_release.version, rf.id)\n    )\n\n\nclass ReleaseFileSerializer(serializers.Serializer):\n    name = serializers.CharField(max_length=200, required=True)\n\n\nclass ReleaseFileDetailsEndpoint(ProjectEndpoint):\n    doc_section = DocSection.RELEASES\n    permission_classes = (ProjectReleasePermission,)\n\n    def download(self, releasefile):\n        file = releasefile.file\n        fp = file.getfile()\n        response = CompatibleStreamingHttpResponse(\n            iter(lambda: fp.read(4096), b''),\n            content_type=file.headers.get('content-type', 'application/octet-stream'),\n        )\n        response['Content-Length'] = file.size\n        response['Content-Disposition'] = 'attachment; filename=\"%s\"' % posixpath.basename(\" \".join(releasefile.name.split()))\n        return response\n\n    @attach_scenarios([retrieve_file_scenario])\n    def get(self, request, project, version, file_id):\n        \"\"\"\n        Retrieve a File\n        ```````````````\n\n        Return details on an individual file within a release.  This does\n        not actually return the contents of the file, just the associated\n        metadata.\n\n        :pparam string organization_slug: the slug of the organization the\n                                          release belongs to.\n        :pparam string project_slug: the slug of the project to retrieve the\n                                     file of.\n        :pparam string version: the version identifier of the release.\n        :pparam string file_id: the ID of the file to retrieve.\n        :auth: required\n        \"\"\"\n        try:\n            release = Release.objects.get(\n                project=project,\n                version=version,\n            )\n        except Release.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        try:\n            releasefile = ReleaseFile.objects.get(\n                release=release,\n                id=file_id,\n            )\n        except ReleaseFile.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        download_requested = request.GET.get('download') is not None\n        if download_requested and (\n           request.access.has_scope('project:write')):\n            return self.download(releasefile)\n        elif download_requested:\n            return Response(status=403)\n        return Response(serialize(releasefile, request.user))\n\n    @attach_scenarios([update_file_scenario])\n    def put(self, request, project, version, file_id):\n        \"\"\"\n        Update a File\n        `````````````\n\n        Update metadata of an existing file.  Currently only the name of\n        the file can be changed.\n\n        :pparam string organization_slug: the slug of the organization the\n                                          release belongs to.\n        :pparam string project_slug: the slug of the project to update the\n                                     file of.\n        :pparam string version: the version identifier of the release.\n        :pparam string file_id: the ID of the file to update.\n        :param string name: the new name of the file.\n        :auth: required\n        \"\"\"\n        try:\n            release = Release.objects.get(\n                project=project,\n                version=version,\n            )\n        except Release.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        try:\n            releasefile = ReleaseFile.objects.get(\n                release=release,\n                id=file_id,\n            )\n        except ReleaseFile.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        serializer = ReleaseFileSerializer(data=request.DATA)\n\n        if not serializer.is_valid():\n            return Response(serializer.errors, status=400)\n\n        result = serializer.object\n\n        releasefile.update(\n            name=result['name'],\n        )\n\n        return Response(serialize(releasefile, request.user))\n\n    @attach_scenarios([delete_file_scenario])\n    def delete(self, request, project, version, file_id):\n        \"\"\"\n        Delete a File\n        `````````````\n\n        Permanently remove a file from a release.\n\n        This will also remove the physical file from storage.\n\n        :pparam string organization_slug: the slug of the organization the\n                                          release belongs to.\n        :pparam string project_slug: the slug of the project to delete the\n                                     file of.\n        :pparam string version: the version identifier of the release.\n        :pparam string file_id: the ID of the file to delete.\n        :auth: required\n        \"\"\"\n        try:\n            release = Release.objects.get(\n                project=project,\n                version=version,\n            )\n        except Release.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        try:\n            releasefile = ReleaseFile.objects.get(\n                release=release,\n                id=file_id,\n            )\n        except ReleaseFile.DoesNotExist:\n            raise ResourceDoesNotExist\n\n        file = releasefile.file\n\n        # TODO(dcramer): this doesnt handle a failure from file.deletefile() to\n        # the actual deletion of the db row\n        releasefile.delete()\n        file.delete()\n\n        return Response(status=204)\n", "path": "src/sentry/api/endpoints/release_file_details.py"}]}