RedirectFollower¶
Follows HTTP redirects transparently by sitting in the callback path between an HTTPClientConnection and the user's receiver.
The connection delivers callbacks to the follower; the follower handles redirects internally and forwards only non-redirect events to the user. The user's callback code sees only the final non-redirect response.
Same-origin redirects reuse the existing TCP connection. Cross-origin redirects use a RedirectConnectionFactory to create a new one.
Use none() as the field default so that this is ref in the actor
constructor body, then replace with create():
actor MyClient is (HTTPClientConnectionActor & RedirectFollowerNotify)
var _http: RedirectFollower = RedirectFollower.none()
new create(auth: lori.TCPConnectAuth, ssl_ctx: ssl_net.SSLContext val,
host: String, port: String)
=>
let config = ClientConnectionConfig
let conn = HTTPClientConnection.ssl(
auth, ssl_ctx, host, port, this, config)
let factory =
{ref(target: uri.URI val)
(auth, ssl_ctx, config, client = this)
: HTTPClientConnection
=>
let o = Origin.from_uri(target)
if o.host.size() == 0 then
return HTTPClientConnection.none()
end
if o.secure then
HTTPClientConnection.ssl(
auth, ssl_ctx, o.host, o.port, client, config)
else
HTTPClientConnection(
auth, o.host, o.port, client, config)
end
}
_http = RedirectFollower(conn, this, factory, 5,
Origin(true, host, port))
fun ref _http_client_connection(): HTTPClientConnection =>
_http.connection()
Implements¶
Constructors¶
create¶
Create a redirect follower that wraps conn.
Inserts itself into the connection's callback path so redirect responses
are handled internally. Non-redirect responses forward to receiver.
Cross-origin redirects use factory to create a new connection.
max_redirects is how many hops to follow before refusing with
TooManyRedirects. origin is the scheme, host, and port of the initial
connection — used to detect cross-origin hops.
new ref create(
conn: HTTPClientConnection ref,
receiver: RedirectFollowerNotify ref,
factory: RedirectConnectionFactory ref,
max_redirects: USize val,
origin: Origin val)
: RedirectFollower ref^
Parameters¶
- conn: HTTPClientConnection ref
- receiver: RedirectFollowerNotify ref
- factory: RedirectConnectionFactory ref
- max_redirects: USize val
- origin: Origin val
Returns¶
- RedirectFollower ref^
none¶
Placeholder for the actor field default, replaced in the actor
constructor body where this is available as ref.
Returns¶
- RedirectFollower ref^
Public Functions¶
connection¶
The current underlying connection, which changes after a cross-origin redirect.
Returns¶
send_request¶
Send a request and remember it for redirect decisions.
Parameters¶
- request: HTTPRequest val
Returns¶
on_connected¶
Returns¶
- None val
on_response¶
Parameters¶
- response: Response val
Returns¶
- None val
on_body_chunk¶
Parameters¶
Returns¶
- None val
on_response_complete¶
Returns¶
- None val
on_closed¶
Returns¶
- None val
on_connection_failure¶
Parameters¶
- reason: ConnectionFailureReason
Returns¶
- None val
on_parse_error¶
Parameters¶
- err: ParseError
Returns¶
- None val
on_throttled¶
Returns¶
- None val
on_unthrottled¶
Returns¶
- None val
on_timer¶
Parameters¶
- token: TimerToken val
Returns¶
- None val
on_timer_failure¶
Returns¶
- None val