Revision e0003509 lib/http/server.py
b/lib/http/server.py | ||
---|---|---|
276 | 276 |
READ_TIMEOUT = 10 |
277 | 277 |
CLOSE_TIMEOUT = 1 |
278 | 278 |
|
279 |
def __init__(self, server, sock, client_addr): |
|
279 |
def __init__(self, server, handler, sock, client_addr):
|
|
280 | 280 |
"""Initializes this class. |
281 | 281 |
|
282 | 282 |
""" |
283 | 283 |
self.server = server |
284 |
self.handler = handler |
|
284 | 285 |
self.sock = sock |
285 | 286 |
self.client_addr = client_addr |
286 | 287 |
|
... | ... | |
324 | 325 |
|
325 | 326 |
(self.response_msg.start_line.code, self.response_msg.headers, |
326 | 327 |
self.response_msg.body) = \ |
327 |
HandleServerRequest(self.server, self.request_msg)
|
|
328 |
HandleServerRequest(self.handler, self.request_msg)
|
|
328 | 329 |
|
329 | 330 |
# Only wait for client to close if we didn't have any exception. |
330 | 331 |
force_close = False |
... | ... | |
363 | 364 |
"""Sends the response to the client. |
364 | 365 |
|
365 | 366 |
""" |
367 |
# HttpMessage.start_line can be of different types, pylint: disable=E1103 |
|
366 | 368 |
if self.response_msg.start_line.code is None: |
367 | 369 |
return |
368 | 370 |
|
... | ... | |
443 | 445 |
class HttpServer(http.HttpBase, asyncore.dispatcher): |
444 | 446 |
"""Generic HTTP server class |
445 | 447 |
|
446 |
Users of this class must subclass it and override the HandleRequest function. |
|
447 |
|
|
448 | 448 |
""" |
449 | 449 |
MAX_CHILDREN = 20 |
450 | 450 |
|
451 |
def __init__(self, mainloop, local_address, port, |
|
451 |
def __init__(self, mainloop, local_address, port, handler,
|
|
452 | 452 |
ssl_params=None, ssl_verify_peer=False, |
453 | 453 |
request_executor_class=None): |
454 | 454 |
"""Initializes the HTTP server |
... | ... | |
480 | 480 |
self.mainloop = mainloop |
481 | 481 |
self.local_address = local_address |
482 | 482 |
self.port = port |
483 |
self.handler = handler |
|
483 | 484 |
family = netutils.IPAddress.GetAddressFamily(local_address) |
484 | 485 |
self.socket = self._CreateSocket(ssl_params, ssl_verify_peer, family) |
485 | 486 |
|
... | ... | |
560 | 561 |
# In case the handler code uses temporary files |
561 | 562 |
utils.ResetTempfileModule() |
562 | 563 |
|
563 |
self.request_executor(self, connection, client_addr) |
|
564 |
self.request_executor(self, self.handler, connection, client_addr)
|
|
564 | 565 |
except Exception: # pylint: disable=W0703 |
565 | 566 |
logging.exception("Error while handling request from %s:%s", |
566 | 567 |
client_addr[0], client_addr[1]) |
... | ... | |
569 | 570 |
else: |
570 | 571 |
self._children.append(pid) |
571 | 572 |
|
573 |
|
|
574 |
class HttpServerHandler(object): |
|
575 |
"""Base class for handling HTTP server requests. |
|
576 |
|
|
577 |
Users of this class must subclass it and override the L{HandleRequest} |
|
578 |
function. |
|
579 |
|
|
580 |
""" |
|
572 | 581 |
def PreHandleRequest(self, req): |
573 | 582 |
"""Called before handling a request. |
574 | 583 |
|
Also available in: Unified diff