mirror of
https://github.com/apple/swift-nio-http2
synced 2026-11-28 05:14:25 +00:00
Allow changing MAX_FRAME_SIZE. (#69)
Motivation: SETTINGS_MAX_FRAME_SIZE is changeable: we should allow that change to occur. Modifications: - Added fields for communicating MAX_FRAME_SIZE changes. - Update the encoders/decoders as those settings change. - Throw errors from the encoders/decoders if violated. Result: Users and remote peers can change MAX_FRAMES_SIZE.
This commit is contained in:
1 parent
7e17e72f41
commit
ed9244267b
9 files changed
+88
-4
No files matched your search
@@ -228,6 +228,9 @@ struct HTTP2FrameDecoder {
|
||||
private var state: ParserState
|
||||
private var allocator: ByteBufferAllocator
|
||||
|
||||
// RFC 7540 § 6.5.2 puts the initial value of SETTINGS_MAX_FRAME_SIZE at 2**14 octets
|
||||
internal var maxFrameSize: UInt32 = 1<<14
|
||||
|
||||
/// Creates a new HTTP2 frame decoder.
|
||||
///
|
||||
/// - parameter allocator: A `ByteBufferAllocator` used when accumulating blocks of data
|
||||
@@ -319,6 +322,11 @@ struct HTTP2FrameDecoder {
|
||||
return .needMoreData
|
||||
}
|
||||
|
||||
// Confirm that SETTINGS_MAX_FRAME_SIZE is respected.
|
||||
guard header.length <= self.maxFrameSize else {
|
||||
throw InternalError.codecError(code: .frameSizeError)
|
||||
}
|
||||
|
||||
if header.type != 0 {
|
||||
// Not a DATA frame.
|
||||
self.state = .accumulatingData(AccumulatingPayloadParserState(fromIdle: state, header: header))
|
||||
@@ -924,6 +932,9 @@ struct HTTP2FrameEncoder {
|
||||
private let allocator: ByteBufferAllocator
|
||||
var headerEncoder: HPACKEncoder
|
||||
|
||||
// RFC 7540 § 6.5.2 puts the initial value of SETTINGS_MAX_FRAME_SIZE at 2**14 octets
|
||||
var maxFrameSize: UInt32 = 1<<14
|
||||
|
||||
init(allocator: ByteBufferAllocator) {
|
||||
self.allocator = allocator
|
||||
self.headerEncoder = HPACKEncoder(allocator: allocator)
|
||||
@@ -1125,6 +1136,11 @@ struct HTTP2FrameEncoder {
|
||||
extraFrameData = nil
|
||||
}
|
||||
|
||||
// Confirm we're not about to violate SETTINGS_MAX_FRAME_SIZE.
|
||||
guard payloadSize <= Int(self.maxFrameSize) else {
|
||||
throw InternalError.codecError(code: .frameSizeError)
|
||||
}
|
||||
|
||||
// Write the frame data. This is the payload size and the flags byte.
|
||||
buf.writePayloadSize(payloadSize, at: start)
|
||||
buf.setInteger(flags.rawValue, at: flagsIndex)
|
||||
|
||||
Reference in new issue
Block a user