Samuel Williams <[email protected]> wrote:
> Hi Eric,
>
> I’ve been testing Rack server conformance and behaviour and noticed that
> while unicorn advertises `env[‘rack.hijack?’]` as true, it fails to correctly
> stream the following response:
>
> if env['rack.hijack?']
> callback = proc do |stream|
> stream.write "Hello World"
> stream.close
> end
>
> return [200, {'rack.hijack' => callback}, nil]
> else
> [404, {}, []]
> end
That looks fine...
> Am I misunderstanding something about how this should work or does Unicorn
> not support partial hijack?
I wonder if it's Rack::Chunked being loaded by default w/
RACK_ENV=(development|deployment) being the problem.
What error do you see? (assuming you're using curl or similar
for testing).
Does using `-E none' or RACK_ENV=none fix it?
$ cat >hijack.ru <<EOF
use Rack::ContentType, 'text/plain'
run(lambda do |env|
if env['rack.hijack?']
callback = proc do |stream|
stream.write "Hello World"
stream.close
end
return [200, {'rack.hijack' => callback}, nil]
else
[404, {}, []]
end
end)
EOF
# This works fine:
$ unicorn -E none hijack.ru
$ curl -Ssf http://0:8080/
# This fails since Rack::Chunk is loaded by default:
$ unicorn hijack.ru
$ curl -Ssf http://0:8080/
curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding
So I think the hijack callback needs to do the chunking itself;
I'm not sure...
That said, I have no idea if rack.hijack gets used at all w/
unicorn; and I seem to recall there being a bit of confusion
on how hijack and middleware would interact...
(please reply-all for archival purposes, thanks)