Two more problems with Mojolicious

Valentin V. Bartenev vbart at nginx.com
Mon Mar 4 14:12:14 UTC 2019


On Monday 04 March 2019 14:25:15 Александр Поволоцкий wrote:
> Hello
> 
> 1. When I'm sending chunked content (I'm using some fairly long database 
> requests, and cursor sending lines one by one is much better in term of 
> both memory usage and response speed) is shown on client side with 
> chunks' lenghts.

HTTP and PSGI are different.

There's not such thing as Chunked Transfer Encoding in PSGI.
PSGI is specifically designed to abastract application from
transport protocol, like HTTP/1.1.

Thus application must not do any assumption about transport
protocol, and must not issue any connection level HTTP headers,
must not apply any trasfer encodings.  All the body data output
is interpreted as is (and this is required by PSGI specification).

When PSGI application writing chunks with lengths, these chunks
are wrapped into HTTP chunks (if allowed) by web server (Unit in
this case) and then they are sent to client.  As a result, you
see exactly what the application outputs.

The protocol can be HTTP/1.0 (where no chunked transfer encoding
is possible), or HTTP/2 as well (where chunks have completely
different representation as binary frames of data).

If you want to send lines one by one, you should do this in the
application just by writing these lines as is, Unit will do all
the work for transferring the data with proper encoding for
particular protocol (HTTP/1.0, HTTP/1.1, or HTTP/2, HTTP/3 in
the future).



> 
> 2. UTF-8 data gets double encoded.
> 
> If you need, I'll make a short example.

Do you mean UTF-8 data in headers or in body?
Request or response?

An example would be useful.

  wbr, Valentin V. Bartenev



More information about the unit mailing list