[issue45523] Python3 ThreadingHTTPServer fails to send chunked encoded response

2021-10-19 Thread Martin Panter


Martin Panter  added the comment:

Looks like you forgot to encode the length of ten in hexadecimal.

I don't think the HTTP server module has any special handling for chunked 
responses, so this up to the user and isn't a bug in Python.

--
nosy: +martin.panter
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45523] Python3 ThreadingHTTPServer fails to send chunked encoded response

2021-10-19 Thread Manuel


New submission from Manuel :

I'm implementing an HTTPServer class that produces a response with 
transfer-encoding chunked mode.

I'm sending the chunks as described in 
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding#chunked_encoding

If I send chunks of length <= 9 bytes the message is received correctly by the 
client, otherwise when sending chunks of length >= 10 bytes, it seems that some 
of them are not received and the message remains stuck in the client waiting 
indefinitely

In attachment an example of the complete code to reproduce the issue, but in 
short, the following code:

# writing 5 chunks of length 10
for i in range(5):
text = str(i+1) * 10  # concatenate 10 chars
chunk = '{0:d}\r\n'.format(len(text)) + text + '\r\n'
self.wfile.write(chunk.encode(encoding='utf-8'))

# writing close sequence
close_chunk = '0\r\n\r\n'
self.wfile.write(close_chunk.encode(encoding='utf-8'))

Produces:
10\r\n
11\r\n
10\r\n
22\r\n
10\r\n
33\r\n
10\r\n
44\r\n
10\r\n
55\r\n
0\r\n
\r\n

In this case the client hangs several minutes without a response 

But if I use length 9 or less instead for example with

text = str(i+1) * 9

the client receives the correct body and the communication ends correctly (in 
about 6ms)

The problem persists with both http.server.ThreadingHTTPServer and 
http.server.HTTPServer
I tried also passing the body as an hard-coded binary string

some version informations:
Python 3.9.2
HTTP Client used: Postman 8.10, curl, Chrome


Thanks a lot for any help
Manuel

--
files: myserver.py
messages: 404300
nosy: manuel_b
priority: normal
severity: normal
status: open
title: Python3 ThreadingHTTPServer fails to send chunked encoded response
type: behavior
versions: Python 3.9
Added file: https://bugs.python.org/file50369/myserver.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com