Skip to content

Commit 92b5db5

Browse files
author
glic3rinu
committed
Added break_long_headers on templatetags and base template
1 parent df30b34 commit 92b5db5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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:
272+
header = mark_safe('<br> ' + ', <br>'.join(header.split(',')))
273+
return header

0 commit comments

Comments
 (0)