From 73baa81e305cb0b769317ee94869f53601037951 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 1 Feb 2025 22:58:47 +0200 Subject: [PATCH] create separated `redirection_base` function --- .../window/tab/item/client/driver/gemini.rs | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/app/browser/window/tab/item/client/driver/gemini.rs b/src/app/browser/window/tab/item/client/driver/gemini.rs index 1d9434f4..36aa1d35 100644 --- a/src/app/browser/window/tab/item/client/driver/gemini.rs +++ b/src/app/browser/window/tab/item/client/driver/gemini.rs @@ -342,28 +342,9 @@ fn handle( // https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection // https://geminiprotocol.net/docs/protocol-specification.gmi#status-31-permanent-redirection Status::PermanentRedirect | Status::Redirect => { - // Build safe base `Uri` from the current request as the donor - // to resolve relative target `String` by Gemini specification - let base = Uri::build( - UriFlags::NONE, - uri.scheme().as_str(), - None, // unexpected - uri.host().as_deref(), - uri.port(), - uri.path().as_str(), - // > If a server sends a redirection in response to a request with a query string, - // > the client MUST NOT apply the query string to the new location - // > https://geminiprotocol.net/docs/protocol-specification.gmi#redirection - None, - // > A server SHOULD NOT include fragments in redirections, - // > but if one is given, and a client already has a fragment it could apply (from the original URI), - // > it is up to the client which fragment to apply. - // > https://geminiprotocol.net/docs/protocol-specification.gmi#redirection - None // @TODO - ); // Expected target URL in response meta match response.meta.data { - Some(data) => match base.parse_relative(data.as_str(), UriFlags::NONE) { + Some(data) => match redirection_base(uri).parse_relative(data.as_str(), UriFlags::NONE) { Ok(target) => { // Increase client redirection counter let total = redirects.take() + 1; @@ -473,3 +454,26 @@ fn uri_to_title(uri: &Uri) -> GString { path } } + +// Build safe base `Uri` from the current request as the donor +// to resolve relative target `String` by Gemini specification +fn redirection_base(request: Uri) -> Uri { + Uri::build( + UriFlags::NONE, + request.scheme().as_str(), + None, // unexpected + request.host().as_deref(), + request.port(), + request.path().as_str(), + // > If a server sends a redirection in response to a request with a query string, + // > the client MUST NOT apply the query string to the new location + // > https://geminiprotocol.net/docs/protocol-specification.gmi#redirection + None, + // > A server SHOULD NOT include fragments in redirections, + // > but if one is given, and a client already has a fragment it could apply (from the original URI), + // > it is up to the client which fragment to apply. + // > https://geminiprotocol.net/docs/protocol-specification.gmi#redirection + // @TODO + None, + ) +}