mirror of
https://github.com/apple/swift-nio-http2
synced 2026-11-26 04:57:50 +00:00
Minor fixes
This commit is contained in:
1 parent
e5d470daf6
commit
986922e01f
2 files changed
+56
-15
No files matched your search
@@ -105,6 +105,46 @@ extension HTTP2ErrorCode: Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
extension HTTP2ErrorCode: CustomDebugStringConvertible {
|
||||
public var debugDescription: String {
|
||||
let errorCodeDescription: String
|
||||
switch self {
|
||||
case .noError:
|
||||
errorCodeDescription = "No Error"
|
||||
case .protocolError:
|
||||
errorCodeDescription = "ProtocolError"
|
||||
case .internalError:
|
||||
errorCodeDescription = "Internal Error"
|
||||
case .flowControlError:
|
||||
errorCodeDescription = "Flow Control Error"
|
||||
case .settingsTimeout:
|
||||
errorCodeDescription = "Settings Timeout"
|
||||
case .streamClosed:
|
||||
errorCodeDescription = "Stream Closed"
|
||||
case .frameSizeError:
|
||||
errorCodeDescription = "Frame Size Error"
|
||||
case .refusedStream:
|
||||
errorCodeDescription = "Refused Stream"
|
||||
case .cancel:
|
||||
errorCodeDescription = "Cancel"
|
||||
case .compressionError:
|
||||
errorCodeDescription = "Compression Error"
|
||||
case .connectError:
|
||||
errorCodeDescription = "Connect Error"
|
||||
case .enhanceYourCalm:
|
||||
errorCodeDescription = "Enhance Your Calm"
|
||||
case .inadequateSecurity:
|
||||
errorCodeDescription = "Inadequate Security"
|
||||
case .http11Required:
|
||||
errorCodeDescription = "HTTP/1.1 Required"
|
||||
default:
|
||||
errorCodeDescription = "Unknown Error"
|
||||
}
|
||||
|
||||
return "HTTP2ErrorCode<0x\(String(self.networkCode, radix: 16)) \(errorCodeDescription)>"
|
||||
}
|
||||
}
|
||||
|
||||
public extension UInt32 {
|
||||
/// Create a 32-bit integer corresponding to the given `HTTP2ErrorCode`.
|
||||
public init(http2ErrorCode code: HTTP2ErrorCode) {
|
||||
|
||||
@@ -266,27 +266,28 @@ fileprivate struct StreamManager {
|
||||
return self.streamMap[streamID]
|
||||
}
|
||||
|
||||
/// Obtains a NIO stream data block for a given stream if one exists, otherwise creates a new one and
|
||||
/// caches it.
|
||||
mutating func getOrCreateStreamData(for streamID: Int32) -> HTTP2Stream {
|
||||
if let streamData = self.getStreamData(for: streamID) {
|
||||
return streamData
|
||||
}
|
||||
|
||||
let streamData = self.createStreamData(for: streamID)
|
||||
/// Creates stream data for a given stream.
|
||||
mutating func createStreamData(for streamID: Int32) -> HTTP2Stream {
|
||||
self.purgeOldStreams()
|
||||
let streamData = HTTP2Stream(mode: self.mode, streamID: HTTP2StreamID(knownID: streamID))
|
||||
self.streamMap[streamID] = streamData
|
||||
return streamData
|
||||
}
|
||||
|
||||
/// Creates stream data for a given stream.
|
||||
mutating func createStreamData(for streamID: Int32) -> HTTP2Stream {
|
||||
/// Creates stream data for a given stream with an internal stream ID.
|
||||
mutating func createStreamData(for internalStreamID: HTTP2StreamID) -> HTTP2Stream {
|
||||
self.purgeOldStreams()
|
||||
let streamData = HTTP2Stream(mode: self.mode, streamID: internalStreamID)
|
||||
self.streamMap[internalStreamID.networkStreamID!] = streamData
|
||||
return streamData
|
||||
}
|
||||
|
||||
// Discard old and unnecessary streams.
|
||||
private mutating func purgeOldStreams() {
|
||||
while self.streamMap.count >= maxSize {
|
||||
let lowestStreamID = self.streamMap.filter { $0.value.active }.keys.sorted().first { $0 != 0 && $0 != Int32.max }!
|
||||
self.streamMap.removeValue(forKey: lowestStreamID)
|
||||
}
|
||||
|
||||
let streamData = HTTP2Stream(mode: self.mode, streamID: HTTP2StreamID(knownID: streamID))
|
||||
self.streamMap[streamID] = streamData
|
||||
return streamData
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,7 +695,7 @@ class NGHTTP2Session {
|
||||
|
||||
precondition(rc > 0)
|
||||
streamID.resolve(to: rc)
|
||||
let streamData = self.streamIDManager.createStreamData(for: rc)
|
||||
let streamData = self.streamIDManager.createStreamData(for: streamID)
|
||||
streamData.active = true
|
||||
|
||||
let blockType = streamData.newOutboundHeaderBlock(block: headers)
|
||||
|
||||
Reference in new issue
Block a user