From 1c8d815476a5a5908a0570976a79e36e95e72a05 Mon Sep 17 00:00:00 2001 From: nixo Date: Fri, 30 Oct 2020 18:50:21 +0100 Subject: [PATCH] types: simplify return --- src/types.jl | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/types.jl b/src/types.jl index ddff82c..d9559a8 100644 --- a/src/types.jl +++ b/src/types.jl @@ -59,19 +59,18 @@ function Request(data::String) """x s = endswith(data, "\r\n") ? data[1:end-2] : data m = match(reg, s) - if isnothing(m) - Request(nothing, nothing, nothing, nothing, nothing, false, data) - else - Request(something(m["protocol"], "gemini"), - m["host"], parse(Int, something(m["port"], "1965")), - # normpath prevents "./path" being different from "path", and - # resolves also "../". The only problem is that "./" is - # transformed to ".", so we filter it. the raw rapresentation - # is still there, if needed - isnothing(m["path"]) ? nothing : filter!(!=("."), split(normpath(m["path"]), "/")), - isnothing(m["query"]) ? nothing : unescape(m["query"]), - true, data) - end + isnothing(m) && + return Request(nothing, nothing, nothing, nothing, nothing, false, data) + + Request(something(m["protocol"], "gemini"), + m["host"], parse(Int, something(m["port"], "1965")), + # normpath prevents "./path" being different from "path", and + # resolves also "../". The only problem is that "./" is + # transformed to ".", so we filter it. the raw rapresentation + # is still there, if needed + isnothing(m["path"]) ? nothing : filter!(!=("."), split(normpath(m["path"]), "/")), + isnothing(m["query"]) ? nothing : unescape(m["query"]), + true, data) end function Request(protocol, host, port, path, query)