Two more problems with Mojolicious

Valentin V. Bartenev vbart at nginx.com
Mon Mar 4 15:34:52 UTC 2019


On Monday 04 March 2019 17:27:10 Александр Поволоцкий wrote:
> I mean reply, body.
> 
> Well, I thought that my application does not do any assumption, but 
> write_chunk seems to be not portable. So I need to patch Mojolicious to 
> determine PSGI, HTTP/1.1 and HTTP/2 and write data properly, or in my 
> app use write instead of write_chunk?

Indeed, write_chunk() function doesn't look portable at all.  It looks
like that it even doesn't check if a client supports chunked transfer
encoding (i.e. speaks HTTP/1.1) when working over HTTP:


sub write_chunk {
  my ($self, $chunk, $cb) = @_;
  $self->headers->transfer_encoding('chunked') unless $self->is_chunked;
  $self->write(defined $chunk ? $self->_build_chunk($chunk) : $chunk, $cb);
  $self->{eof} = 1 if defined $chunk && !length $chunk;
  return $self;
}

sub _build_chunk {
  my ($self, $chunk) = @_;

  # End
  return "\x0d\x0a0\x0d\x0a\x0d\x0a" unless length $chunk;

  # First chunk has no leading CRLF
  my $crlf = $self->{chunks}++ ? "\x0d\x0a" : '';
  return $crlf . sprintf('%x', length $chunk) . "\x0d\x0a$chunk";
}


You can just use write() with Unit.


> 
> And the problem with double encoding concerns me even more. Looks like 
> either PSGI in Mojolicious is broken, or Mojo and unit just speaks 
> different dialects...
> 

We'll try to reproduce and look what happens in this case.

But from the code above, it seems Mojo authors don't care much
about protocols other than particular version of HTTP/1.1.

  wbr, Valentin V. Bartenev



More information about the unit mailing list