-
Notifications
You must be signed in to change notification settings - Fork 118
Add ControlPlaneResponseDecoder #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| return .decoded(head) | ||
|
|
||
| case .contentLength(let length): | ||
| head.contentLength = length // TODO: This can crash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
| case 202: | ||
| return .accepted | ||
| case 400 ..< 600: | ||
| preconditionFailure("TODO: implement") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
| switch head.statusCode { | ||
| case 200: | ||
| guard let body = body else { | ||
| preconditionFailure("TODO: implement") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
| return status | ||
| } | ||
|
|
||
| private mutating func decodeCRLFTerminatedLine(from buffer: inout ByteBuffer) throws -> DecodeResult<ByteBuffer> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does nio offer any utils to parse line by line, I thought there was some Decoder for that?
| } | ||
|
|
||
| private mutating func decodeHeaderLine(from buffer: inout ByteBuffer) throws -> HeaderLineContent { | ||
| guard let colonIndex = buffer.readableBytesView.firstIndex(of: UInt8(ascii: ":")) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool trick
| @discardableResult | ||
| mutating func decodeOptionalWhiteSpaceBeforeFieldValue(from buffer: inout ByteBuffer) throws -> Int { | ||
| let startIndex = buffer.readerIndex | ||
| guard let index = buffer.readableBytesView.firstIndex(where: { $0 != UInt8(ascii: " ") && $0 != UInt8(ascii: "\t") }) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe worth defining consts for the UInt8 here and in other spots around the code
tomerd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome. looks like some leftover TODOs?
| case .contentLength(let length): | ||
| head.contentLength = length // TODO: This can crash | ||
|
|
||
| case .contentType: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dont need to record that?
296cb92 to
41cd689
Compare
41cd689 to
c848509
Compare
|
closing in inactive PRs, feel free to re-open if still relevant |
Add ControlPlaneResponseDecoder to decode incoming HTTP responses.
Motivation:
We want to save allocations wherever possible. A big driver of allocations is the NIOHTTP1 HTTPResponseDecoder. The reason for this is: It can not be optimized for the lambda use case and allocates header string values that are not needed.
Modifications:
Result:
Faster control plane response decoding.