mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
this plugin is an HTTP/2 only plugin which enables bidirectional streaming the client can continue writing request streams as response streams arrive midway Closes https://github.com/HoneyryderChuck/httpx/discussions/71
28 lines
648 B
Ruby
28 lines
648 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "test"
|
|
|
|
class Bidi < TestHTTP2Server
|
|
private
|
|
|
|
def handle_stream(_conn, stream)
|
|
stream.on(:data) do |d|
|
|
next if d.empty?
|
|
|
|
# puts "SERVER: payload chunk: <<#{d}>>"
|
|
data = JSON.parse(d)
|
|
stream.data(JSON.dump({ processed: data }) << "\n", end_stream: false)
|
|
end
|
|
|
|
stream.on(:half_close) do
|
|
stream.data("", end_stream: true)
|
|
end
|
|
|
|
stream.headers({
|
|
":status" => "200",
|
|
"date" => Time.now.httpdate,
|
|
"content-type" => "application/x-ndjson",
|
|
}, end_stream: false)
|
|
end
|
|
end
|