Skip to content

HTTPServerActor

[Source]

Trait for actors that serve HTTP connections.

Extends TCPConnectionActor (for lori ASIO plumbing) and HTTPServerLifecycleEventReceiver (for HTTP-level callbacks). The actor stores an HTTPServer as a field and implements _http_connection() to return it. All other required methods have default implementations that delegate to the protocol.

Minimal implementation:

actor MyServer is HTTPServerActor
  var _http: HTTPServer = HTTPServer.none()

  new create(auth: lori.TCPServerAuth, fd: U32,
    config: ServerConfig)
  =>
    _http = HTTPServer(auth, fd, this, config)

  fun ref _http_connection(): HTTPServer => _http

  fun ref on_request_complete(request': Request val,
    responder: Responder)
  =>
    // build and send response using request' and responder

For HTTPS, use HTTPServer.ssl(auth, ssl_ctx, fd, this, config) instead of HTTPServer(auth, fd, this, config).

The none() default ensures all fields are initialized before the constructor body runs, so this is ref when passed to HTTPServer.create() or HTTPServer.ssl().

trait tag HTTPServerActor is
  TCPConnectionActor tag,
  HTTPServerLifecycleEventReceiver ref

Implements


Public Behaviours

dispose

be dispose()

Public Functions

on_request

fun ref on_request(
  request': Request val,
  responder: Responder ref)
: None val

Parameters

Returns


on_body_chunk

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

Parameters

Returns


on_request_complete

fun ref on_request_complete(
  request': Request val,
  responder: Responder ref)
: None val

Parameters

Returns


on_closed

fun ref on_closed()
: None val

Returns


on_throttled

fun ref on_throttled()
: None val

Returns


on_chunk_sent

fun ref on_chunk_sent(
  token: ChunkSendToken val)
: None val

Parameters

Returns


on_unthrottled

fun ref on_unthrottled()
: None val

Returns