Clients - http : Caller

The caller actions for responding to client requests.

Remote Methods

respond Sends the outbound response to the caller.
promise Pushes a promise to the caller.
pushPromisedResponse Sends a promised push response to the caller.
acceptWebSocketUpgrade Sends an upgrade request with custom headers.
cancelWebSocketUpgrade Cancels the handshake.
continue Sends a 100-continue response to the caller.
redirect Sends a redirect response to the user with the specified redirection status code.
ok Sends the outbound response to the caller with the status 200 OK.
created Sends the outbound response to the caller with the status 201 Created.
accepted Sends the outbound response to the caller with the status 202 Accepted.
noContent Sends the outbound response to the caller with the status 204 No Content. If the given response contains a body that will be removed.
 http:ListenerError? err = caller->noContent();
badRequest Sends the outbound response to the caller with the status 400 Bad Request.
 http:ListenerError? err = caller->badRequest();
notFound Sends the outbound response to the caller with the status 404 Not Found.
 http:ListenerError? err = caller->notFound();
internalServerError Sends the outbound response to the caller with the status 500 Internal Server Error.
 http:ListenerError? err = caller->internalServerError();

Methods

Gets the hostname from the remote address.

Fields

  • remoteAddress Remote (default {})
  • The remote address

  • localAddress Local (default {})
  • The local address

  • protocol string
  • The protocol associated with the service endpoint

respond

(ResponseMessage message)

returns ListenerError?

Sends the outbound response to the caller.

Parameters

  • message ResponseMessage (default ())
  • The outbound response or any payload of type string, xml, json, byte[], io:ReadableByteChannel, or mime:Entity[]

  • Return Type

    (ListenerError?)
  • An http:ListenerError if failed to respond or else ()

promise

(PushPromise promise)

returns ListenerError?

Pushes a promise to the caller.

Parameters

  • Return Type

    (ListenerError?)
  • An http:ListenerError in case of failures

pushPromisedResponse

(PushPromise promise, Response response)

returns ListenerError?

Sends a promised push response to the caller.

Parameters

  • response Response
  • The outbound response

  • Return Type

    (ListenerError?)
  • An http:ListenerError in case of failures while responding with the promised response

acceptWebSocketUpgrade

(map headers)

returns WebSocketCaller | WebSocketError

Sends an upgrade request with custom headers.

Parameters

  • headers map
  • A map of custom headers for handshake

cancelWebSocketUpgrade

(int status, string reason)

returns WebSocketError?

Cancels the handshake.

Parameters

  • status int
  • Error Status code for cancelling the upgrade and closing the connection. This error status code need to be 4xx or 5xx else the default status code would be 400.

  • reason string
  • Reason for cancelling the upgrade

  • Return Type

    (WebSocketError?)
  • An error if an error occurs during cancelling the upgrade or nil

continue

()

returns ListenerError?

Sends a 100-continue response to the caller.

  • Return Type

    (ListenerError?)
  • An http:ListenerError if failed to send the 100-continue response or else ()

redirect

(Response response, RedirectCode code, string[] locations)

returns ListenerError?

Sends a redirect response to the user with the specified redirection status code.

Parameters

  • response Response
  • Response to be sent to the caller

  • locations string[]
  • An array of URLs to which the caller can redirect to

  • Return Type

    (ListenerError?)
  • An http:ListenerError if failed to send the redirect response or else ()

ok

(ResponseMessage message)

returns ListenerError?

Sends the outbound response to the caller with the status 200 OK.

Parameters

  • message ResponseMessage (default ())
  • The outbound response or any payload of type string, xml, json, byte[], io:ReadableByteChannel or mime:Entity[]

  • Return Type

    (ListenerError?)
  • An http:ListenerError if failed to respond or else ()

created

(string uri, ResponseMessage message)

returns ListenerError?

Sends the outbound response to the caller with the status 201 Created.

Parameters

  • uri string
  • Represents the most specific URI for the newly created resource

  • message ResponseMessage (default ())
  • The outbound response or any payload of type string, xml, json, byte[], io:ReadableByteChannel or mime:Entity[]. This message is optional.

  • Return Type

    (ListenerError?)
  • An http:ListenerError if failed to respond or else ()

accepted

(ResponseMessage message)

returns ListenerError?

Sends the outbound response to the caller with the status 202 Accepted.

Parameters

  • message ResponseMessage (default ())
  • The outbound response or any payload of type string, xml, json, byte[], io:ReadableByteChannel or mime:Entity[]. This message is optional.

  • Return Type

    (ListenerError?)
  • An http:ListenerError if failed to respond or else ()

noContent

(Response? message)

returns ListenerError?

Sends the outbound response to the caller with the status 204 No Content. If the given response contains a body that will be removed.

 http:ListenerError? err = caller->noContent();

Parameters

  • message Response? (default ())
  • The outbound response, which is optional

  • Return Type

    (ListenerError?)
  • An http:ListenerError if failed to respond or else ()

badRequest

(ResponseMessage message)

returns ListenerError?

Sends the outbound response to the caller with the status 400 Bad Request.

 http:ListenerError? err = caller->badRequest();

Parameters

  • message ResponseMessage (default ())
  • The outbound response or any payload of type string, xml, json, byte[], io:ByteChannel, or mime:Entity[]

  • Return Type

    (ListenerError?)
  • An http:ListenerError if failed to respond or else ()

notFound

(ResponseMessage message)

returns ListenerError?

Sends the outbound response to the caller with the status 404 Not Found.

 http:ListenerError? err = caller->notFound();

Parameters

  • message ResponseMessage (default ())
  • The outbound response or any payload of type string, xml, json, byte[], io:ByteChannel, or mime:Entity[]

  • Return Type

    (ListenerError?)
  • An http:ListenerError if failed to respond or else ()

internalServerError

(ResponseMessage message)

returns ListenerError?

Sends the outbound response to the caller with the status 500 Internal Server Error.

 http:ListenerError? err = caller->internalServerError();

Parameters

  • message ResponseMessage (default ())
  • The outbound response or any payload of type string, xml, json, byte[], io:ByteChannel, or mime:Entity[]

  • Return Type

    (ListenerError?)
  • An http:ListenerError if failed to respond or else ()

getRemoteHostName

()

returns string?

Gets the hostname from the remote address. This method may trigger a DNS reverse lookup if the address was created with a literal IP address.

 string? remoteHost = caller.getRemoteHostName();

  • Return Type

    (string?)
  • The hostname of the address or else () if it is unresolved