From 92b5db593953f03a17ca0fcee2b9ea91a29cb143 Mon Sep 17 00:00:00 2001
From: glic3rinu
Date: Thu, 4 Apr 2013 12:11:04 +0200
Subject: Added break_long_headers on templatetags and base template
---
rest_framework/templates/rest_framework/base.html | 2 +-
rest_framework/templatetags/rest_framework.py | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/rest_framework/templates/rest_framework/base.html b/rest_framework/templates/rest_framework/base.html
index 44633f5a..4410f285 100644
--- a/rest_framework/templates/rest_framework/base.html
+++ b/rest_framework/templates/rest_framework/base.html
@@ -115,7 +115,7 @@
HTTP {{ response.status_code }} {{ response.status_text }}{% autoescape off %}
-{% for key, val in response.items %}{{ key }}: {{ val|urlize_quoted_links }}
+{% for key, val in response.items %}{{ key }}: {{ val|break_long_headers|urlize_quoted_links }}
{% endfor %}
{{ content|urlize_quoted_links }}
{% endautoescape %}
diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py
index 1d7a499f..189e82f6 100644
--- a/rest_framework/templatetags/rest_framework.py
+++ b/rest_framework/templatetags/rest_framework.py
@@ -260,3 +260,14 @@ def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=Tru
elif autoescape:
words[i] = escape(word)
return ''.join(words)
+
+
+@register.filter
+def break_long_headers(header):
+ """
+ Breaks headers longer than 160 characters (~page length)
+ when possible (are comma separated)
+ """
+ if len(header) > 160:
+ header = mark_safe('
' + ',
'.join(header.split(',')))
+ return header
--
cgit v1.2.3
From b6c7730d7f31e84b5f120071ddf9c7ab08e4e7da Mon Sep 17 00:00:00 2001
From: glic3rinu
Date: Thu, 4 Apr 2013 14:01:47 +0200
Subject: Fixed comma detection in break_long_headers templatetag
---
rest_framework/templatetags/rest_framework.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py
index 189e82f6..c86b6456 100644
--- a/rest_framework/templatetags/rest_framework.py
+++ b/rest_framework/templatetags/rest_framework.py
@@ -268,6 +268,6 @@ def break_long_headers(header):
Breaks headers longer than 160 characters (~page length)
when possible (are comma separated)
"""
- if len(header) > 160:
+ if len(header) > 160 and ',' in header:
header = mark_safe('
' + ',
'.join(header.split(',')))
return header
--
cgit v1.2.3
From e8978eaf6873ac4c651322fd386d8103a9d02c1f Mon Sep 17 00:00:00 2001
From: glic3rinu
Date: Thu, 4 Apr 2013 14:02:20 +0200
Subject: Added break_long_headers on the release notes
---
docs/topics/release-notes.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md
index 7242dcce..2a181cc5 100644
--- a/docs/topics/release-notes.md
+++ b/docs/topics/release-notes.md
@@ -44,6 +44,7 @@ You can determine your currently installed version using `pip freeze`:
* OAuth2 authentication no longer requires unneccessary URL parameters in addition to the token.
* URL hyperlinking in browseable API now handles more cases correctly.
+* Long HTTP headers are broken in multiple lines when possible in browsable API.
* Bugfix: Fix regression with DjangoFilterBackend not worthing correctly with single object views.
* Bugfix: OAuth should fail hard when invalid token used.
* Bugfix: Fix serializer potentially returning `None` object for models that define `__bool__` or `__len__`.
--
cgit v1.2.3
From 77ac2044294cb1dc40d715abd1bb63543beac95b Mon Sep 17 00:00:00 2001
From: glic3rinu
Date: Thu, 4 Apr 2013 14:07:56 +0200
Subject: Rephrased break_long_headers release notes line
---
docs/topics/release-notes.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md
index 2a181cc5..609b4504 100644
--- a/docs/topics/release-notes.md
+++ b/docs/topics/release-notes.md
@@ -44,7 +44,7 @@ You can determine your currently installed version using `pip freeze`:
* OAuth2 authentication no longer requires unneccessary URL parameters in addition to the token.
* URL hyperlinking in browseable API now handles more cases correctly.
-* Long HTTP headers are broken in multiple lines when possible in browsable API.
+* Long HTTP headers in browsable API are broken in multiple lines when possible.
* Bugfix: Fix regression with DjangoFilterBackend not worthing correctly with single object views.
* Bugfix: OAuth should fail hard when invalid token used.
* Bugfix: Fix serializer potentially returning `None` object for models that define `__bool__` or `__len__`.
--
cgit v1.2.3