Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
df0523de
Kaydet (Commit)
df0523de
authored
Kas 04, 2014
tarafından
Berker Peksag
Kaydeden (comit)
Tim Graham
Kas 04, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #23531 -- Added CommonMiddleware.response_redirect_class.
üst
83daf536
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
2 deletions
+42
-2
common.py
django/middleware/common.py
+6
-1
middleware.txt
docs/ref/middleware.txt
+8
-0
1.8.txt
docs/releases/1.8.txt
+7
-0
tests.py
tests/middleware/tests.py
+21
-1
No files found.
django/middleware/common.py
Dosyayı görüntüle @
df0523de
...
@@ -30,11 +30,16 @@ class CommonMiddleware(object):
...
@@ -30,11 +30,16 @@ class CommonMiddleware(object):
urlpatterns, then an HTTP-redirect is returned to this new URL;
urlpatterns, then an HTTP-redirect is returned to this new URL;
otherwise the initial URL is processed as usual.
otherwise the initial URL is processed as usual.
This behavior can be customized by subclassing CommonMiddleware and
overriding the response_redirect_class attribute.
- ETags: If the USE_ETAGS setting is set, ETags will be calculated from
- ETags: If the USE_ETAGS setting is set, ETags will be calculated from
the entire page content and Not Modified responses will be returned
the entire page content and Not Modified responses will be returned
appropriately.
appropriately.
"""
"""
response_redirect_class
=
http
.
HttpResponsePermanentRedirect
def
process_request
(
self
,
request
):
def
process_request
(
self
,
request
):
"""
"""
Check for denied User-Agents and rewrite the URL based on
Check for denied User-Agents and rewrite the URL based on
...
@@ -100,7 +105,7 @@ class CommonMiddleware(object):
...
@@ -100,7 +105,7 @@ class CommonMiddleware(object):
newurl
+=
'?'
+
request
.
META
[
'QUERY_STRING'
]
.
decode
()
newurl
+=
'?'
+
request
.
META
[
'QUERY_STRING'
]
.
decode
()
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
pass
pass
return
http
.
HttpResponsePermanentRedirect
(
newurl
)
return
self
.
response_redirect_class
(
newurl
)
def
process_response
(
self
,
request
,
response
):
def
process_response
(
self
,
request
,
response
):
"""
"""
...
...
docs/ref/middleware.txt
Dosyayı görüntüle @
df0523de
...
@@ -66,6 +66,14 @@ Adds a few conveniences for perfectionists:
...
@@ -66,6 +66,14 @@ Adds a few conveniences for perfectionists:
for each request by MD5-hashing the page content, and it'll take care of
for each request by MD5-hashing the page content, and it'll take care of
sending ``Not Modified`` responses, if appropriate.
sending ``Not Modified`` responses, if appropriate.
.. attribute:: CommonMiddleware.response_redirect_class
.. versionadded:: 1.8
Defaults to :class:`~django.http.HttpResponsePermanentRedirect`. Subclass
``CommonMiddleware`` and override the attribute to customize the redirects
issued by the middleware.
.. class:: BrokenLinkEmailsMiddleware
.. class:: BrokenLinkEmailsMiddleware
* Sends broken link notification emails to :setting:`MANAGERS` (see
* Sends broken link notification emails to :setting:`MANAGERS` (see
...
...
docs/releases/1.8.txt
Dosyayı görüntüle @
df0523de
...
@@ -304,6 +304,13 @@ Management Commands
...
@@ -304,6 +304,13 @@ Management Commands
:setting:`FIXTURE_DIRS` contains duplicates or a default fixture directory
:setting:`FIXTURE_DIRS` contains duplicates or a default fixture directory
path (``app_name/fixtures``), an exception is raised.
path (``app_name/fixtures``), an exception is raised.
Middleware
^^^^^^^^^^
* The :attr:`CommonMiddleware.response_redirect_class
<django.middleware.common.CommonMiddleware.response_redirect_class>`
attribute allows you to customize the redirects issued by the middleware.
Migrations
Migrations
^^^^^^^^^^
^^^^^^^^^^
...
...
tests/middleware/tests.py
Dosyayı görüntüle @
df0523de
...
@@ -9,7 +9,10 @@ from unittest import skipIf
...
@@ -9,7 +9,10 @@ from unittest import skipIf
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core
import
mail
from
django.core
import
mail
from
django.http
import
HttpRequest
,
HttpResponse
,
StreamingHttpResponse
from
django.http
import
(
HttpRequest
,
HttpResponse
,
StreamingHttpResponse
,
HttpResponsePermanentRedirect
,
HttpResponseRedirect
,
)
from
django.middleware.clickjacking
import
XFrameOptionsMiddleware
from
django.middleware.clickjacking
import
XFrameOptionsMiddleware
from
django.middleware.common
import
CommonMiddleware
,
BrokenLinkEmailsMiddleware
from
django.middleware.common
import
CommonMiddleware
,
BrokenLinkEmailsMiddleware
from
django.middleware.http
import
ConditionalGetMiddleware
from
django.middleware.http
import
ConditionalGetMiddleware
...
@@ -242,6 +245,23 @@ class CommonMiddlewareTest(TestCase):
...
@@ -242,6 +245,23 @@ class CommonMiddlewareTest(TestCase):
response
=
CommonMiddleware
()
.
process_request
(
request
)
response
=
CommonMiddleware
()
.
process_request
(
request
)
self
.
assertEqual
(
response
.
status_code
,
301
)
self
.
assertEqual
(
response
.
status_code
,
301
)
def
test_response_redirect_class
(
self
):
request
=
self
.
_get_request
(
'slash'
)
r
=
CommonMiddleware
()
.
process_request
(
request
)
self
.
assertEqual
(
r
.
status_code
,
301
)
self
.
assertEqual
(
r
.
url
,
'http://testserver/slash/'
)
self
.
assertIsInstance
(
r
,
HttpResponsePermanentRedirect
)
def
test_response_redirect_class_subclass
(
self
):
class
MyCommonMiddleware
(
CommonMiddleware
):
response_redirect_class
=
HttpResponseRedirect
request
=
self
.
_get_request
(
'slash'
)
r
=
MyCommonMiddleware
()
.
process_request
(
request
)
self
.
assertEqual
(
r
.
status_code
,
302
)
self
.
assertEqual
(
r
.
url
,
'http://testserver/slash/'
)
self
.
assertIsInstance
(
r
,
HttpResponseRedirect
)
@override_settings
(
@override_settings
(
IGNORABLE_404_URLS
=
(
re
.
compile
(
r'foo'
),),
IGNORABLE_404_URLS
=
(
re
.
compile
(
r'foo'
),),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment