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
2688644e
Kaydet (Commit)
2688644e
authored
Mar 15, 2013
tarafından
Senthil Kumaran
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#1291 http.server's send_error takes an optional explain argument
üst
12bb353d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
10 deletions
+33
-10
http.server.rst
Doc/library/http.server.rst
+8
-4
server.py
Lib/http/server.py
+12
-6
test_httpservers.py
Lib/test/test_httpservers.py
+10
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/http.server.rst
Dosyayı görüntüle @
2688644e
...
...
@@ -170,15 +170,19 @@ of which this module provides three different variants:
.. versionadded:: 3.2
.. method:: send_error(code, message=None)
.. method:: send_error(code, message=None
, explain=None
)
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.
specifies the HTTP error code, with *message* as optional, more specific
text, usually referring to short message response. The *explain*
argument can be used to send a detailed information about the error in
response content body. A complete set of headers is sent, followed by
text composed using the :attr:`error_message_format` class variable.
.. versionchanged:: 3.4
The error response includes a Content-Length header.
explain argument was added.
.. method:: send_response(code, message=None)
...
...
Lib/http/server.py
Dosyayı görüntüle @
2688644e
...
...
@@ -401,12 +401,17 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
while
not
self
.
close_connection
:
self
.
handle_one_request
()
def
send_error
(
self
,
code
,
message
=
None
):
def
send_error
(
self
,
code
,
message
=
None
,
explain
=
None
):
"""Send and log an error reply.
Arguments are the error code, and a detailed message.
The detailed message defaults to the short entry matching the
response code.
Arguments are
* code: an HTTP error code
3 digits
* message: a simple optional 1 line reason phrase.
*( HTAB / SP / VCHAR /
%
x80-FF )
defaults to short entry matching the response code
* explain: a detailed message defaults to the long entry
matching the response code.
This sends an error response (so it must be called before any
output has been generated), logs the error, and finally sends
...
...
@@ -420,11 +425,12 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
shortmsg
,
longmsg
=
'???'
,
'???'
if
message
is
None
:
message
=
shortmsg
explain
=
longmsg
if
explain
is
None
:
explain
=
longmsg
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
})
{
'code'
:
code
,
'message'
:
_quote_html
(
message
),
'explain'
:
_quote_html
(
explain
)
})
body
=
content
.
encode
(
'UTF-8'
,
'replace'
)
self
.
send_response
(
code
,
message
)
self
.
send_header
(
"Content-Type"
,
self
.
error_content_type
)
...
...
Lib/test/test_httpservers.py
Dosyayı görüntüle @
2688644e
...
...
@@ -95,6 +95,10 @@ class BaseHTTPServerTestCase(BaseTestCase):
def
do_NOTFOUND
(
self
):
self
.
send_error
(
404
)
def
do_EXPLAINERROR
(
self
):
self
.
send_error
(
999
,
"Short Message"
,
"This is a long
\n
explaination"
)
def
do_CUSTOM
(
self
):
self
.
send_response
(
999
)
self
.
send_header
(
'Content-Type'
,
'text/html'
)
...
...
@@ -206,6 +210,12 @@ class BaseHTTPServerTestCase(BaseTestCase):
res
=
self
.
con
.
getresponse
()
self
.
assertEqual
(
res
.
status
,
999
)
def
test_return_explain_error
(
self
):
self
.
con
.
request
(
'EXPLAINERROR'
,
'/'
)
res
=
self
.
con
.
getresponse
()
self
.
assertEqual
(
res
.
status
,
999
)
self
.
assertTrue
(
int
(
res
.
getheader
(
'Content-Length'
)))
def
test_latin1_header
(
self
):
self
.
con
.
request
(
'LATINONEHEADER'
,
'/'
,
headers
=
{
'X-Special-Incoming'
:
'Ärger mit Unicode'
...
...
Misc/NEWS
Dosyayı görüntüle @
2688644e
...
...
@@ -280,6 +280,9 @@ Core and Builtins
Library
-------
- Issue #12921: http.server'
s
send_error
takes
an
explain
argument
to
send
more
information
in
response
.
Patch
contributed
by
Karl
.
-
Issue
#
17414
:
Add
timeit
,
repeat
,
and
default_timer
to
timeit
.
__all__
.
-
Issue
#
1285086
:
Get
rid
of
the
refcounting
hack
and
speed
up
...
...
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