1
0
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:
Jeremy Stretch
2021-03-09 12:03:56 -05:00
parent 6ffadb501b
commit c083b862a7

View File

@ -1,3 +1,4 @@
import json
import sys
from http.server import HTTPServer, BaseHTTPRequestHandler
@ -47,8 +48,10 @@ class WebhookHandler(BaseHTTPRequestHandler):
# Print the request body (if any)
content_length = self.headers.get('Content-Length')
if content_length is not None:
body = self.rfile.read(int(content_length))
print(body.decode('utf-8'))
body = self.rfile.read(int(content_length)).decode('utf-8')
if self.headers.get('Content-Type') == 'application/json':
body = json.loads(body)
print(json.dumps(body, indent=4))
else:
print('(No body)')