Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
snf-ganeti
Commits
b1d979cf
Commit
b1d979cf
authored
Dec 03, 2008
by
Michael Hanselmann
Browse files
ganeti.http: Move request handling logic from server to handler class
Reviewed-by: ultrotter
parent
73a59d9e
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/http.py
View file @
b1d979cf
...
...
@@ -412,7 +412,7 @@ class _HttpSocketBase(object):
self
.
_ssl_cert
.
digest
(
"md5"
)
==
cert
.
digest
(
"md5"
))
class
_
Http
ConnectionHandle
r
(
object
):
class
Http
ServerRequestExecuto
r
(
object
):
"""Implements server side of HTTP
This class implements the server side of HTTP. It's based on code of Python's
...
...
@@ -465,13 +465,27 @@ class _HttpConnectionHandler(object):
self
.
should_fork
=
False
logging
.
info
(
"Connection from %s:%s"
,
client_addr
[
0
],
client_addr
[
1
])
try
:
self
.
_ReadRequest
()
self
.
_ReadPostData
()
except
HTTPException
,
err
:
self
.
_SetErrorStatus
(
err
)
try
:
try
:
try
:
# Read, parse and handle request
self
.
_ReadRequest
()
self
.
_ReadPostData
()
self
.
_HandleRequest
()
except
HTTPException
,
err
:
self
.
_SetErrorStatus
(
err
)
finally
:
# Try to send a response
self
.
_SendResponse
()
self
.
_Close
()
except
SocketClosed
:
pass
finally
:
logging
.
info
(
"Disconnected %s:%s"
,
client_addr
[
0
],
client_addr
[
1
])
def
Close
(
self
):
def
_
Close
(
self
):
if
not
self
.
wfile
.
closed
:
self
.
wfile
.
flush
()
self
.
wfile
.
close
()
...
...
@@ -512,7 +526,7 @@ class _HttpConnectionHandler(object):
self
.
response_content_type
=
self
.
error_content_type
self
.
response_body
=
self
.
error_message_format
%
values
def
HandleRequest
(
self
):
def
_
HandleRequest
(
self
):
"""Handle the actual request.
Calls the actual handler function and converts exceptions into HTTP errors.
...
...
@@ -549,7 +563,7 @@ class _HttpConnectionHandler(object):
except
HTTPException
,
err
:
self
.
_SetErrorStatus
(
err
)
def
SendResponse
(
self
):
def
_
SendResponse
(
self
):
"""Sends response to the client.
"""
...
...
@@ -794,26 +808,9 @@ class HttpServer(_HttpSocketBase):
pid
=
os
.
fork
()
if
pid
==
0
:
# Child process
logging
.
info
(
"Connection from %s:%s"
,
client_addr
[
0
],
client_addr
[
1
])
try
:
try
:
try
:
handler
=
None
try
:
# Read, parse and handle request
handler
=
_HttpConnectionHandler
(
self
,
connection
,
client_addr
,
self
.
_fileio_class
)
handler
.
HandleRequest
()
finally
:
# Try to send a response
if
handler
:
handler
.
SendResponse
()
handler
.
Close
()
except
SocketClosed
:
pass
finally
:
logging
.
info
(
"Disconnected %s:%s"
,
client_addr
[
0
],
client_addr
[
1
])
HttpServerRequestExecutor
(
self
,
connection
,
client_addr
,
self
.
_fileio_class
)
except
:
logging
.
exception
(
"Error while handling request from %s:%s"
,
client_addr
[
0
],
client_addr
[
1
])
...
...
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