GRPC.Server.Adapters.Cowboy.Handler (gRPC v0.11.5)

View Source

A cowboy handler accepting all requests and calls corresponding functions defined by users.

Summary

Functions

Return all bindings of a given request.

Return the client TLS certificate. :undefined is returned if no certificate was specified when establishing the connection.

Return all request headers.

Return the peer IP address and port number

Return the query string for the request URI.

Callback implementation for :cowboy_loop.info/3.

This function is meant to be called whenever a new request arrives to an existing connection. This handler works mainly with two linked processes. One of them is the process started by cowboy which internally we'll refer to it as stream_pid, this process is responsible to interface the interactions with the open socket. The second process is the one we start in this function, we'll refer to it as server_rpc_pid, which is the point where we call the functions implemented by users (aka the modules who use the GRPC.Server macro)

Synchronously reads a chunk of body content of a given request. Raise in case of a timeout.

Synchronously reads the whole body content of a given request. Raise in case of a timeout.

Asynchronously set the compressor algorithm to be used for compress the responses. This checks if the grpc-accept-encoding header is present on the original request, otherwise no compression is applied.

Asynchronously set the headers for a given request. This function does not send any data back to the client. It simply appends the headers to be used in the response.

Asynchronously set the trailer headers for a given request. This function does not send any data back to the client. It simply appends the trailer headers to be used in the response.

Asynchronously send back to client a chunk of data, when http_transcode? is true, the data is sent back as it's, with no transformation of protobuf binaries to http2 data frames.

Asynchronously send back to the client the http status and the headers for a given request.

Asynchronously stream the given trailers of request back to client.

Types

exception_log_filter()

@type exception_log_filter() :: {module(), atom()} | nil

headers()

@type headers() :: %{required(binary()) => binary()}

init_result()

@type init_result() ::
  {:cowboy_loop, :cowboy_req.req(), stream_state()}
  | {:ok, :cowboy_req.req(), init_state()}

init_state()

@type init_state() ::
  {endpoint :: atom(), server :: {name :: String.t(), module()},
   route :: String.t(), opts :: keyword()}

is_fin()

@type is_fin() :: :fin | :nofin

pending_reader()

@type pending_reader() ::
  {cowboy_read_ref :: reference(), server_rpc_pid :: pid(),
   server_rpc_reader_reference :: reference()}

stream_body_opts()

@type stream_body_opts() :: {:code, module()} | {:compress, boolean()}

stream_state()

@type stream_state() :: %{
  pid: server_rpc_pid :: pid(),
  handling_timer: timeout_timer_ref :: reference(),
  pending_reader: nil | pending_reader(),
  access_mode: GRPC.Server.Stream.access_mode(),
  exception_log_filter: exception_log_filter()
}

Functions

call_rpc(server, path, stream)

exit_handler(pid, reason)

get_bindings(pid)

@spec get_bindings(stream_pid :: pid()) :: :cowboy_router.bindings()

Return all bindings of a given request.

get_cert(pid)

@spec get_cert(stream_pid :: pid()) :: binary() | :undefined

Return the client TLS certificate. :undefined is returned if no certificate was specified when establishing the connection.

get_headers(pid)

@spec get_headers(stream_pid :: pid()) :: :cowboy.http_headers()

Return all request headers.

get_peer(pid)

@spec get_peer(stream_pid :: pid()) :: {:inet.ip_address(), :inet.port_number()}

Return the peer IP address and port number

get_qs(pid)

@spec get_qs(stream_pid :: pid()) :: binary()

Return the query string for the request URI.

info(arg, req, state)

Callback implementation for :cowboy_loop.info/3.

init(req, state)

@spec init(:cowboy_req.req(), state :: init_state()) :: init_result()

This function is meant to be called whenever a new request arrives to an existing connection. This handler works mainly with two linked processes. One of them is the process started by cowboy which internally we'll refer to it as stream_pid, this process is responsible to interface the interactions with the open socket. The second process is the one we start in this function, we'll refer to it as server_rpc_pid, which is the point where we call the functions implemented by users (aka the modules who use the GRPC.Server macro)

read_body(pid)

@spec read_body(stream_pid :: pid()) :: binary()

Synchronously reads a chunk of body content of a given request. Raise in case of a timeout.

read_full_body(pid)

@spec read_full_body(stream_pid :: pid()) :: binary()

Synchronously reads the whole body content of a given request. Raise in case of a timeout.

set_compressor(pid, compressor)

@spec set_compressor(stream_pid :: pid(), compressor :: module()) :: :ok

Asynchronously set the compressor algorithm to be used for compress the responses. This checks if the grpc-accept-encoding header is present on the original request, otherwise no compression is applied.

set_resp_headers(pid, headers)

@spec set_resp_headers(stream_pid :: pid(), headers :: headers()) :: :ok

Asynchronously set the headers for a given request. This function does not send any data back to the client. It simply appends the headers to be used in the response.

set_resp_trailers(pid, trailers)

@spec set_resp_trailers(stream_pid :: pid(), trailers :: headers()) :: :ok

Asynchronously set the trailer headers for a given request. This function does not send any data back to the client. It simply appends the trailer headers to be used in the response.

stream_body(pid, data, opts, is_fin, http_transcode? \\ false)

@spec stream_body(
  stream_pid :: pid(),
  data :: iodata(),
  opts :: [stream_body_opts()],
  is_fin(),
  http_transcode? :: boolean()
) :: :ok

Asynchronously send back to client a chunk of data, when http_transcode? is true, the data is sent back as it's, with no transformation of protobuf binaries to http2 data frames.

stream_reply(pid, status, headers)

@spec stream_reply(
  stream_pid :: pid(),
  status :: non_neg_integer(),
  headers :: headers()
) :: :ok

Asynchronously send back to the client the http status and the headers for a given request.

stream_trailers(pid, trailers)

@spec stream_trailers(stream_pid :: pid(), trailers :: headers()) :: :ok

Asynchronously stream the given trailers of request back to client.

terminate(reason, req, arg3)

Callback implementation for :cowboy_loop.terminate/3.