diff --git a/Sources/PerfectHTTPServer/HTTP11/HTTP11Request.swift b/Sources/PerfectHTTPServer/HTTP11/HTTP11Request.swift index b6d7fce..9cafe44 100644 --- a/Sources/PerfectHTTPServer/HTTP11/HTTP11Request.swift +++ b/Sources/PerfectHTTPServer/HTTP11/HTTP11Request.swift @@ -395,7 +395,11 @@ class HTTP11Request: HTTPRequest { workingBuffer.removeAll() case .headerField: workingBuffer.append(0) - lastHeaderName = String(validatingUTF8: UnsafeMutableRawPointer(mutating: workingBuffer).assumingMemoryBound(to: Int8.self)) + lastHeaderName = workingBuffer.withUnsafeBufferPointer { + return $0.baseAddress?.withMemoryRebound(to: Int8.self, capacity: workingBuffer.count) { + return String(validatingUTF8: $0) + } + } workingBuffer.removeAll() case .headerValue: if let name = lastHeaderName { @@ -476,8 +480,11 @@ class HTTP11Request: HTTPRequest { // false indicates that the request either was fully read and is being processed or that the request failed // either way no further action should be taken func didReadSomeBytes(_ b: [UInt8], callback: @escaping StatusCallback) -> Bool { - _ = UnsafePointer(b).withMemoryRebound(to: Int8.self, capacity: b.count) { - http_parser_execute(&parser, &parserSettings, $0, b.count) + var mutableB = b + _ = mutableB.withUnsafeMutableBufferPointer { buffered in + buffered.baseAddress?.withMemoryRebound(to: Int8.self, capacity: b.count) { + http_parser_execute(&parser, &parserSettings, $0, b.count) + } } let http_errno = parser.http_errno diff --git a/Sources/PerfectHTTPServer/HTTPContentCompression.swift b/Sources/PerfectHTTPServer/HTTPContentCompression.swift index 8261462..df7ce1e 100644 --- a/Sources/PerfectHTTPServer/HTTPContentCompression.swift +++ b/Sources/PerfectHTTPServer/HTTPContentCompression.swift @@ -49,7 +49,12 @@ class ZlibStream { dest.deallocate() } if !bytes.isEmpty { - stream.next_in = UnsafeMutablePointer(mutating: bytes) + var byts = bytes + byts.withUnsafeMutableBufferPointer { buffered in + buffered.baseAddress?.withMemoryRebound(to: Bytef.self, capacity: bytes.count) { + stream.next_in = $0 + } + } stream.avail_in = uInt(bytes.count) } else { stream.next_in = nil