fix //url parsing

This commit is contained in:
nixo 2020-10-30 22:27:59 +01:00
parent 1c8d815476
commit 9bfe896ead
1 changed files with 8 additions and 5 deletions

View File

@ -49,13 +49,16 @@ struct Request
spaces encoded with: %20"
end
# TODO: https://tools.ietf.org/html/rfc3986#section-5.2.4
# Read specs and fix implementation!
function Request(data::String)
reg = r"""
((?P<protocol>[^:/]+)://)? # optional protocol
(?P<host>[^:/]+)? # required host (but can be omitted in parsing like /path/ or ./path)
(:(?P<port>[0-9]{1,5}))? # optional port (will match impossible 65000+ ports)
(/(?P<path>[^\?]*))? # optional path
(\?(?P<query>.+))? # optional query
((?P<protocol>[^:/]+))? # optional protocol
((:)?//)? # optional separator
(?P<host>[^:/]+)? # required host (but can be omitted in parsing like /path/ or ./path)
(:(?P<port>[0-9]{1,5}))? # optional port (will match impossible 65000+ ports)
(/(?P<path>[^\?]*))? # optional path
(\?(?P<query>.+))? # optional query
"""x
s = endswith(data, "\r\n") ? data[1:end-2] : data
m = match(reg, s)