View Source GRPC.Server.Adapters.Cowboy.Handler (grpc v0.9.0)

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

@type headers() :: %{required(binary()) => binary()}
@type init_result() ::
  {:cowboy_loop, :cowboy_req.req(), stream_state()}
  | {:ok, :cowboy_req.req(), init_state()}
@type init_state() ::
  {endpoint :: atom(), server :: {name :: String.t(), module()},
   route :: String.t(), opts :: keyword()}
@type is_fin() :: :fin | :nofin
@type pending_reader() ::
  {cowboy_read_ref :: reference(), server_rpc_pid :: pid(),
   server_rpc_reader_reference :: reference()}
@type stream_body_opts() :: {:code, module()} | {:compress, boolean()}
@type stream_state() :: %{
  pid: server_rpc_pid :: pid(),
  handling_timer: timeout_timer_ref :: reference(),
  pending_reader: nil | pending_reader()
}

Functions

Link to this function

call_rpc(server, path, stream)

View Source
Link to this function

exit_handler(pid, reason)

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

Return all bindings of a given request.

@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.

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

Return all request headers.

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

Return the peer IP address and port number

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

Return the query string for the request URI.

Callback implementation for :cowboy_loop.info/3.

@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)

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

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

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

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

Link to this function

set_compressor(pid, compressor)

View Source
@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.

Link to this function

set_resp_headers(pid, headers)

View Source
@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.

Link to this function

set_resp_trailers(pid, trailers)

View Source
@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.

Link to this function

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

View Source
@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.

Link to this function

stream_reply(pid, status, headers)

View Source
@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.

Link to this function

stream_trailers(pid, trailers)

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

Asynchronously stream the given trailers of request back to client.

Link to this function

terminate(reason, req, arg3)

View Source

Callback implementation for :cowboy_loop.terminate/3.