mirror of
https://github.com/apple/swift-nio-http2
synced 2026-11-28 05:14:25 +00:00
ignore frames that don't have a HTTP/1 equivalent (#146)
Motivation: Previously, the H2to1 codec would crash if for example a push promise came by. Modifications: Instead of crashing, ignore the frames without equivalent. Result: Fewer crashes.
This commit is contained in:
1 parent
17434a9658
commit
7de397fda8
3 files changed
+25
-5
No files matched your search
@@ -79,12 +79,9 @@ public final class HTTP2ToHTTP1ClientCodec: ChannelInboundHandler, ChannelOutbou
|
||||
if content.endStream {
|
||||
context.fireChannelRead(self.wrapInboundOut(.end(nil)))
|
||||
}
|
||||
case .alternativeService, .rstStream, .priority, .windowUpdate:
|
||||
// All these frames may be sent on a stream, but are ignored by the multiplexer and will be
|
||||
// handled elsewhere.
|
||||
case .alternativeService, .rstStream, .priority, .windowUpdate, .settings, .pushPromise, .ping, .goAway, .origin:
|
||||
// These don't have an HTTP/1 equivalent, so let's drop them.
|
||||
return
|
||||
default:
|
||||
fatalError("unimplemented frame \(frame)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ extension HTTP2ToHTTP1CodecTests {
|
||||
("testReceiveResponseWithNonNumericalStatus", testReceiveResponseWithNonNumericalStatus),
|
||||
("testSendRequestWithoutHost", testSendRequestWithoutHost),
|
||||
("testSendRequestWithDuplicateHost", testSendRequestWithDuplicateHost),
|
||||
("testFramesWithoutHTTP1EquivalentAreIgnored", testFramesWithoutHTTP1EquivalentAreIgnored),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,4 +640,26 @@ final class HTTP2ToHTTP1CodecTests: XCTestCase {
|
||||
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicateHostHeader, NIOHTTP2Errors.DuplicateHostHeader())
|
||||
}
|
||||
}
|
||||
|
||||
func testFramesWithoutHTTP1EquivalentAreIgnored() throws {
|
||||
let streamID = HTTP2StreamID(1)
|
||||
XCTAssertNoThrow(try self.channel.pipeline.addHandler(HTTP2ToHTTP1ClientCodec(streamID: streamID,
|
||||
httpProtocol: .https)).wait())
|
||||
|
||||
let headers = HPACKHeaders([(":method", "GET"), (":scheme", "https"), (":path", "/x")])
|
||||
let frames: [HTTP2Frame.FramePayload] = [.alternativeService(origin: nil, field: nil),
|
||||
.rstStream(.init(networkCode: 1)),
|
||||
.priority(.init(exclusive: true, dependency: streamID, weight: 1)),
|
||||
.windowUpdate(windowSizeIncrement: 1),
|
||||
.settings(.ack),
|
||||
.pushPromise(.init(pushedStreamID: HTTP2StreamID(2), headers: headers)),
|
||||
.ping(.init(withInteger: 123), ack: true),
|
||||
.goAway(lastStreamID: streamID, errorCode: .init(networkCode: 1), opaqueData: nil),
|
||||
.origin([])]
|
||||
for payload in frames {
|
||||
let frame = HTTP2Frame(streamID: streamID, payload: payload)
|
||||
XCTAssertNoThrow(try self.channel.writeInbound(frame), "error on \(frame)")
|
||||
}
|
||||
XCTAssertNoThrow(XCTAssertTrue(try self.channel.finish().isClean))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user