url.bend checks
raw source on the hub · import 0x5e4e2a9db839a0214ace6923b04b685b/url.bend as Url
ezhttp/url: a URL taken apart far enough for an HTTP request. Scheme, host, port, and an origin-form path (absolute-path, optional query). Userinfo is stripped. The fragment is not part of the request-target.
Shape follows RFC 3986 URI generic syntax: scheme ":" hier-part, with hier-part as "//" authority path-abempty ["?" query] ["#" fragment] (RFC 3986 §3, §3.1, §3.2, §3.4, §3.5).
1 import
import Base
Types
type Loc source · line 11 · raw
Data
a url that came apart, or the reason it would not
Bad@why:String -> Loc
Loc@scheme:String -> @host:String -> @port:U32 -> @path:String -> Loc
Definitions
def dflt source · line 17 · raw
@scheme:String -> U32
the port a scheme implies when the authority names none (RFC 3986 §3.2.3; HTTPS default 443 is the well-known TLS port, not re-specified here)
def port.num source · line 21 · raw
@m:Maybe<&2, U32> -> @scheme:String -> U32
a port that parsed, or the scheme's own when the digits were not digits
def port.tail source · line 29 · raw
@ps:List<&2, String> -> @scheme:String -> U32
the port named after the colon, when there is anything after it
def port.of source · line 37 · raw
@ps:List<&2, String> -> @scheme:String -> U32
the port an authority asked for, or the one its scheme implies
def host.of source · line 45 · raw
@ps:List<&2, String> -> String
the host an authority named: everything before the colon
def path.of source · line 55 · raw
@ps:List<&2, String> -> String
the path a url asked for, "/" when it named none. The leading slash ended the authority, so it is put back. Absolute-path form matches RFC 3986 path-absolute / path-abempty used with an authority (§3.3).
def auth.last.of source · line 63 · raw
@m:Maybe<&2, String> -> String
the last piece, or "" when the split was empty
def auth.last source · line 71 · raw
@ps:List<&2, String> -> String
the last @-separated piece (the hostport). Earlier pieces are userinfo.
def auth.host source · line 75 · raw
@authority:String -> String
userinfo is stripped: user:pass@host yields host (RFC 3986 §3.2.1)
def frag.drop.of source · line 79 · raw
@ps:List<&2, String> -> String
the first piece of a # split
def frag.drop source · line 87 · raw
@s:String -> String
everything before # (RFC 3986 §3.5). The fragment is not a request-target.
def query.hier source · line 91 · raw
@ps:List<&2, String> -> String
the hier-part before ?
def query.text source · line 99 · raw
@ps:List<&2, String> -> String
the query after the first ?, with later ? kept (RFC 3986 §3.4)
def path.target.of source · line 107 · raw
@path:String -> @query:String -> @empty:Bool -> String
origin-form path: absolute-path, then ? query when the query is present
def path.target source · line 115 · raw
@path:String -> @+query:String -> String
absolute-path ["?" query] (RFC 3986 §3.4, RFC 9112 §3.2.1)
def parse.auth source · line 119 · raw
@+scheme:String -> @+au:List<&2, String> -> @path:String -> Loc
a url whose authority is now split on its colon
def parse.parts source · line 123 · raw
@+scheme:String -> @+ps:List<&2, String> -> @query:String -> Loc
authority (userinfo stripped) and origin-form path
def parse.q source · line 128 · raw
@+scheme:String -> @+ps:List<&2, String> -> Loc
hier-part split on ?
def parse.hier source · line 132 · raw
@+scheme:String -> @+rest:String -> Loc
fragment stripped, then query split from the hier-part
def parse.body source · line 136 · raw
@+scheme:String -> @+rest:String -> @slashes:Bool -> Loc
what follows the scheme, once it is known whether it opens with //
def parse.rest source · line 144 · raw
@+scheme:String -> @+rest:String -> Loc
what follows the scheme, judged on its //
def parse.scheme source · line 149 · raw
@ps:List<&2, String> -> Loc
a url split on its colons: the first piece is the scheme, and a colon in the path survives because the rest is joined back up
def parse source · line 157 · raw
@url:String -> Loc
a url in pieces, or the reason it is not one
def show source · line 161 · raw
@l:Loc -> String
a parsed url on one line, for a test to read