Skip to content

Commit c71df3e

Browse files
Confusing response behaviour.
1 parent 6618545 commit c71df3e

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

ext/hyper_ruby/src/response.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ impl Response {
5959
// copy back from the hyper body to the ruby string; doesn't need to be performant,
6060
// only used in tests
6161
let body = self.response.body();
62-
let frame = body.clone().frame().now_or_never().unwrap().unwrap().unwrap();
63-
let data_chunk = frame.into_data().unwrap();
64-
RString::from_slice(data_chunk.iter().as_slice())
62+
match body.clone().frame().now_or_never() {
63+
Some(frame) => {
64+
let data_chunk = frame.unwrap().unwrap().into_data().unwrap();
65+
RString::from_slice(data_chunk.iter().as_slice())
66+
}
67+
None => RString::buf_new(0),
68+
}
6569
}
6670
}

test/test_hyper_ruby.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ def test_unix_socket_cleans_up_socket
6464
end
6565
end
6666

67-
def test_blocking
68-
buffer = String.new(capacity: 1024)
69-
with_server(-> (request) { handler_accept(request, buffer) }) do |client|
70-
gets
71-
end
72-
end
67+
# def test_blocking
68+
# buffer = String.new(capacity: 1024)
69+
# with_server(-> (request) { handler_accept(request, buffer) }) do |client|
70+
# gets
71+
# end
72+
# end
7373

7474
def with_server(request_handler, &block)
7575
server = HyperRuby::Server.new

test/test_response.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ def test_can_read_properties_back
1212
assert_equal 'Hello, world!', response.body
1313
end
1414

15+
def test_can_read_property_with_empty_body
16+
response = HyperRuby::Response.new(200, { 'Content-Type' => 'text/plain' }, '')
17+
assert_equal 200, response.status
18+
assert_equal 'text/plain', response.headers['content-type']
19+
assert_equal '', response.body
20+
end
21+
1522
end

0 commit comments

Comments
 (0)