Skip to content

Commit 56460bc

Browse files
committed
Add a test for line length.
1 parent 60929d0 commit 56460bc

File tree

1 file changed

+28
-5
lines changed
  • test/protocol/http1/connection

1 file changed

+28
-5
lines changed

test/protocol/http1/connection/bad.rb

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
describe Protocol::HTTP1::Connection do
1010
include_context ConnectionContext
1111

12-
def before
13-
super
14-
15-
client.stream.write(input)
16-
client.stream.close
12+
before do
13+
# We use a thread here, as writing to the stream may block, e.g. if the input is big enough.
14+
@writer = Thread.new do
15+
client.stream.write(input)
16+
client.stream.close
17+
end
18+
end
19+
20+
after do
21+
@writer.join
1722
end
1823

1924
with "invalid hexadecimal content-length" do
@@ -122,4 +127,22 @@ def input
122127
end.to raise_exception(Protocol::HTTP1::BadRequest)
123128
end
124129
end
130+
131+
with "line length exceeding the limit" do
132+
def input
133+
<<~HTTP.gsub("\n", "\r\n")
134+
POST / HTTP/1.1
135+
Host: a.com
136+
Connection: close
137+
Long-Header: #{'a' * 8192}
138+
139+
HTTP
140+
end
141+
142+
it "should fail to parse the request" do
143+
expect do
144+
server.read_request
145+
end.to raise_exception(Protocol::HTTP1::LineLengthError)
146+
end
147+
end
125148
end

0 commit comments

Comments
 (0)