diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2023-12-19 16:01:18 -0700 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2023-12-19 16:01:18 -0700 |
commit | d620e27eea7974b74117f77e556d0bf0062c842d (patch) | |
tree | 8ee97b8d613b6b1595400ef01f15986d2ce48bcf | |
parent | 6a21acca8a294df4bf113d7c11863733ff84336c (diff) |
add fallback for incorrectly formatted gophermaps
-rw-r--r-- | Sources/swiftGopherClient/gopherRequestResponseHandler.swift | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Sources/swiftGopherClient/gopherRequestResponseHandler.swift b/Sources/swiftGopherClient/gopherRequestResponseHandler.swift index 6cede51..8349c6e 100644 --- a/Sources/swiftGopherClient/gopherRequestResponseHandler.swift +++ b/Sources/swiftGopherClient/gopherRequestResponseHandler.swift @@ -88,12 +88,22 @@ final class GopherRequestResponseHandler: ChannelInboundHandler { "Carriage Returns: \(carriageReturnCount), Newline + Carriage Returns: \(newlineCarriageReturnCount)" ) - for line in response.split(separator: "\r\n") { - let lineItemType = getGopherFileType(item: "\(line.first ?? " ")") - let item = createGopherItem( - rawLine: String(line), itemType: lineItemType, rawData: originalBytes) - gopherServerResponse.append(item) + if carriageReturnCount == 0 { + for line in response.split(separator: "\n") { + let lineItemType = getGopherFileType(item: "\(line.first ?? " ")") + let item = createGopherItem( + rawLine: String(line), itemType: lineItemType, rawData: originalBytes) + gopherServerResponse.append(item) + } + } else { + for line in response.split(separator: "\r\n") { + let lineItemType = getGopherFileType(item: "\(line.first ?? " ")") + let item = createGopherItem( + rawLine: String(line), itemType: lineItemType, rawData: originalBytes) + gopherServerResponse.append(item) + + } } print("done parsing") |