Here's why WEBrick doesn't work on Glitch


If you try to serve a page from WEBrick, it fails with this message like this in the log:

bad URI `/’.

And there’s nothing particularly bad or unparsable about that, so it’s mysterious.
This post is about why that is.


Our Glitch containers run Ubuntu 16.04, with the distro’s version of Ruby, 2.3.1.

In that version of Ruby, the error comes from the HTTP request parser here

I found with some debugging that the line that raises is this one calling parse_uri, and within that, this line that sets the incoming request URI’s scheme

The forwarded proto comes from an HTTP header, which we do indeed receive from Glitch’s router.
We receive something like https,http,http, indicating that the request came from your browser over HTTPS, then the routing system forwarded it two times over HTTP.
But this string is an invalid value for the URI class’s scheme.
This raises an exception, which WEBrick swallows, providing its own unhelpful message.

What happened after Xenial’s feature freeze

Later, Ruby 2.4 came out with an enhancement to WEBrick to support comma separated X-Forwarded-Proto

Concluding words

tsk, grr