aboutsummaryrefslogtreecommitdiff
path: root/Sources/swiftGopherClient
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2023-12-19 16:01:18 -0700
committerNavan Chauhan <navanchauhan@gmail.com>2023-12-19 16:01:18 -0700
commitd620e27eea7974b74117f77e556d0bf0062c842d (patch)
tree8ee97b8d613b6b1595400ef01f15986d2ce48bcf /Sources/swiftGopherClient
parent6a21acca8a294df4bf113d7c11863733ff84336c (diff)
add fallback for incorrectly formatted gophermaps
Diffstat (limited to 'Sources/swiftGopherClient')
-rw-r--r--Sources/swiftGopherClient/gopherRequestResponseHandler.swift20
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")