Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

the_metal

> 编程语言
Open source

A spike for thoughts about Rack 2.0

520 stars0 likes3 views
WebsiteGitHub

About

A spike for thoughts about Rack 2.0

the_metal

  • http://github.com/tenderlove/the_metal

DESCRIPTION:

A spike for researching Rack 2.0

FEATURES/PROBLEMS:

Totally experimental. It's just a spike.

SYNOPSIS:

An app without any middleware:

ruby
gem 'the_metal', github: 'tenderlove/the_metal'
ruby
require 'the_metal/puma'

TheMetal.create_server(->(req, res) {
  res.write_head 200, 'Content-Type' => 'text/plain'
  res.write "Hello World\n"
  res.finish
}).listen 9292, '0.0.0.0'

You can use a class too:

ruby
class Application
  def call req, res
    res.write_head 200, 'Content-Type' => 'text/plain'
    res.write "Hello World\n"
    res.finish
  end
end

require 'the_metal/puma'
server = TheMetal.create_server Application.new
server.listen 9292, '0.0.0.0'

An app that checks out a database connection when the request starts and checks it back in when the response is finished:

…

IDEAS:

Middleware

We should separate middleware from the server itself. In other words, build_app should probably be a separate Gem, and we can make a nicer API for it than the above examples.

I think Rack middleware should be out of scope for Rack 2.0. This is analogous to the Node.JS / Connect relationship. We should develop a middleware handler separately from the webserver interface. The build_app middleware API implemented here is just a suggestion and an experiment to demonstrate how middleware could work with this API. I think Rack 2.0 should only handle the first example.

Webservers

Webserver should supply a request and response object to the handler. Rack 2.0 will define the API on the request and response object, but we should keep it to a minimum. Rack 2.0 should implement request and response objects that webserver implementers can reuse -- we shouldn't have code for writing headers to a socket duplicated across many webserver implementations.

Application code should be executed immediately after the request headers have been read in. The request object should have an IO where post bodies can be ready. The IO is not rewindable.

The response object should have an output IO. The output IO doesn't have to be the same as the input IO. This is entirely up to the webserver implementer.

Tests

So far, the ideas I've laid out are sort of vague, and I've not been very specific about the exact behavior. To address this, I think we should develop a test suite that web server implementors can run to ensure that all webservers behave similarly. Think RubySpec, but for Ruby webservers. I've demonstrated that with Unicorn, Puma, and WEBRick in the tests for this project.

Finally

This is a spike. It is extremely experimental at this point, but it puts most of my thoughts to code. My overall idea is:

  • Applications should be dealing with streams
  • Request / Response objects abstract applications from specific implementations
  • A middleware framework should not be defined by Rack 2.0.
  • Test should ensure webserver compatibility

If you have ideas for changes, please open a ticket or send a pull request. Let's make the HTTP landscape for Ruby even more amazing!

LICENSE:

(The MIT License)

Copyright (c) 2014 Aaron Patterson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言