Revision 377ae13e lib/server/rapi.py
b/lib/server/rapi.py | ||
---|---|---|
64 | 64 |
self.body_data = None |
65 | 65 |
|
66 | 66 |
|
67 |
class JsonErrorRequestExecutor(http.server.HttpServerRequestExecutor): |
|
68 |
"""Custom Request Executor class that formats HTTP errors in JSON. |
|
69 |
|
|
70 |
""" |
|
71 |
error_content_type = http.HTTP_APP_JSON |
|
72 |
|
|
73 |
def _FormatErrorMessage(self, values): |
|
74 |
"""Formats the body of an error message. |
|
75 |
|
|
76 |
@type values: dict |
|
77 |
@param values: dictionary with keys code, message and explain. |
|
78 |
@rtype: string |
|
79 |
@return: the body of the message |
|
80 |
|
|
81 |
""" |
|
82 |
return serializer.DumpJson(values) |
|
83 |
|
|
84 |
|
|
85 | 67 |
class RemoteApiHandler(http.auth.HttpServerRequestAuthentication, |
86 | 68 |
http.server.HttpServerHandler): |
87 | 69 |
"""REST Request Handler Class. |
... | ... | |
127 | 109 |
|
128 | 110 |
return True |
129 | 111 |
|
112 |
@staticmethod |
|
113 |
def FormatErrorMessage(values): |
|
114 |
"""Formats the body of an error message. |
|
115 |
|
|
116 |
@type values: dict |
|
117 |
@param values: dictionary with keys C{code}, C{message} and C{explain}. |
|
118 |
@rtype: tuple; (string, string) |
|
119 |
@return: Content-type and response body |
|
120 |
|
|
121 |
""" |
|
122 |
return (http.HTTP_APP_JSON, serializer.DumpJson(values)) |
|
123 |
|
|
130 | 124 |
def _GetRequestContext(self, req): |
131 | 125 |
"""Returns the context for a request. |
132 | 126 |
|
... | ... | |
319 | 313 |
|
320 | 314 |
server = \ |
321 | 315 |
http.server.HttpServer(mainloop, options.bind_address, options.port, |
322 |
handler, ssl_params=options.ssl_params, ssl_verify_peer=False, |
|
323 |
request_executor_class=JsonErrorRequestExecutor) |
|
316 |
handler, ssl_params=options.ssl_params, ssl_verify_peer=False) |
|
324 | 317 |
server.Start() |
325 | 318 |
|
326 | 319 |
return (mainloop, server) |
Also available in: Unified diff