|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | # Released under the MIT License. |
4 | | -# Copyright, 2019-2024, by Samuel Williams. |
| 4 | +# Copyright, 2019-2026, by Samuel Williams. |
5 | 5 |
|
6 | 6 | require "protocol/http1/connection" |
7 | 7 | require "connection_context" |
|
11 | 11 |
|
12 | 12 | with "#upgrade" do |
13 | 13 | let(:protocol) {"binary"} |
14 | | - let(:request_version) {Protocol::HTTP1::Connection::HTTP10} |
| 14 | + let(:request_version) {Protocol::HTTP1::Connection::HTTP11} |
15 | 15 |
|
16 | 16 | it "should upgrade connection" do |
17 | 17 | client.write_request("testing.com", "GET", "/", request_version, []) |
|
29 | 29 | stream = server.hijack! |
30 | 30 | expect(stream.read).to be == "Hello World" |
31 | 31 | end |
| 32 | + |
| 33 | + with "HTTP/1.0 request" do |
| 34 | + let(:request_version) {Protocol::HTTP1::Connection::HTTP10} |
| 35 | + |
| 36 | + it "should ignore upgrade header" do |
| 37 | + # RFC 9110 Section 7.8: a server MUST ignore the Upgrade header field in an HTTP/1.0 request. |
| 38 | + client.write_request("testing.com", "GET", "/", request_version, []) |
| 39 | + client.write_upgrade_body(protocol) |
| 40 | + |
| 41 | + authority, method, path, version, headers, body = server.read_request |
| 42 | + |
| 43 | + expect(version).to be == request_version |
| 44 | + expect(headers["upgrade"]).to be == [protocol] |
| 45 | + expect(body).to be_nil |
| 46 | + expect(server).not.to be(:persistent) |
| 47 | + end |
| 48 | + |
| 49 | + it "should not bypass transfer-encoding framing checks" do |
| 50 | + client.stream.write "GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\nUpgrade: #{protocol}\r\nTransfer-Encoding: chunked\r\n\r\nb\r\nHello World\r\n0\r\n\r\n" |
| 51 | + client.stream.close |
| 52 | + |
| 53 | + expect do |
| 54 | + server.read_request |
| 55 | + end.to raise_exception(Protocol::HTTP1::BadRequest, message: be =~ /HTTP\/1.0/) |
| 56 | + |
| 57 | + expect(server).not.to be(:persistent) |
| 58 | + end |
| 59 | + end |
32 | 60 | end |
33 | 61 | end |
0 commit comments