~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/old-fella

Old people's social media app

0
1
main
25 lines · 1.0 KB Raw History
import Observation
import XCTest

@testable import OldFella

final class ImageTestProtocol: URLProtocol {
    override static func canInit(with request: URLRequest) -> Bool { true }
    override static func canonicalRequest(for request: URLRequest) -> URLRequest { request }

    override func startLoading() {
        guard let url = request.url, url.path != "/wait" else { return }
        let response = HTTPURLResponse(
            url: url, statusCode: url.path == "/error" ? 503 : 200, httpVersion: "HTTP/1.1", headerFields: nil)!
        client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
        if url.path == "/gif" {
            client?.urlProtocol(self, didLoad: Data("GIF89a".utf8))
            client?.urlProtocol(self, didLoad: Data(repeating: 0, count: GIFDownload.byteLimit))
        } else {
            client?.urlProtocol(self, didLoad: Data(repeating: 0, count: 1024))
        }
        client?.urlProtocolDidFinishLoading(self)
    }

    override func stopLoading() {}
}