Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post requests tests. #185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion lib/async/http/protocol/http1/finishable.rb
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ class Finishable < ::Protocol::HTTP::Body::Wrapper
def initialize(body)
super(body)

$stderr.puts "Finishable#initialize: #{body.inspect}"

@closed = Async::Variable.new
@error = nil

@@ -28,12 +30,16 @@ def reading?
def read
@reading = true

super
super.tap do |chunk|
$stderr.puts "Finishable#read: #{chunk.inspect}"
end
end

def close(error = nil)
super

$stderr.puts "Finishable#close: #{error.inspect}"

unless @closed.resolved?
@error = error
@closed.value = true
45 changes: 45 additions & 0 deletions test/async/http/client/post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2024, by Samuel Williams.

require "sus/fixtures/async/http"

APostRequest = Sus::Shared("a post request") do
include Sus::Fixtures::Async::HTTP::ServerContext
let(:protocol) {subject}

let(:app) do
::Protocol::HTTP::Middleware.for do |request|
::Protocol::HTTP::Response[200, {}, request.body]
end
end

it "can post a fixed length body" do
$stderr.puts "Connecting to server: #{subject}"
body = Protocol::HTTP::Body::Buffered.wrap(["Hello, World!"])

begin
response = client.post("/", body: body)

$stderr.puts "Got response: #{response.inspect}"

expect(response).to be(:success?)
expect(response.read).to be == "Hello, World!"
ensure
response&.finish
end
end
end

describe Async::HTTP::Protocol::HTTP10 do
it_behaves_like APostRequest
end

describe Async::HTTP::Protocol::HTTP11 do
it_behaves_like APostRequest
end

describe Async::HTTP::Protocol::HTTP2 do
it_behaves_like APostRequest
end