Fix redirects not being handled

Closes #1
This commit is contained in:
Shadowfacts 2020-12-20 22:57:29 -05:00
parent d2f3ddf864
commit a8a8ea10a1
2 changed files with 12 additions and 10 deletions

View File

@ -154,11 +154,11 @@ class BrowserWebViewController: UIViewController {
}
case let .success(response):
if response.status.isRedirect {
DispatchQueue.main.async {
print("Trying to redirect to: '\(response.meta)'")
if let redirect = URL(string: response.meta) {
self.navigator.changeURL(redirect)
} else {
DispatchQueue.main.async {
self.showError(message: "Invalid redirect URL: '\(response.meta)'")
}
}

View File

@ -88,12 +88,14 @@ class GeminiProtocol: NWProtocolFramerImplementation {
let header = GeminiResponseHeader(status: statusCode, meta: meta)
let message = NWProtocolFramer.Message(geminiResponseHeader: header)
while true {
if !framer.deliverInputNoCopy(length: .max, message: message, isComplete: true) {
// What does the return value of deliverInputNoCopy mean, you ask? Why, I have no idea
// It always returns true for a length of zero, so following the sample code and looping
// infinitely until it returns false causes an infinite loop.
// Additionally, calling deliverInput with an empty Data() causes an error inside Network.framework.
// So, we just ignore the result since it doesn't seem to cause any problems ¯\_()_/¯
_ = framer.deliverInputNoCopy(length: statusCode.isSuccess ? .max : 0, message: message, isComplete: true)
return 0
}
}
}
func handleOutput(framer: NWProtocolFramer.Instance, message: NWProtocolFramer.Message, messageLength: Int, isComplete: Bool) {
guard let request = message.geminiRequest else { fatalError("GeminiProtocol can't send message that doesn't have an associated GeminiRequest") }