-
Notifications
You must be signed in to change notification settings - Fork 1
⚡ Optimize JSON Serialization to Remove Indentation #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -109,10 +109,10 @@ def do_GET(self): | |||||
|
|
||||||
| def send_json(self, data): | ||||||
| self.send_response(200) | ||||||
| self.send_header('Content-Type', 'application/json') | ||||||
| self.send_header('Content-Type', 'application/json; charset=utf-8') | ||||||
| self.send_header('Access-Control-Allow-Origin', '*') | ||||||
| self.end_headers() | ||||||
| self.wfile.write(json.dumps(data, separators=(',', ':')).encode()) | ||||||
| self.wfile.write(json.dumps(data, separators=(',', ':')).encode('utf-8')) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To further optimize payload size and serialization performance, consider adding 'ensure_ascii=False' to 'json.dumps'. By default, 'json.dumps' escapes non-ASCII characters into 6-byte sequences (e.g., '\uXXXX'). Since the output is explicitly encoded as UTF-8, allowing raw UTF-8 characters is more efficient and aligns with the PR's optimization goals.
Suggested change
|
||||||
|
|
||||||
| def log_message(self, format, *args): | ||||||
| """Override to customize logging""" | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'charset' parameter is not defined for the 'application/json' media type according to RFC 8259. JSON text is required to be encoded using UTF-8 when exchanged between systems, making this addition redundant and technically non-standard.