From b1d4c766f4bdd0f5c37d72941a73b4f8b6a3272c Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Sat, 9 Mar 2024 21:45:24 -0700 Subject: fix work with character mode --- Sources/swift-gopher/gopherHandler.swift | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'Sources') diff --git a/Sources/swift-gopher/gopherHandler.swift b/Sources/swift-gopher/gopherHandler.swift index a9a3167..8b7100d 100644 --- a/Sources/swift-gopher/gopherHandler.swift +++ b/Sources/swift-gopher/gopherHandler.swift @@ -37,7 +37,7 @@ final class GopherHandler: ChannelInboundHandler { var input = self.unwrapInboundIn(data) buffer.writeBuffer(&input) - print(buffer.readableBytes) + // print(buffer.readableBytes) if let requestString = buffer.getString(at: 0, length: buffer.readableBytes) { if requestString.firstIndex(of: "\r\n") != nil || requestString.firstIndex(of: "\n") != nil @@ -51,7 +51,8 @@ final class GopherHandler: ChannelInboundHandler { logger.warning("Unable to retrieve remote address") } - var processedRequestString: String = requestString + var processedRequestString: String = requestString.replacingOccurrences( + of: "\r\0", with: "") // Check for backspace or delete and process them if processedRequestString.contains(delChar) || processedRequestString.contains(backspaceChar) @@ -78,13 +79,13 @@ final class GopherHandler: ChannelInboundHandler { processedRequestString = processDeleteCharacter(processedRequestString) // Could just combine in one statement if asciiCode is changed to asciiCodes: [Int] } - // for character in requestString { // Helpful for debugging - // if let scalar = character.unicodeScalars.first, scalar.value < 128 { - // print("\(character): \(scalar.value)") - // } else { - // print("\(character): Not an ASCII character") - // } - // } +// for character in requestString { // Helpful for debugging +// if let scalar = character.unicodeScalars.first, scalar.value < 128 { +// print("\(character): \(scalar.value)") +// } else { +// print("\(character): Not an ASCII character") +// } +// } let response = processGopherRequest(processedRequestString) var outputBuffer: ByteBuffer -- cgit v1.2.3