src/redirect.bend checks
raw source on the hub · import ezhttp@0.24.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. What is guaranteed is under laws/, such as laws/RedirectsFollowLocation.bend.
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 20 · raw
Data
what the client does after a response
StopHop
Go@url:String -> Hop
type Ref source · line 112 · 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 150 · 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 25 · raw
Nat
the most hops the client follows (httpx's default is 20)
def redirect.is source · line 29 · raw
@+status:U32 -> Bool
whether a status asks the client to go elsewhere (RFC 9110 §15.4.2-9)
def redirect.absolute source · line 35 · raw
@+loc:String -> Bool
whether a Location is an absolute http or https URL
def redirect.pop source · line 42 · 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 50 · 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 58 · 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 67 · 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 78 · 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 88 · 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 94 · raw
@t:List<&2, String> -> @s:String -> List<&2, String>
every segment but the last, after s
def redirect.init source · line 102 · raw
@ss:List<&2, String> -> List<&2, String>
every segment but the last
def redirect.split.of source · line 116 · raw
@c:0x8673751971e75cc0377d73b25bc4d890/src/http.Cut -> @loc:String -> Ref
a Location divided at its first ?
def redirect.split source · line 124 · raw
@+loc:String -> Ref
a Location's path and query, its fragment dropped
def redirect.abs.of source · line 129 · raw
@r:Ref -> String
an absolute-path reference's path, dot segments removed, then its query
def redirect.rel.of source · line 136 · 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 144 · raw
@path:String -> String
a path without its query
def redirect.schemed.end source · line 158 · raw
@+c:Char -> Bool
a character that ends a reference's first segment
def redirect.schemed.colon source · line 162 · 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 170 · raw
@stop:Bool -> @colon:Bool -> @rest:(@_:Unit -> Bool) -> Bool
one character of the scheme search
def redirect.schemed source · line 178 · raw
@s:String -> Bool
whether a reference names a scheme: a : before its first /, ? or #
def redirect.stays source · line 187 · raw
@+loc:String -> Bool
a Location the client does not follow: empty, a fragment, another scheme
def redirect.sort.rel source · line 192 · raw
@query:Bool -> Sort
a relative reference: a query, or a relative path
def redirect.sort.stay source · line 201 · 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 209 · 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 217 · raw
@net:Bool -> @abs:Bool -> @stay:Bool -> @query:Bool -> Sort
the sort, from what the Location starts with
def redirect.sort source · line 225 · raw
@+loc:String -> Sort
what sort of reference a Location is
def redirect.against source · line 232 · 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 250 · raw
@l:0x8673751971e75cc0377d73b25bc4d890/src/url.Loc -> @+loc:String -> Maybe<&2, String>
a Location against the current URL, once it is parsed
def redirect.target.of source · line 258 · 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 268 · 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 272 · raw
@m:Maybe<&2, String> -> Hop
a resolved target as a hop
def redirect.on source · line 280 · raw
@url:String -> @+loc:String -> @moved:Bool -> Hop
a response once it is known whether its status redirects
def redirect.next source · line 289 · 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 297 · raw
@left:Nat -> @url:String -> @+status:U32 -> @headers:List<&2, 0x8673751971e75cc0377d73b25bc4d890/src/http.Header> -> Hop
the next hop after a response's status and headers
def redirect.follows source · line 303 · 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)