unit, PSGI and Mojolicous

Andrey Zelenkov zelenkov at nginx.com
Mon Jan 28 10:38:24 UTC 2019



> On 24 Jan 2019, at 19:40, Александр Поволоцкий <tarkhil at over.ru> wrote:
> 
> 
> 
> On 24.01.2019 19:13, Alexander Borisov wrote:
>> Hi Александр,
>> 
>> Please, try this patch for fix the problem:
>> # HG changeset patch
>> # User Alexander Borisov <alexander.borisov at nginx.com>
>> # Date 1548345939 -10800
>> #      Thu Jan 24 19:05:39 2019 +0300
>> # Node ID a0a93e0673de88519bfd1062bdb6df166aa5ffa9
>> # Parent  dace60fc4926351efe9322761faf974b0ce7964a
>> Perl: fixed issue with body reading from response object.
>> 
>>>>> The smallest possible app, however, does not run
>>>>> 
>>>>> ===
>>>>> #!/usr/bin/env perl
>>>>> use Mojolicious::Lite;
>>>>> get '/' => sub {
>>>>>      my $c = shift;
>>>>> $c->render(text=>'hello');
>>>>> };
>>>>> 
>>>>> app->start;
>>>>> ===
>>>>> 
>>>>> 2019/01/23 09:41:23.029 [error] 26579#26579 [unit] #4: PSGI: Failed to
>>>>> run Perl Application:
>>>>> Undefined subroutine &main::1 called.
>>>>> 
>>>>> plackup runs it Ok, so there is some incompatibility, which I do not
>>>>> know how to trace.
>>>>> 
>>>>> What kind of error in framework can it be and how to trace it?
>>>>> 
>>>> [..]
>>>> 
>>>> https://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#PSGI-Plack
>>>> 
>>>> Seems it doesn't behave like PSGI application by default,
>>>> unless there's a PLACK_ENV environment variable.
>>>> 
>>>> Unit doesn't set PLACK_ENV by default.
>>> 
>>> Sorry for doubleposting, but I've found one strange thing.
>>> 
>>> root at VMNEW:~# telnet localhost 8000
>>> Trying ::1...
>>> Trying 127.0.0.1...
>>> Connected to localhost.
>>> Escape character is '^]'.
>>> GET / HTTP/1.0
>>> 
>>> HTTP/1.1 200 OK
>>> Content-Length: 6
>>> Date: Wed, 23 Jan 2019 19:31:37 GMT
>>> Content-Type: text/html;charset=UTF-8
>>> Server: Unit/1.7
>>> 
>>> Connection closed by foreign host.
>>> 
>>> when I was expecting "hello\n" to be sent as output. You see, Content-Length is correct, but no actual content.
>>> 
>>> Alex
>>> 
>>> _______________________________________________
>>> unit mailing list
>>> unit at nginx.org
>>> https://mailman.nginx.org/mailman/listinfo/unit
>> 
>> 
> Cool, it nearly works. But looks like headers with underscore (yes I know that's wrong) are not passed to PSGI app

Hi Alex,

I tried to send header with underscore and it looks like app have access to it.

For the following request:

===
GET / HTTP/1.1
Host: localhost
_X_-Foo-Bar_: _bl_ah_
Connection: close

===

I've got response:

===
HTTP/1.1 200 OK
Content-Length: 7
Content-Type: text/html;charset=UTF-8
Date: Mon, 28 Jan 2019 10:23:30 GMT
Server: Unit/1.8
Connection: close

_bl_ah_
===

And PSGI app that I used is:

===
use Mojolicious::Lite;

get '/' => sub {
    my $c = shift;
    $c->render(text=>$c->req->headers->header('-X--Foo-Bar-'));
};
===


Could you please provide more information about
how you try to use headers with underscore?

--
Andrey Zelenkov



More information about the unit mailing list