Skip to content

Commit fdb36d3

Browse files
committed
Fix failing tests
1 parent 59d3f08 commit fdb36d3

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

Sources/AWSLambdaRuntimeCore/ControlPlaneResponseDecoder.swift

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import NIOCore
16-
#if canImport(Darwin)
17-
import Darwin
18-
#else
19-
import Glibc
20-
#endif
2116

2217
struct ControlPlaneResponseDecoder: NIOSingleStepByteToMessageDecoder {
2318
typealias InboundOut = ControlPlaneResponse
@@ -191,12 +186,7 @@ struct ControlPlaneResponseDecoder: NIOSingleStepByteToMessageDecoder {
191186
throw LambdaRuntimeError.responseHeadInvalidStatusLine
192187
}
193188

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 {
200190
throw LambdaRuntimeError.responseHeadInvalidStatusLine
201191
}
202192

@@ -401,6 +391,28 @@ extension ControlPlaneResponseDecoder {
401391
}
402392

403393
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+
404416
fileprivate mutating func readHeaderName(_ name: String) -> Bool {
405417
let result = self.withUnsafeReadableBytes { inputBuffer in
406418
name.utf8.withContiguousStorageIfAvailable { nameBuffer -> Bool in

0 commit comments

Comments
 (0)