Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
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
cpython
Commits
52d27204
Kaydet (Commit)
52d27204
authored
Eki 11, 2012
tarafından
Senthil Kumaran
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #16088: BaseHTTPRequestHandler's send_error method includes a
Content-Length header. Patch by Antoine Pitrou.
üst
ec7c16d2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
1 deletion
+21
-1
http.server.rst
Doc/library/http.server.rst
+3
-0
server.py
Lib/http/server.py
+3
-1
test_httpservers.py
Lib/test/test_httpservers.py
+12
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/http.server.rst
Dosyayı görüntüle @
52d27204
...
@@ -177,6 +177,9 @@ of which this module provides three different variants:
...
@@ -177,6 +177,9 @@ of which this module provides three different variants:
complete set of headers is sent, followed by text composed using the
complete set of headers is sent, followed by text composed using the
:attr:`error_message_format` class variable.
:attr:`error_message_format` class variable.
.. versionchanged:: 3.4
The error response includes a Content-Length header.
.. method:: send_response(code, message=None)
.. method:: send_response(code, message=None)
Adds a response header to the headers buffer and logs the accepted
Adds a response header to the headers buffer and logs the accepted
...
...
Lib/http/server.py
Dosyayı görüntüle @
52d27204
...
@@ -425,12 +425,14 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
...
@@ -425,12 +425,14 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
# using _quote_html to prevent Cross Site Scripting attacks (see bug #1100201)
# using _quote_html to prevent Cross Site Scripting attacks (see bug #1100201)
content
=
(
self
.
error_message_format
%
content
=
(
self
.
error_message_format
%
{
'code'
:
code
,
'message'
:
_quote_html
(
message
),
'explain'
:
explain
})
{
'code'
:
code
,
'message'
:
_quote_html
(
message
),
'explain'
:
explain
})
body
=
content
.
encode
(
'UTF-8'
,
'replace'
)
self
.
send_response
(
code
,
message
)
self
.
send_response
(
code
,
message
)
self
.
send_header
(
"Content-Type"
,
self
.
error_content_type
)
self
.
send_header
(
"Content-Type"
,
self
.
error_content_type
)
self
.
send_header
(
'Connection'
,
'close'
)
self
.
send_header
(
'Connection'
,
'close'
)
self
.
send_header
(
'Content-Length'
,
int
(
len
(
body
)))
self
.
end_headers
()
self
.
end_headers
()
if
self
.
command
!=
'HEAD'
and
code
>=
200
and
code
not
in
(
204
,
304
):
if
self
.
command
!=
'HEAD'
and
code
>=
200
and
code
not
in
(
204
,
304
):
self
.
wfile
.
write
(
content
.
encode
(
'UTF-8'
,
'replace'
)
)
self
.
wfile
.
write
(
body
)
def
send_response
(
self
,
code
,
message
=
None
):
def
send_response
(
self
,
code
,
message
=
None
):
"""Add the response header to the headers buffer and log the
"""Add the response header to the headers buffer and log the
...
...
Lib/test/test_httpservers.py
Dosyayı görüntüle @
52d27204
...
@@ -92,6 +92,9 @@ class BaseHTTPServerTestCase(BaseTestCase):
...
@@ -92,6 +92,9 @@ class BaseHTTPServerTestCase(BaseTestCase):
def
do_KEYERROR
(
self
):
def
do_KEYERROR
(
self
):
self
.
send_error
(
999
)
self
.
send_error
(
999
)
def
do_NOTFOUND
(
self
):
self
.
send_error
(
404
)
def
do_CUSTOM
(
self
):
def
do_CUSTOM
(
self
):
self
.
send_response
(
999
)
self
.
send_response
(
999
)
self
.
send_header
(
'Content-Type'
,
'text/html'
)
self
.
send_header
(
'Content-Type'
,
'text/html'
)
...
@@ -211,6 +214,15 @@ class BaseHTTPServerTestCase(BaseTestCase):
...
@@ -211,6 +214,15 @@ class BaseHTTPServerTestCase(BaseTestCase):
self
.
assertEqual
(
res
.
getheader
(
'X-Special'
),
'Dängerous Mind'
)
self
.
assertEqual
(
res
.
getheader
(
'X-Special'
),
'Dängerous Mind'
)
self
.
assertEqual
(
res
.
read
(),
'Ärger mit Unicode'
.
encode
(
'utf-8'
))
self
.
assertEqual
(
res
.
read
(),
'Ärger mit Unicode'
.
encode
(
'utf-8'
))
def
test_error_content_length
(
self
):
# Issue #16088: standard error responses should have a content-length
self
.
con
.
request
(
'NOTFOUND'
,
'/'
)
res
=
self
.
con
.
getresponse
()
self
.
assertEqual
(
res
.
status
,
404
)
data
=
res
.
read
()
import
pdb
;
pdb
.
set_trace
()
self
.
assertEqual
(
int
(
res
.
getheader
(
'Content-Length'
)),
len
(
data
))
class
SimpleHTTPServerTestCase
(
BaseTestCase
):
class
SimpleHTTPServerTestCase
(
BaseTestCase
):
class
request_handler
(
NoLogRequestHandler
,
SimpleHTTPRequestHandler
):
class
request_handler
(
NoLogRequestHandler
,
SimpleHTTPRequestHandler
):
...
...
Misc/NEWS
Dosyayı görüntüle @
52d27204
...
@@ -45,6 +45,9 @@ Core and Builtins
...
@@ -45,6 +45,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #16088: BaseHTTPRequestHandler's send_error method includes a
Content-Length header in it's response now. Patch by Antoine Pitrou.
- Issue #16114: The subprocess module no longer provides a misleading error
- Issue #16114: The subprocess module no longer provides a misleading error
message stating that args[0] did not exist when either the cwd or executable
message stating that args[0] did not exist when either the cwd or executable
keyword arguments specified a path that did not exist.
keyword arguments specified a path that did not exist.
...
...
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