From 81f90e6340e84027bb62a15f8fa5048da9842b32 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Sat, 9 Dec 2023 15:57:59 -0700 Subject: added version string to response --- Sources/Helpers.swift | 8 ++++++++ Sources/gopherHandler.swift | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Sources/Helpers.swift b/Sources/Helpers.swift index fecc4ab..8481347 100644 --- a/Sources/Helpers.swift +++ b/Sources/Helpers.swift @@ -1 +1,9 @@ import Foundation + +let versionString = "generated and served by swift-gopher/1.0.0" // TODO: Handle automatic versioning + +func buildVersionStringResponse() -> String { + let repeatedString = "i" + String(repeating: "-", count: 80) + "\terror.host\t1\r\n" + let versionResponseString = "i" + String(repeating: " ", count: 80 - versionString.count) + versionString + "\terror.host\t1\r\n" + return "\(repeatedString)\(versionResponseString)" +} \ No newline at end of file diff --git a/Sources/gopherHandler.swift b/Sources/gopherHandler.swift index ffe2ada..e43619d 100644 --- a/Sources/gopherHandler.swift +++ b/Sources/gopherHandler.swift @@ -229,6 +229,9 @@ final class GopherHandler: ChannelInboundHandler { let search_line = "7Search Server\t/search\t\(gopherdata_host)\t\(gopherdata_port)\r\n" gopherResponse.append(search_line) } + + // Append Server Info + gopherResponse.append(buildVersionStringResponse()) return gopherResponse.joined(separator: "") @@ -286,7 +289,7 @@ final class GopherHandler: ChannelInboundHandler { if gopherResponse.count == 0 { gopherResponse.append("iNo results found for the query \(query)\r\n") } - + gopherResponse.append(buildVersionStringResponse()) return gopherResponse.joined(separator: "") } -- cgit v1.2.3