Revision 16b037a9

b/daemons/ganeti-rapi
59 59
  """Custom Request Executor class that formats HTTP errors in JSON.
60 60

  
61 61
  """
62
  error_content_type = http.HttpJsonConverter.CONTENT_TYPE
62
  error_content_type = http.HTTP_APP_JSON
63 63

  
64 64
  def _FormatErrorMessage(self, values):
65 65
    """Formats the body of an error message.
......
174 174
      # treat it as type "application/octet-stream".
175 175
      req_content_type = req.request_headers.get(http.HTTP_CONTENT_TYPE,
176 176
                                                 http.HTTP_APP_OCTET_STREAM)
177
      if (req_content_type.lower() !=
178
          http.HttpJsonConverter.CONTENT_TYPE.lower()):
177
      if req_content_type.lower() != http.HTTP_APP_JSON.lower():
179 178
        raise http.HttpUnsupportedMediaType()
180 179

  
181 180
      try:
......
196 195
      logging.exception("Error while handling the %s request", method)
197 196
      raise
198 197

  
199
    req.resp_headers[http.HTTP_CONTENT_TYPE] = \
200
      http.HttpJsonConverter.CONTENT_TYPE
198
    req.resp_headers[http.HTTP_CONTENT_TYPE] = http.HTTP_APP_JSON
201 199

  
202 200
    return serializer.DumpJson(result)
203 201

  
b/lib/http/__init__.py
32 32
from cStringIO import StringIO
33 33

  
34 34
from ganeti import constants
35
from ganeti import serializer
36 35
from ganeti import utils
37 36

  
38 37

  
......
67 66
HTTP_ALLOW = "Allow"
68 67

  
69 68
HTTP_APP_OCTET_STREAM = "application/octet-stream"
69
HTTP_APP_JSON = "application/json"
70 70

  
71 71
_SSL_UNEXPECTED_EOF = "Unexpected EOF"
72 72

  
......
323 323
  code = 505
324 324

  
325 325

  
326
class HttpJsonConverter: # pylint: disable-msg=W0232
327
  CONTENT_TYPE = "application/json"
328

  
329
  @staticmethod
330
  def Encode(data):
331
    return serializer.DumpJson(data)
332

  
333
  @staticmethod
334
  def Decode(data):
335
    return serializer.LoadJson(data)
336

  
337

  
338 326
def WaitForSocketCondition(sock, event, timeout):
339 327
  """Waits for a condition to occur on the socket.
340 328

  

Also available in: Unified diff