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
6af1c49b
Kaydet (Commit)
6af1c49b
authored
Haz 08, 2016
tarafından
Martin Panter
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #25738: Don’t send message body for 205 Reset Content
Patch by Susumu Koshiba.
üst
c3636449
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
6 deletions
+64
-6
basehttpserver.rst
Doc/library/basehttpserver.rst
+4
-1
BaseHTTPServer.py
Lib/BaseHTTPServer.py
+16
-5
test_httpservers.py
Lib/test/test_httpservers.py
+38
-0
ACKS
Misc/ACKS
+1
-0
NEWS
Misc/NEWS
+5
-0
No files found.
Doc/library/basehttpserver.rst
Dosyayı görüntüle @
6af1c49b
...
...
@@ -197,7 +197,10 @@ to a handler. Code to create and run the server looks like this::
Sends and logs a complete error reply to the client. The numeric *code*
specifies the HTTP error code, with *message* as optional, more specific text. A
complete set of headers is sent, followed by text composed using the
:attr:`error_message_format` class variable.
:attr:`error_message_format` class variable. The body will be empty
if the method is HEAD or the response code is one of the following:
``1xx``, ``204 No Content``, ``205 Reset Content``,
``304 Not Modified``.
.. method:: send_response(code[, message])
...
...
Lib/BaseHTTPServer.py
Dosyayı görüntüle @
6af1c49b
...
...
@@ -362,14 +362,25 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
message
=
short
explain
=
long
self
.
log_error
(
"code
%
d, message
%
s"
,
code
,
message
)
# using _quote_html to prevent Cross Site Scripting attacks (see bug #1100201)
content
=
(
self
.
error_message_format
%
{
'code'
:
code
,
'message'
:
_quote_html
(
message
),
'explain'
:
explain
})
self
.
send_response
(
code
,
message
)
self
.
send_header
(
"Content-Type"
,
self
.
error_content_type
)
self
.
send_header
(
'Connection'
,
'close'
)
# Message body is omitted for cases described in:
# - RFC7230: 3.3. 1xx, 204(No Content), 304(Not Modified)
# - RFC7231: 6.3.6. 205(Reset Content)
content
=
None
if
code
>=
200
and
code
not
in
(
204
,
205
,
304
):
# HTML encode to prevent Cross Site Scripting attacks
# (see bug #1100201)
content
=
(
self
.
error_message_format
%
{
'code'
:
code
,
'message'
:
_quote_html
(
message
),
'explain'
:
explain
})
self
.
send_header
(
"Content-Type"
,
self
.
error_content_type
)
self
.
end_headers
()
if
self
.
command
!=
'HEAD'
and
code
>=
200
and
code
not
in
(
204
,
304
):
if
self
.
command
!=
'HEAD'
and
content
:
self
.
wfile
.
write
(
content
)
error_message_format
=
DEFAULT_ERROR_MESSAGE
...
...
Lib/test/test_httpservers.py
Dosyayı görüntüle @
6af1c49b
...
...
@@ -178,6 +178,12 @@ class BaseHTTPServerTestCase(BaseTestCase):
self
.
send_header
(
'Connection'
,
'close'
)
self
.
end_headers
()
def
do_SEND_ERROR
(
self
):
self
.
send_error
(
int
(
self
.
path
[
1
:]))
def
do_HEAD
(
self
):
self
.
send_error
(
int
(
self
.
path
[
1
:]))
def
setUp
(
self
):
BaseTestCase
.
setUp
(
self
)
self
.
con
=
httplib
.
HTTPConnection
(
'localhost'
,
self
.
PORT
)
...
...
@@ -276,6 +282,38 @@ class BaseHTTPServerTestCase(BaseTestCase):
res
=
self
.
con
.
getresponse
()
self
.
assertEqual
(
res
.
status
,
999
)
def
test_send_error
(
self
):
allow_transfer_encoding_codes
=
(
205
,
304
)
for
code
in
(
101
,
102
,
204
,
205
,
304
):
self
.
con
.
request
(
'SEND_ERROR'
,
'/{}'
.
format
(
code
))
res
=
self
.
con
.
getresponse
()
self
.
assertEqual
(
code
,
res
.
status
)
self
.
assertEqual
(
None
,
res
.
getheader
(
'Content-Length'
))
self
.
assertEqual
(
None
,
res
.
getheader
(
'Content-Type'
))
if
code
not
in
allow_transfer_encoding_codes
:
self
.
assertEqual
(
None
,
res
.
getheader
(
'Transfer-Encoding'
))
data
=
res
.
read
()
self
.
assertEqual
(
b
''
,
data
)
def
test_head_via_send_error
(
self
):
allow_transfer_encoding_codes
=
(
205
,
304
)
for
code
in
(
101
,
200
,
204
,
205
,
304
):
self
.
con
.
request
(
'HEAD'
,
'/{}'
.
format
(
code
))
res
=
self
.
con
.
getresponse
()
self
.
assertEqual
(
code
,
res
.
status
)
if
code
==
200
:
self
.
assertEqual
(
None
,
res
.
getheader
(
'Content-Length'
))
self
.
assertIn
(
'text/html'
,
res
.
getheader
(
'Content-Type'
))
else
:
self
.
assertEqual
(
None
,
res
.
getheader
(
'Content-Length'
))
self
.
assertEqual
(
None
,
res
.
getheader
(
'Content-Type'
))
if
code
not
in
allow_transfer_encoding_codes
:
self
.
assertEqual
(
None
,
res
.
getheader
(
'Transfer-Encoding'
))
data
=
res
.
read
()
self
.
assertEqual
(
b
''
,
data
)
class
SimpleHTTPServerTestCase
(
BaseTestCase
):
class
request_handler
(
NoLogRequestHandler
,
SimpleHTTPRequestHandler
):
...
...
Misc/ACKS
Dosyayı görüntüle @
6af1c49b
...
...
@@ -741,6 +741,7 @@ Peter A. Koren
Марк Коренберг
Vlad Korolev
Anna Koroliuk
Susumu Koshiba
Joseph Koshy
Daniel Kozan
Jerzy Kozera
...
...
Misc/NEWS
Dosyayı görüntüle @
6af1c49b
...
...
@@ -92,6 +92,11 @@ Core and Builtins
Library
-------
-
Issue
#
25738
:
Stop
BaseHTTPServer
.
BaseHTTPRequestHandler
.
send_error
()
from
sending
a
message
body
for
205
Reset
Content
.
Also
,
don
't send the
Content-Type header field in responses that don'
t
have
a
body
.
Based
on
patch
by
Susumu
Koshiba
.
-
Issue
#
21313
:
Fix
the
"platform"
module
to
tolerate
when
sys
.
version
contains
truncated
build
information
.
...
...
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