Skip to content

Commit 5d8754b

Browse files
Add test for head requests.
1 parent 16655cb commit 5d8754b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/protocol/rack/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
require_relative "body"
77
require_relative "constants"
8-
# require 'time'
98

109
require "protocol/http/response"
1110
require "protocol/http/headers"
11+
require "protocol/http/body/head"
1212

1313
module Protocol
1414
module Rack

test/protocol/rack/response.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Copyright, 2022-2025, by Samuel Williams.
55

66
require "sus/fixtures/console"
7+
require "protocol/http/request"
78
require "protocol/rack/response"
89

910
describe Protocol::Rack::Response do
@@ -14,8 +15,9 @@
1415
let(:headers) {Hash.new}
1516
let(:meta) {Hash.new}
1617
let(:body) {Array.new}
18+
let(:request) {nil}
1719

18-
let(:response) {subject.wrap(env, status, Protocol::HTTP::Headers[headers], meta, body)}
20+
let(:response) {subject.wrap(env, status, Protocol::HTTP::Headers[headers], meta, body, request)}
1921

2022
with "hop headers" do
2123
let(:headers) {{"connection" => "keep-alive", "keep-alive" => "timeout=10, max=100"}}
@@ -30,4 +32,12 @@
3032
expect_console.to have_logged(message: be =~ /Ignoring hop headers/)
3133
end
3234
end
35+
36+
with "head request" do
37+
let(:request) {Protocol::HTTP::Request.new("https", "example.com", "HEAD", "/", "http/1.1", Protocol::HTTP::Headers[{"accept" => "text/html"}], body)}
38+
39+
it "should return a head response" do
40+
expect(response.body).to be_a(::Protocol::HTTP::Body::Head)
41+
end
42+
end
3343
end

0 commit comments

Comments
 (0)