mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Improve JSON output formatting of webhook receiver
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import sys
|
import sys
|
||||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||||
|
|
||||||
@ -47,8 +48,10 @@ class WebhookHandler(BaseHTTPRequestHandler):
|
|||||||
# Print the request body (if any)
|
# Print the request body (if any)
|
||||||
content_length = self.headers.get('Content-Length')
|
content_length = self.headers.get('Content-Length')
|
||||||
if content_length is not None:
|
if content_length is not None:
|
||||||
body = self.rfile.read(int(content_length))
|
body = self.rfile.read(int(content_length)).decode('utf-8')
|
||||||
print(body.decode('utf-8'))
|
if self.headers.get('Content-Type') == 'application/json':
|
||||||
|
body = json.loads(body)
|
||||||
|
print(json.dumps(body, indent=4))
|
||||||
else:
|
else:
|
||||||
print('(No body)')
|
print('(No body)')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user