def send_response(self, status_code, content=None, headers=None): """ Send a response back to the client with the HTTP `status_code` (int), `content` (str) and `headers` (dict). """ self.log_message( "Sent HTTP response: {0} with content '{1}' and headers {2}". format(status_code, content, headers)) if headers is None: headers = { 'Access-Control-Allow-Origin': "*", } BaseHTTPRequestHandler.send_response(self, status_code) for (key, value) in headers.items(): self.send_header(key, value) if len(headers) > 0: self.end_headers() if content is not None: if not six.PY2 and isinstance(content, six.text_type): content = content.encode('utf-8') self.wfile.write(content)