Skip to content

Instantly share code, notes, and snippets.

@shc261392
Created December 17, 2022 08:26
Show Gist options
  • Save shc261392/168e07b007fcebfb1fa7192fb6bab816 to your computer and use it in GitHub Desktop.
Save shc261392/168e07b007fcebfb1fa7192fb6bab816 to your computer and use it in GitHub Desktop.
A simple HTTP server for debugging POST request content-length header and actual content length.
#!/usr/bin/env python3
import http.server
import socketserver
PORT = 8000
class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_POST(self):
print('Received header Content-Length: ', self.headers['Content-Length'])
content = self.rfile.read(int(self.headers['Content-Length']))
print('Received actual bytes: ', len(content))
self.send_response(200)
self.end_headers()
self.rfile.close()
with socketserver.TCPServer(('', PORT), CustomHTTPRequestHandler) as httpd:
print('serving at port', PORT)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment