mirror of
https://github.com/apple/swift-nio-extras
synced 2026-11-26 04:57:49 +00:00
Throw on invalid psuedoheaders when converting between http/2 (#316)
Motivation: The HTTPType to HTTP2 conversion functions can trip up on invalid psuedo header fields. Prior to this change they'll loop indefinitely, instead they should be rejected per RFC 9113 § 8.3. Modifications: - Throw on unrecognised psuedo header fields - Add tests Result: - More spec compliant
This commit is contained in:
1 parent
92a6e73338
commit
cff75b3d21
2 files changed
+85
-5
No files matched your search
@@ -15,7 +15,7 @@
|
||||
import HTTPTypes
|
||||
import NIOHPACK
|
||||
|
||||
private enum HTTP2TypeConversionError: Error {
|
||||
package enum HTTP2TypeConversionError: Error, Equatable {
|
||||
case multipleMethod
|
||||
case multipleScheme
|
||||
case multipleAuthority
|
||||
@@ -30,6 +30,7 @@ private enum HTTP2TypeConversionError: Error {
|
||||
|
||||
case pseudoFieldNotFirst
|
||||
case pseudoFieldInTrailers
|
||||
case unknownPseudoField
|
||||
}
|
||||
|
||||
extension HPACKIndexing {
|
||||
@@ -100,7 +101,7 @@ extension HPACKHeaders {
|
||||
}
|
||||
|
||||
extension HTTPRequest {
|
||||
init(_ hpack: HPACKHeaders) throws {
|
||||
package init(_ hpack: HPACKHeaders) throws {
|
||||
var methodString: String? = nil
|
||||
var methodIndexable: HPACKIndexing = .indexable
|
||||
var schemeString: String? = nil
|
||||
@@ -150,7 +151,7 @@ extension HTTPRequest {
|
||||
protocolString = value
|
||||
protocolIndexable = indexable
|
||||
default:
|
||||
continue
|
||||
throw HTTP2TypeConversionError.unknownPseudoField
|
||||
}
|
||||
i = hpack.index(after: i)
|
||||
}
|
||||
@@ -194,7 +195,7 @@ extension HTTPRequest {
|
||||
}
|
||||
|
||||
extension HTTPResponse {
|
||||
init(_ hpack: HPACKHeaders) throws {
|
||||
package init(_ hpack: HPACKHeaders) throws {
|
||||
var statusString: String? = nil
|
||||
var statusIndexable: HPACKIndexing = .indexable
|
||||
|
||||
@@ -212,7 +213,7 @@ extension HTTPResponse {
|
||||
statusString = value
|
||||
statusIndexable = indexable
|
||||
default:
|
||||
continue
|
||||
throw HTTP2TypeConversionError.unknownPseudoField
|
||||
}
|
||||
i = hpack.index(after: i)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user