Revision 377ae13e lib/http/server.py

b/lib/http/server.py
265 265
  # Most web servers default to HTTP 0.9, i.e. don't send a status line.
266 266
  default_request_version = http.HTTP_0_9
267 267

  
268
  # Error message settings
269
  error_message_format = DEFAULT_ERROR_MESSAGE
270
  error_content_type = DEFAULT_ERROR_CONTENT_TYPE
271

  
272 268
  responses = BaseHTTPServer.BaseHTTPRequestHandler.responses
273 269

  
274 270
  # Timeouts in seconds for socket layer
......
420 416
      "explain": longmsg,
421 417
      }
422 418

  
423
    self.response_msg.start_line.code = err.code
419
    (content_type, body) = self.handler.FormatErrorMessage(values)
420

  
421
    headers = {
422
      http.HTTP_CONTENT_TYPE: content_type,
423
      }
424 424

  
425
    headers = {}
426 425
    if err.headers:
427 426
      headers.update(err.headers)
428
    headers[http.HTTP_CONTENT_TYPE] = self.error_content_type
429
    self.response_msg.headers = headers
430

  
431
    self.response_msg.body = self._FormatErrorMessage(values)
432

  
433
  def _FormatErrorMessage(self, values):
434
    """Formats the body of an error message.
435

  
436
    @type values: dict
437
    @param values: dictionary with keys code, message and explain.
438
    @rtype: string
439
    @return: the body of the message
440 427

  
441
    """
442
    return self.error_message_format % values
428
    self.response_msg.start_line.code = err.code
429
    self.response_msg.headers = headers
430
    self.response_msg.body = body
443 431

  
444 432

  
445 433
class HttpServer(http.HttpBase, asyncore.dispatcher):
......
592 580

  
593 581
    """
594 582
    raise NotImplementedError()
583

  
584
  @staticmethod
585
  def FormatErrorMessage(values):
586
    """Formats the body of an error message.
587

  
588
    @type values: dict
589
    @param values: dictionary with keys C{code}, C{message} and C{explain}.
590
    @rtype: tuple; (string, string)
591
    @return: Content-type and response body
592

  
593
    """
594
    return (DEFAULT_ERROR_CONTENT_TYPE, DEFAULT_ERROR_MESSAGE % values)

Also available in: Unified diff