Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 141 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ gem "rake", "~> 13.0"
gem "rake-compiler"
gem "rb_sys", "~> 0.9.63"

gem "minitest", "~> 5.16"
gem "minitest", "~> 5.0"

gem "httpx", "~> 1.4"
gem "httpx", "~> 1.2"

# gRPC dependencies
gem "grpc", "~> 1.62"
gem "grpc-tools", "~> 1.62"
gem "google-protobuf", "~> 3.25"
18 changes: 16 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ PATH
GEM
remote: https://rubygems.org/
specs:
google-protobuf (3.25.6)
google-protobuf (3.25.6-arm64-darwin)
googleapis-common-protos-types (1.18.0)
google-protobuf (>= 3.18, < 5.a)
grpc (1.70.1)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.70.1-arm64-darwin)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc-tools (1.70.1)
http-2 (1.0.2)
httpx (1.4.0)
http-2 (>= 1.0.0)
Expand All @@ -22,9 +33,12 @@ PLATFORMS
ruby

DEPENDENCIES
httpx (~> 1.4)
google-protobuf (~> 3.25)
grpc (~> 1.62)
grpc-tools (~> 1.62)
httpx (~> 1.2)
hyper_ruby!
minitest (~> 5.16)
minitest (~> 5.0)
rake (~> 13.0)
rake-compiler
rb_sys (~> 0.9.63)
Expand Down
23 changes: 20 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "minitest/test_task"
require "rake/testtask"

Minitest::TestTask.create
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.pattern = "test/**/test_*.rb"
t.warning = false
t.verbose = true
end

# Remove the existing default task
Rake::Task[:default].clear if Rake::Task.task_defined?(:default)

namespace :proto do
desc "Generate Ruby code from proto files"
task :generate do
system("grpc_tools_ruby_protoc -I test --ruby_out=test --grpc_out=test test/echo.proto") or fail "Failed to generate proto files"
end
end

require "rb_sys/extensiontask"

Expand All @@ -15,4 +31,5 @@ RbSys::ExtensionTask.new("hyper_ruby", GEMSPEC) do |ext|
ext.lib_dir = "lib/hyper_ruby"
end

task default: %i[compile test]
# Define the default task to run both compile and test
task :default => [:compile, :test]
60 changes: 60 additions & 0 deletions bin/run-server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)

puts "Loading hyper_ruby"

require "hyper_ruby"
require "json"

# Create and configure the server
server = HyperRuby::Server.new
config = {
bind_address: ENV.fetch("BIND_ADDRESS", "127.0.0.1:3000"),
tokio_threads: ENV.fetch("TOKIO_THREADS", "1").to_i,
debug: ENV.fetch("DEBUG", "false") == "true",
recv_timeout: ENV.fetch("RECV_TIMEOUT", "30000").to_i
}
server.configure(config)

puts "Starting server with config: #{config}"

# Start the server
server.start

puts "Server started"

# Create a worker thread to handle requests
worker = Thread.new do
server.run_worker do |request|
buffer = String.new(capacity: 1024)
request.fill_body(buffer)

# Create a response that echoes back request details
response_data = {
method: request.http_method,
path: request.path,
headers: request.headers,
body: buffer
}

HyperRuby::Response.new(
200,
{ "Content-Type" => "application/json" },
JSON.pretty_generate(response_data)
)
end
end

puts "Server running at #{config[:bind_address]}"
puts "Press Ctrl+C to stop"

# Wait for Ctrl+C
begin
sleep
rescue Interrupt
puts "\nShutting down..."
server.stop
worker.join
end
6 changes: 5 additions & 1 deletion ext/hyper_ruby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ tokio-stream = { version = "0.1", features = ["net"] }
crossbeam-channel = "0.5.14"
rb-sys = "0.9.110"
hyper = { version = "1.0", features = ["http1", "http2", "server"] }
hyper-util = { version = "0.1", features = ["tokio", "server", "http1", "http2"] }
hyper-util = { version = "0.1", features = ["tokio", "server", "server-auto", "http1", "http2"] }
http-body-util = "0.1.2"
jemallocator = { version = "0.5.4", features = ["disable_initial_exec_tls"] }
futures = "0.3.31"
h2 = "0.4"
async-stream = "0.3.5"
env_logger = "0.11"
log = "0.4"
Loading
Loading