Project

kantan

0.0
No release in over 3 years
An HTTP/2.0 parser in Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.0
~> 3
~> 13.0
 Project Readme

Kantan - Pure Ruby HTTP/2 and HTTP/3 (QUIC) Implementation

An HTTP/2 and HTTP/3 server and client implementation in pure Ruby.

Passes h2spec and hpack-test-case.

Only works with Ruby 4.1.0+

Client

An example using HTTP/2 is here: examples/fetch_google.rb

An example using HTTP/3 is here: examples/quic_fetch.rb

Server

Just a demo server:

# frozen_string_literal: true

require "kantan"
require "socket"
require "logger"

class MyApp < Kantan::Handler
  def on_request stream
    stream.respond [[":status", "200"]], body: "hello"
  end
end

server = TCPServer.new "127.0.0.1", 8888

logger = Logger.new $stderr
logger.debug "port #{8888}"

while true
  client_fd = server.sysaccept

  logger.debug "new connection"
  Ractor.new(client_fd) do |c_fd|
    c = Socket.for_fd(c_fd)
    c.autoclose = true
    c.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
    session = Kantan::Session.new(c, handler: MyApp.new)
    session.receive
    session.join
  end
end