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
9390da7f
Kaydet (Commit)
9390da7f
authored
Mar 18, 2016
tarafından
ieatkittens
Kaydeden (comit)
Tim Graham
Mar 23, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26293 -- Fixed CommonMiddleware to process PREPEND_WWW and APPEND_SLASH independently.
üst
107165c4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
16 deletions
+15
-16
common.py
django/middleware/common.py
+11
-10
1.9.5.txt
docs/releases/1.9.5.txt
+3
-0
tests.py
tests/middleware/tests.py
+1
-6
No files found.
django/middleware/common.py
Dosyayı görüntüle @
9390da7f
...
@@ -54,18 +54,19 @@ class CommonMiddleware(object):
...
@@ -54,18 +54,19 @@ class CommonMiddleware(object):
# Check for a redirect based on settings.PREPEND_WWW
# Check for a redirect based on settings.PREPEND_WWW
host
=
request
.
get_host
()
host
=
request
.
get_host
()
must_prepend
=
settings
.
PREPEND_WWW
and
host
and
not
host
.
startswith
(
'www.'
)
redirect_url
=
(
'
%
s://www.
%
s'
%
(
request
.
scheme
,
host
))
if
must_prepend
else
''
if
settings
.
PREPEND_WWW
and
host
and
not
host
.
startswith
(
'www.'
):
# Check if a slash should be appended
host
=
'www.'
+
host
if
self
.
should_redirect_with_slash
(
request
):
path
=
self
.
get_full_path_with_slash
(
request
)
# Check if we also need to append a slash so we can do it all
else
:
# with a single redirect.
path
=
request
.
get_full_path
()
if
self
.
should_redirect_with_slash
(
request
):
path
=
self
.
get_full_path_with_slash
(
request
)
else
:
path
=
request
.
get_full_path
()
return
self
.
response_redirect_class
(
'
%
s://
%
s
%
s'
%
(
request
.
scheme
,
host
,
path
))
# Return a redirect if necessary
if
redirect_url
or
path
!=
request
.
get_full_path
():
redirect_url
+=
path
return
self
.
response_redirect_class
(
redirect_url
)
def
should_redirect_with_slash
(
self
,
request
):
def
should_redirect_with_slash
(
self
,
request
):
"""
"""
...
...
docs/releases/1.9.5.txt
Dosyayı görüntüle @
9390da7f
...
@@ -34,3 +34,6 @@ Bugfixes
...
@@ -34,3 +34,6 @@ Bugfixes
* Fixed a crash when using a reverse lookup with a subquery when a
* Fixed a crash when using a reverse lookup with a subquery when a
``ForeignKey`` has a ``to_field`` set to something other than the primary key
``ForeignKey`` has a ``to_field`` set to something other than the primary key
(:ticket:`26373`).
(:ticket:`26373`).
* Fixed a regression in ``CommonMiddleware`` that caused spurious warnings in
logs on requests missing a trailing slash (:ticket:`26293`).
tests/middleware/tests.py
Dosyayı görüntüle @
9390da7f
...
@@ -67,10 +67,8 @@ class CommonMiddlewareTest(SimpleTestCase):
...
@@ -67,10 +67,8 @@ class CommonMiddlewareTest(SimpleTestCase):
APPEND_SLASH should redirect slashless URLs to a valid pattern.
APPEND_SLASH should redirect slashless URLs to a valid pattern.
"""
"""
request
=
self
.
rf
.
get
(
'/slash'
)
request
=
self
.
rf
.
get
(
'/slash'
)
response
=
HttpResponseNotFound
()
r
=
CommonMiddleware
()
.
process_request
(
request
)
r
=
CommonMiddleware
()
.
process_response
(
request
,
response
)
self
.
assertEqual
(
r
.
status_code
,
301
)
self
.
assertEqual
(
r
.
status_code
,
301
)
self
.
assertEqual
(
r
.
url
,
'/slash/'
)
@override_settings
(
APPEND_SLASH
=
True
)
@override_settings
(
APPEND_SLASH
=
True
)
def
test_append_slash_redirect_querystring
(
self
):
def
test_append_slash_redirect_querystring
(
self
):
...
@@ -301,9 +299,6 @@ class CommonMiddlewareTest(SimpleTestCase):
...
@@ -301,9 +299,6 @@ class CommonMiddlewareTest(SimpleTestCase):
request
=
self
.
rf
.
get
(
'/slash'
)
request
=
self
.
rf
.
get
(
'/slash'
)
request
.
META
[
'QUERY_STRING'
]
=
force_str
(
'drink=café'
)
request
.
META
[
'QUERY_STRING'
]
=
force_str
(
'drink=café'
)
r
=
CommonMiddleware
()
.
process_request
(
request
)
r
=
CommonMiddleware
()
.
process_request
(
request
)
self
.
assertIsNone
(
r
)
response
=
HttpResponseNotFound
()
r
=
CommonMiddleware
()
.
process_response
(
request
,
response
)
self
.
assertEqual
(
r
.
status_code
,
301
)
self
.
assertEqual
(
r
.
status_code
,
301
)
def
test_response_redirect_class
(
self
):
def
test_response_redirect_class
(
self
):
...
...
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