Skip to content

Commit 6799cf6

Browse files
dwtMartin Häckermarkstory
authored
Fix recording content_type (#771)
The intiial code skipped reorcding the content type and instead fell back to guessing. Now it only falls back to guessing if no explicit content type is provided. Closes #770 Co-authored-by: Mark Story <[email protected]> --------- Co-authored-by: Martin Häcker <[email protected]> Co-authored-by: Mark Story <[email protected]>
1 parent bb9ba99 commit 6799cf6

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.25.8
2+
------
3+
4+
* Fix bug where the content type is always recorded as either text/plain or application/json. See #770
5+
16
0.25.7
27
------
38

responses/_recorder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from responses import RequestsMock
2727
from responses import Response
2828
from responses import _real_send
29+
from responses import _UNSET
2930
from responses.registries import OrderedRegistry
3031

3132

@@ -153,6 +154,7 @@ def _on_request(
153154
status=requests_response.status_code,
154155
body=requests_response.text,
155156
headers=headers_values,
157+
content_type=requests_response.headers.get("Content-Type", _UNSET),
156158
)
157159
self._registry.add(responses_response)
158160
return requests_response

responses/tests/test_recorder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_data(host, port):
5858
"url": f"http://{host}:{port}/202",
5959
"body": "OK",
6060
"status": 202,
61-
"content_type": "text/plain",
61+
"content_type": "image/tiff",
6262
"auto_calculate_content_length": False,
6363
}
6464
},
@@ -132,7 +132,7 @@ def prepare_server(self, httpserver):
132132
httpserver.expect_request("/202").respond_with_data(
133133
"OK",
134134
status=202,
135-
content_type="text/plain",
135+
content_type="image/tiff",
136136
)
137137
httpserver.expect_request("/404").respond_with_data(
138138
"404 Not Found",

0 commit comments

Comments
 (0)