Skip to content

Commit 5b56639

Browse files
committed
Merge pull request #777 from glic3rinu/master
Break long headers on the browsable API
2 parents df30b34 + 77ac204 commit 5b56639

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

docs/topics/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ You can determine your currently installed version using `pip freeze`:
4444

4545
* OAuth2 authentication no longer requires unneccessary URL parameters in addition to the token.
4646
* URL hyperlinking in browseable API now handles more cases correctly.
47+
* Long HTTP headers in browsable API are broken in multiple lines when possible.
4748
* Bugfix: Fix regression with DjangoFilterBackend not worthing correctly with single object views.
4849
* Bugfix: OAuth should fail hard when invalid token used.
4950
* Bugfix: Fix serializer potentially returning `None` object for models that define `__bool__` or `__len__`.

rest_framework/templates/rest_framework/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
</div>
116116
<div class="response-info">
117117
<pre class="prettyprint"><div class="meta nocode"><b>HTTP {{ response.status_code }} {{ response.status_text }}</b>{% autoescape off %}
118-
{% for key, val in response.items %}<b>{{ key }}:</b> <span class="lit">{{ val|urlize_quoted_links }}</span>
118+
{% for key, val in response.items %}<b>{{ key }}:</b> <span class="lit">{{ val|break_long_headers|urlize_quoted_links }}</span>
119119
{% endfor %}
120120
</div>{{ content|urlize_quoted_links }}</pre>{% endautoescape %}
121121
</div>

rest_framework/templatetags/rest_framework.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,14 @@ def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=Tru
260260
elif autoescape:
261261
words[i] = escape(word)
262262
return ''.join(words)
263+
264+
265+
@register.filter
266+
def break_long_headers(header):
267+
"""
268+
Breaks headers longer than 160 characters (~page length)
269+
when possible (are comma separated)
270+
"""
271+
if len(header) > 160 and ',' in header:
272+
header = mark_safe('<br> ' + ', <br>'.join(header.split(',')))
273+
return header

0 commit comments

Comments
 (0)