unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: Samuel Williams <samuel@oriontransfer.net>
Cc: unicorn-public@yhbt.net
Subject: Re: Is Rack partial hijack supported?
Date: Mon, 29 Aug 2022 06:42:45 +0000	[thread overview]
Message-ID: <20220829064245.GA1272@dcvr> (raw)
In-Reply-To: <B9DAECE5-D139-44E5-A442-9FAF3E2A920B@oriontransfer.net>

Samuel Williams <samuel@oriontransfer.net> 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)

  reply	other threads:[~2022-08-29  6:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-29  5:56 Is Rack partial hijack supported? Samuel Williams
2022-08-29  6:42 ` Eric Wong [this message]
2022-08-29  7:19   ` Samuel Williams
2022-08-29  8:14     ` Eric Wong
2022-09-01 21:53       ` Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220829064245.GA1272@dcvr \
    --to=e@yhbt.net \
    --cc=samuel@oriontransfer.net \
    --cc=unicorn-public@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).