Loopback.Interceptors.Httpc (Loopback v0.1.0)

Copy Markdown View Source

An interceptor for :httpc, the HTTP client of Erlang/OTP, and the clients built on it, like Tesla's default adapter, Tesla.Adapter.Httpc.

Implementation notes:

  • Synchronous and asynchronous requests are intercepted, including the :receiver option.
  • The :stream option works like in :httpc, for 200 and 206 responses. Streaming to the calling process sends the body in one stream message. With {:self, :once}, the stream is sent without waiting for :httpc.stream_next/1, like :httpc sends a body that has already arrived.
  • A fake's response gets an HTTP/1.1 status line, with the standard reason phrase of its status.
  • Like in :httpc, a request's content type replaces its content-type header.
  • Loopback.HTTPError reasons are returned the way :httpc returns them: :timeout as :timeout, :closed as :socket_closed_remotely, and the other reasons as {:failed_connect, [...]}.
  • Asynchronous requests that fakes handle get request IDs of their own, which work with :httpc.cancel_request/1,2.
  • Requests that fakes handle ignore the HTTP options, like :timeout, and the profile, and don't need :inets to be started.

Summary

Functions

cancel_request(request_id)

cancel_request(request_id, profile)

request(url)

request(url, profile)

request(method, request, http_options, options)

request(method, request, http_options, options, profile)