Revision 1f8588f6 lib/http/server.py

b/lib/http/server.py
207 207
    return http.HttpClientToServerStartLine(method, path, version)
208 208

  
209 209

  
210
class _HttpServerRequestExecutor(object):
210
class HttpServerRequestExecutor(object):
211 211
  """Implements server side of HTTP.
212 212

  
213 213
  This class implements the server side of HTTP. It's based on code of
......
405 405
    headers[http.HTTP_CONTENT_TYPE] = self.error_content_type
406 406
    self.response_msg.headers = headers
407 407

  
408
    self.response_msg.body = self.error_message_format % values
408
    self.response_msg.body = self._FormatErrorMessage(values)
409 409

  
410
  def _FormatErrorMessage(self, values):
411
    """Formats the body of an error message.
412

  
413
    @type values: dict
414
    @param values: dictionary with keys code, message and explain.
415
    @rtype: string
416
    @return: the body of the message
417

  
418
    """
419
    return self.error_message_format % values
410 420

  
411 421
class HttpServer(http.HttpBase):
412 422
  """Generic HTTP server class
......
417 427
  MAX_CHILDREN = 20
418 428

  
419 429
  def __init__(self, mainloop, local_address, port,
420
               ssl_params=None, ssl_verify_peer=False):
430
               ssl_params=None, ssl_verify_peer=False,
431
               request_executor_class=None):
421 432
    """Initializes the HTTP server
422 433

  
423 434
    @type mainloop: ganeti.daemon.Mainloop
......
431 442
    @type ssl_verify_peer: bool
432 443
    @param ssl_verify_peer: Whether to require client certificate
433 444
        and compare it with our certificate
445
    @type request_executor_class: class
446
    @param request_executor_class: an class derived from the
447
        HttpServerRequestExecutor class
434 448

  
435 449
    """
436 450
    http.HttpBase.__init__(self)
437 451

  
452
    if request_executor_class is None:
453
      self.request_executor = HttpServerRequestExecutor
454
    else:
455
      self.request_executor = request_executor_class
456

  
438 457
    self.mainloop = mainloop
439 458
    self.local_address = local_address
440 459
    self.port = port
......
505 524
    if pid == 0:
506 525
      # Child process
507 526
      try:
508
        _HttpServerRequestExecutor(self, connection, client_addr)
527
        self.request_executor(self, connection, client_addr)
509 528
      except Exception:
510 529
        logging.exception("Error while handling request from %s:%s",
511 530
                          client_addr[0], client_addr[1])

Also available in: Unified diff