Gemini/GeminiProtocol/GeminiRequest.swift

32 lines
578 B
Swift
Raw Normal View History

2020-07-13 03:09:37 +00:00
//
// GeminiRequest.swift
// Gemini
//
// Created by Shadowfacts on 7/12/20.
//
import Foundation
2020-07-13 22:22:36 +00:00
public struct GeminiRequest {
public let url: URL
2020-07-13 03:09:37 +00:00
2020-07-13 22:22:36 +00:00
public init(url: URL) throws {
2020-07-13 03:09:37 +00:00
if url.absoluteString.count > 1024 {
throw Error.urlTooLong
}
self.url = url
}
var data: Data {
var data = url.absoluteString.data(using: .utf8)!
data.append(contentsOf: [13, 10]) // <CR><LF>
return data
}
}
2020-07-13 22:22:36 +00:00
public extension GeminiRequest {
2020-07-13 03:09:37 +00:00
enum Error: Swift.Error {
case urlTooLong
}
}