Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 25 lines (21 sloc) 715 Bytes
#!/usr/bin/env python3
#
# An HTTP server that returns fewer bytes in the body of the response than
# stated in the chunk size when using "Transfer-Encoding: Chunked".
#
import socketserver
class MyTCPHandler(socketserver.BaseRequestHandler):
def handle(self):
data = self.request.recv(1024)
print(data.decode())
self.request.sendall(
b'HTTP/1.1 200 OK\r\n'
b'Transfer-Encoding: chunked\r\n'
b'\r\n'
b'a\r\n' # size of the chunk (0xa = 10)
b'123456'
)
class MyTCPSever(socketserver.TCPServer):
allow_reuse_address = True
with MyTCPSever(('localhost', 8080), MyTCPHandler) as server:
server.serve_forever()