~garritfra/taurus

taurus: Infer gemini:// scheme in the URL v2 SUPERSEDED

Alexey Yerin: 1
 Infer gemini:// scheme in the URL

 2 files changed, 30 insertions(+), 13 deletions(-)
#340514 ci.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~garritfra/taurus/patches/14953/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH taurus v2] Infer gemini:// scheme in the URL Export this patch

Signed-off-by: Alexey Yerin <yerinalexey98fd@gmail.com>
---
Moved logic to GeminiRequest, rewrote some tests and removed
invalid_request_url test because the tested URL was actually valid.

 src/gemini.rs | 39 ++++++++++++++++++++++++++-------------
 src/main.rs   |  4 ++++
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/gemini.rs b/src/gemini.rs
index 9963012..e0853f8 100644
--- a/src/gemini.rs
+++ b/src/gemini.rs
@@ -27,6 +27,16 @@ impl FromStr for GeminiRequest {
    type Err = TaurusError;

    fn from_str(s: &str) -> TaurusResult<Self> {
        let mut s = s.to_string();

        // Implicitly add gemini:// scheme
        if s.starts_with("//") {
            s = format!("gemini:{}", s);
        }
        if !s.starts_with("gemini://") {
            s = format!("gemini://{}", s);
        }

        // Extract and parse the url from the request.
        let raw = s
            .trim_end_matches(0x0 as char)
@@ -88,32 +98,35 @@ impl GeminiResponse {
mod tests {
    use super::*;

    #[test]
    fn parse_request() {
        let raw = "gemini://example.space\r\n";

    fn check_request(raw: &str, expected_url: &str) {
        let req = GeminiRequest::parse(raw).unwrap();

        assert_eq!(
            req,
            GeminiRequest {
                url: Url::parse("gemini://example.space").unwrap()
                url: Url::parse(expected_url).unwrap()
            }
        );
    }

    #[test]
    fn parse_malformed_request() {
        let raw = "gemini://example.space";
    fn parse_request() {
        check_request("gemini://example.space\r\n", "gemini://example.space");
    }

        match GeminiRequest::parse(raw) {
            Err(TaurusError::InvalidRequest(_)) => {}
            x => panic!("expected TaurusError::InvalidRequest, got: {:?}", x),
        }
    #[test]
    fn parse_without_scheme() {
        check_request("example.space\r\n", "gemini://example.space");
    }

    #[test]
    fn parse_invalid_request_url() {
        let raw = "foobar@example.com\r\n";
    fn parse_without_scheme_double_slash() {
        check_request("//example.space\r\n", "gemini://example.space");
    }

    #[test]
    fn parse_malformed_request() {
        let raw = "gemini://example.space";

        match GeminiRequest::parse(raw) {
            Err(TaurusError::InvalidRequest(_)) => {}
diff --git a/src/main.rs b/src/main.rs
index 86d899b..ed34ed8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -135,6 +135,10 @@ fn handle_client(mut stream: TlsStream<TcpStream>, static_root: &str) -> TaurusR
        .map_err(TaurusError::StreamReadFailed)?;

    let mut raw_request = String::from_utf8_lossy(&buffer[..]).into_owned();

    if raw_request.starts_with("//") {
        raw_request = format!("gemini:{}", raw_request);
    }
    if !raw_request.starts_with("gemini://") {
        raw_request = format!("gemini://{}", raw_request);
    }
-- 
2.29.2
builds.sr.ht
taurus/patches/ci.yml: SUCCESS in 1m45s

[Infer gemini:// scheme in the URL][0] v2 from [Alexey Yerin][1]

[0]: https://lists.sr.ht/~garritfra/taurus/patches/14953
[1]: mailto:yerinalexey98fd@gmail.com

✓ #340514 SUCCESS taurus/patches/ci.yml https://builds.sr.ht/~garritfra/job/340514