File tree Expand file tree Collapse file tree 1 file changed +23
-11
lines changed
Sources/AWSLambdaRuntimeCore Expand file tree Collapse file tree 1 file changed +23
-11
lines changed Original file line number Diff line number Diff line change 13
13
//===----------------------------------------------------------------------===//
14
14
15
15
import NIOCore
16
- #if canImport(Darwin)
17
- import Darwin
18
- #else
19
- import Glibc
20
- #endif
21
16
22
17
struct ControlPlaneResponseDecoder : NIOSingleStepByteToMessageDecoder {
23
18
typealias InboundOut = ControlPlaneResponse
@@ -191,12 +186,7 @@ struct ControlPlaneResponseDecoder: NIOSingleStepByteToMessageDecoder {
191
186
throw LambdaRuntimeError . responseHeadInvalidStatusLine
192
187
}
193
188
194
- let cmp = buffer. readableBytesView. withUnsafeBytes { ptr in
195
- memcmp ( " HTTP/1.1 " , ptr. baseAddress, 8 ) == 0 ? true : false
196
- }
197
- buffer. moveReaderIndex ( forwardBy: 9 )
198
-
199
- guard cmp else {
189
+ guard buffer. readString ( " HTTP/1.1 " ) else {
200
190
throw LambdaRuntimeError . responseHeadInvalidStatusLine
201
191
}
202
192
@@ -401,6 +391,28 @@ extension ControlPlaneResponseDecoder {
401
391
}
402
392
403
393
extension ByteBuffer {
394
+ fileprivate mutating func readString( _ string: String ) -> Bool {
395
+ let result = self . withUnsafeReadableBytes { inputBuffer in
396
+ string. utf8. withContiguousStorageIfAvailable { validateBuffer -> Bool in
397
+ assert ( inputBuffer. count >= validateBuffer. count)
398
+
399
+ for idx in 0 ..< validateBuffer. count {
400
+ if inputBuffer [ idx] != validateBuffer [ idx] {
401
+ return false
402
+ }
403
+ }
404
+ return true
405
+ }
406
+ } !
407
+
408
+ if result {
409
+ self . moveReaderIndex ( forwardBy: string. utf8. count)
410
+ return true
411
+ }
412
+
413
+ return false
414
+ }
415
+
404
416
fileprivate mutating func readHeaderName( _ name: String ) -> Bool {
405
417
let result = self . withUnsafeReadableBytes { inputBuffer in
406
418
name. utf8. withContiguousStorageIfAvailable { nameBuffer -> Bool in
You can’t perform that action at this time.
0 commit comments