Skip to content

RedirectFollower

[Source]

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()
class ref RedirectFollower is
  HTTPClientLifecycleEventReceiver ref

Implements


Constructors

create

[Source]

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

Returns


none

[Source]

Placeholder for the actor field default, replaced in the actor constructor body where this is available as ref.

new ref none()
: RedirectFollower ref^

Returns


Public Functions

connection

[Source]

The current underlying connection, which changes after a cross-origin redirect.

fun ref connection()
: HTTPClientConnection ref

Returns


send_request

[Source]

Send a request and remember it for redirect decisions.

fun ref send_request(
  request: HTTPRequest val)
: SendRequestResult

Parameters

Returns


on_connected

[Source]

fun ref on_connected()
: None val

Returns


on_response

[Source]

fun ref on_response(
  response: Response val)
: None val

Parameters

Returns


on_body_chunk

[Source]

fun ref on_body_chunk(
  data: Array[U8 val] val)
: None val

Parameters

Returns


on_response_complete

[Source]

fun ref on_response_complete()
: None val

Returns


on_closed

[Source]

fun ref on_closed()
: None val

Returns


on_connection_failure

[Source]

fun ref on_connection_failure(
  reason: ConnectionFailureReason)
: None val

Parameters

Returns


on_parse_error

[Source]

fun ref on_parse_error(
  err: ParseError)
: None val

Parameters

Returns


on_throttled

[Source]

fun ref on_throttled()
: None val

Returns


on_unthrottled

[Source]

fun ref on_unthrottled()
: None val

Returns


on_timer

[Source]

fun ref on_timer(
  token: TimerToken val)
: None val

Parameters

Returns


on_timer_failure

[Source]

fun ref on_timer_failure()
: None val

Returns