src/redirect.bend checks
raw source on the hub · import emerging-ezhttp@0.13.0.0/src/redirect.bend as Redirect
ezhttp/src/redirect: where a GET goes after a response, pure. The client's follow loop (client.bend) sends the next GET where this module says and decides nothing itself. SPEC.md HTTP-REDIR lists what is guaranteed.
Policy: the client follows redirects for GET only, so every hop is a GET.
301, 302, 303, 307 and 308 with a Location are followed; any other status
stops. A Location is resolved against the current URL as RFC 3986 §5.2
resolves a reference: an absolute http or https URL is taken as it is, a
network-path (//host/...) takes the current scheme, an absolute path the
current origin, a query the current path, and a relative path is merged
with the current path's directory; dot segments are removed. An empty
Location, a fragment, or another scheme stops. The client gives a chain at
most redirect.max() hops.
3 imports
import Base import ./url.bend as Url import ./http.bend as Http
Types
type Hop source · line 19 · raw
Data
what the client does after a response
StopHop
Go@url:String -> Hop
type Ref source · line 111 · raw
Data
a Location's path and its query (with its ?, "" when it has none)
Ref@path:String -> @query:String -> Ref
type Sort source · line 149 · raw
Data
what sort of reference a Location that is not an absolute URL is
NetSort
AbsSort
StaySort
QuerySort
RelSort
Definitions
def redirect.max source · line 24 · raw
Nat
the most hops the client follows (httpx's default is 20)
def redirect.is source · line 28 · raw
@+status:U32 -> Bool
whether a status asks the client to go elsewhere (RFC 9110 §15.4.2-9)
def redirect.absolute source · line 34 · raw
@+loc:String -> Bool
whether a Location is an absolute http or https URL
def redirect.pop source · line 41 · raw
@out:List<&2, String> -> List<&2, String>
the segments kept so far, last first, with the last one dropped
def redirect.dots.end source · line 49 · raw
@last:Bool -> @out:List<&2, String> -> List<&2, String>
a path that ends in . or .. keeps its trailing /: an empty last segment
def redirect.dots.up source · line 57 · raw
@up:Bool -> @last:Bool -> @s:String -> @out:List<&2, String> -> @rest:(@_:List<&2, String> -> List<&2, String>) -> List<&2, String>
a segment that is not .: .. drops the last kept, any other is kept
def redirect.dots.one source · line 66 · raw
@dot:Bool -> @up:Bool -> @last:Bool -> @s:String -> @out:List<&2, String> -> @rest:(@_:List<&2, String> -> List<&2, String>) -> List<&2, String>
one segment: . is dropped, .. drops the last kept, any other is kept
def redirect.dots source · line 77 · raw
@ss:List<&2, String> -> @out:List<&2, String> -> List<&2, String>
a path's segments with dot segments removed, out holding those kept so
far, last first
def redirect.clean source · line 87 · raw
@ss:List<&2, String> -> String
the segments after a path's leading /, dot segments removed, as a path
def redirect.init.of source · line 93 · raw
@t:List<&2, String> -> @s:String -> List<&2, String>
every segment but the last, after s
def redirect.init source · line 101 · raw
@ss:List<&2, String> -> List<&2, String>
every segment but the last
def redirect.split.of source · line 115 · raw
@c:0xd3f9c1f02240edb63fd4a109ceb8fa74/src/http.Cut -> @loc:String -> Ref
a Location divided at its first ?
def redirect.split source · line 123 · raw
@+loc:String -> Ref
a Location's path and query, its fragment dropped
def redirect.abs.of source · line 128 · raw
@r:Ref -> String
an absolute-path reference's path, dot segments removed, then its query
def redirect.rel.of source · line 135 · raw
@base:String -> @r:Ref -> String
a relative-path reference merged with the current path, dot segments removed, then its query
def redirect.base source · line 143 · raw
@path:String -> String
a path without its query
def redirect.schemed.end source · line 157 · raw
@+c:Char -> Bool
a character that ends a reference's first segment
def redirect.schemed.colon source · line 161 · raw
@colon:Bool -> @rest:(@_:Unit -> Bool) -> Bool
a character that does not end the first segment: a : names a scheme
def redirect.schemed.at source · line 169 · raw
@stop:Bool -> @colon:Bool -> @rest:(@_:Unit -> Bool) -> Bool
one character of the scheme search
def redirect.schemed source · line 177 · raw
@s:String -> Bool
whether a reference names a scheme: a : before its first /, ? or #
def redirect.stays source · line 186 · raw
@+loc:String -> Bool
a Location the client does not follow: empty, a fragment, another scheme
def redirect.sort.rel source · line 191 · raw
@query:Bool -> Sort
a relative reference: a query, or a relative path
def redirect.sort.stay source · line 200 · raw
@stay:Bool -> @query:Bool -> Sort
a reference that is not a path from the root: one the client stays on, or a relative one
def redirect.sort.abs source · line 208 · raw
@abs:Bool -> @stay:Bool -> @query:Bool -> Sort
a reference that is not a network path: an absolute path, or another
def redirect.sort.of source · line 216 · raw
@net:Bool -> @abs:Bool -> @stay:Bool -> @query:Bool -> Sort
the sort, from what the Location starts with
def redirect.sort source · line 224 · raw
@+loc:String -> Sort
what sort of reference a Location is
def redirect.against source · line 231 · raw
@scheme:String -> @host:String -> @port:U32 -> @path:String -> @+loc:String -> @k:Sort -> Maybe<&2, String>
a Location of a known sort against the current URL's parts
def redirect.at source · line 249 · raw
@l:0xd3f9c1f02240edb63fd4a109ceb8fa74/src/url.Loc -> @+loc:String -> Maybe<&2, String>
a Location against the current URL, once it is parsed
def redirect.target.of source · line 257 · raw
@url:String -> @+loc:String -> @absolute:Bool -> Maybe<&2, String>
a Location once it is known whether it is an absolute URL
def redirect.target source · line 267 · raw
@url:String -> @+loc:String -> Maybe<&2, String>
where a Location sends a client that is at url, or None when it is not
one the client follows
def redirect.hop source · line 271 · raw
@m:Maybe<&2, String> -> Hop
a resolved target as a hop
def redirect.on source · line 279 · raw
@url:String -> @+loc:String -> @moved:Bool -> Hop
a response once it is known whether its status redirects
def redirect.next source · line 288 · raw
@left:Nat -> @url:String -> @+status:U32 -> @+loc:String -> Hop
the next hop from url, after a response with status and Location loc
("" when it had none), with left hops still allowed
def redirect.plan source · line 296 · raw
@left:Nat -> @url:String -> @+status:U32 -> @headers:List<&2, 0xd3f9c1f02240edb63fd4a109ceb8fa74/src/http.Header> -> Hop
the next hop after a response's status and headers
def redirect.follows source · line 302 · raw
@+method:String -> @follow:Bool -> Bool
whether a request with this method follows redirects when asked to: only a GET does (method names are case-sensitive, RFC 9110 §9.1)