MCPcopy
hub / github.com/PromtEngineer/localGPT / send_json_response

Method send_json_response

backend/server.py:1059–1076  ·  view source on GitHub ↗

Send a JSON (UTF-8) response with CORS headers. Safe against client disconnects.

(self, data, status_code: int = 200)

Source from the content-addressed store, hash-verified

1057 self.send_json_response({"error": f"Failed to rename session: {str(e)}"}, status_code=500)
1058
1059 def send_json_response(self, data, status_code: int = 200):
1060 """Send a JSON (UTF-8) response with CORS headers. Safe against client disconnects."""
1061 try:
1062 self.send_response(status_code)
1063 self.send_header('Content-Type', 'application/json')
1064 self.send_header('Access-Control-Allow-Origin', '*')
1065 self.send_header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
1066 self.send_header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
1067 self.send_header('Access-Control-Allow-Credentials', 'true')
1068 self.end_headers()
1069
1070 response_bytes = json.dumps(data, indent=2).encode('utf-8')
1071 self.wfile.write(response_bytes)
1072 except BrokenPipeError:
1073 # Client disconnected before we could finish sending
1074 print("⚠️ Client disconnected during response – ignoring.")
1075 except Exception as e:
1076 print(f"❌ Error sending response: {e}")
1077
1078 def log_message(self, format, *args):
1079 """Custom log format"""

Callers 15

do_GETMethod · 0.95
handle_chatMethod · 0.95
handle_get_sessionsMethod · 0.95
handle_get_sessionMethod · 0.95
handle_create_sessionMethod · 0.95
handle_session_chatMethod · 0.95
handle_delete_sessionMethod · 0.95
handle_file_uploadMethod · 0.95
handle_pdf_uploadMethod · 0.95

Calls 1

encodeMethod · 0.80

Tested by

no test coverage detected