Protocol::Rack

Protocol::Rack

Provides abstractions for working with the Rack specification on top of Protocol::HTTP. This would, in theory, allow you to run any Protocol::HTTP compatible application on top any rack-compatible server.

Development Status

Features

Usage

Please browse the source code index or refer to the guides below.

Application Adapter

Given a rack application, you can adapt it for use on async-http:

require 'async'
require 'async/http/server'
require 'async/http/client'
require 'async/http/endpoint'
require 'protocol/rack/adapter'

app = proc{|env| [200, {}, ["Hello World"]]}
middleware = Protocol::Rack::Adapter.new(app)

Async do
  endpoint = Async::HTTP::Endpoint.parse("http://localhost:9292")
  
  server_task = Async(transient: true) do
    server = Async::HTTP::Server.new(middleware, endpoint)
    server.run
  end
  
  client = Async::HTTP::Client.new(endpoint)
  puts client.get("/").read
  # "Hello World"
end

Server Adapter

While not tested, in theory any Rack compatible server can host Protocol::HTTP compatible middlewares.

require 'protocol/http/middleware'
require 'protocol/rack'

# Your native application:
middleware = Protocol::HTTP::Middleware::HelloWorld

run proc{|env|
  # Convert the rack request to a compatible rich request object:
  request = Protocol::Rack::Request[env]
  
  # Call your application
  response = middleware.call(request)
  
  Protocol::Rack::Adapter.make_response(env, response)
}

Contributing

We welcome contributions to this project.

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create new Pull Request.

Developer Certificate of Origin

This project uses the Developer Certificate of Origin. All contributors to this project must agree to this document to have their contributions accepted.

Contributor Covenant

This project is governed by Contributor Covenant. All contributors and participants agree to abide by its terms.

See Also