Created
December 17, 2022 08:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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