Gun 2.0 includes state of the art tunnel support. With Gun 2.0 it is possible to make requests or data go through any number of proxy endpoints using any combination of TCP or TLS transports and HTTP/1.1, HTTP/2 or SOCKS5 protocols. All combinations of the scenario Proxy1 -> Proxy2 -> Origin are tested and known to work.
Gun 2.0 adds many more features such as Websocket over HTTP/2, a built-in cookie store, graceful shutdown, flow control for data messages, event handlers and more.
Gun 2.0 also introduces an experimental pool module that automatically maintains connections and routes requests to the right process, in a similar way as browsers do.
Gun 2.0 greatly improves the HTTP/2 performance when it comes to receiving large response bodies; and when receiving response bodies from many separate requests concurrently.
Gun now shares much of its HTTP/2 code with Cowboy, including the HTTP/2 state machine. Numerous issues were fixed as a result because the Cowboy implementation was much more advanced.
The Gun connection process is now implemented using
Gun 2.0 requires Erlang/OTP 22.0 or greater.
cookie_storeoption allows configuring the cookie store backend. The
gun_cookiesmodule provides functions to help implementing such a backend. Gun comes with the backend
gun_cookies_listwhich provides a per-connection, non-persistent cookie store. The cookie store engine implements the entire RFC6265bis draft algorithms except the parts about non-HTTP cookies as no such interface is provided; and the parts about SameSite as Gun has no concept of "browsing context".
gun:shutdown/1or when the owner process goes away; or on the peer side via the connection: close HTTP/1.1 header, the HTTP/2 GOAWAY frame or the Websocket close frame. Gun will try to complete existing streams when possible; other streams get canceled immediately. The
closing_timeoutoption controls how long we are willing to wait at most before closing the connection.
gun:protocols()type for details.
keepaliveoption. It is disabled by default.
silence_pingsoption can be set to
falseto receive all ping and pong frames when using Websocket. They are typically not needed and therefore silent by default.
reply_tooption has been added to
gun:ws_upgrade/4. The option applies to both the response and subsequent Websocket frames.
reply_tooption is also propagated to messages following a CONNECT request when the protocol requested is not HTTP.
retry_funcan be used to implement different backoff strategies when reconnecting.
supervisecan be used to start a Gun connection without using Gun's supervisor. It defaults to
gun_poolmodule was introduced. Its interface is very similar to the
gunmodule, but as it is an experimental feature, it has not been documented yet. The intent is to obtain feedback and document it in an upcoming minor release. Pools are created for each authority (host/port) and scope (user-defined value) pairs and are resolved accordingly using the information provided in the request and request options. Connections may concurrently handle multiple requests/responses from as many different processes as required.
reply_tooption is used.
protocolhas been removed. It was previously deprecated in favor of
keepalivetimeout is now disabled by default for HTTP/1.1 and HTTP/2. To be perfectly clear, this is unrelated to the HTTP/1.1 keep-alive mechanism.
gun:set_owner/2has been added. It allows changing the owner of a connection process. Only the current owner can do this operation.
gun:shutdown/1has been added. It initiates the graceful shutdown of the connection, followed by the termination of the Gun process.
gun:stream_info/2has been added. It provides information about a specific HTTP stream.
gun:info/1now returns the owner of the connection as well as the cookie store.
gun:await_up/1,2,3now distinguish the error types. They can be a timeout, a connection error, a stream error or a down error (when the Gun process exited while waiting).
gun:await/2,3,4will now receive upgrades, tunnel up and Websocket messages and return them.
tunneloption to send the request on a specific tunnel.
gun:request/4,5,6have been replaced with
gun:request/5,6. This provides a cleaner separation between requests that are followed by a body and those that aren't.
gun:ws_send/2has been replaced with the function
gun:ws_send/3. The stream reference for the corresponding Websocket upgrade request must now be given.
gun_tunnel_upmessage has been added.
gun_downmessage no longer has its final element documented as
UnprocessedStreams. It never worked and was always an empty list.
gun_errormessages to the same process.
gun_downmessage when the response contained a connection: close header. This is no longer the case.
gun_downmessage to the connection owner as well as the exit reason of the Gun process.
gun_errormessage. This has been corrected.
Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:
Recurring payment options are also available via GitHub Sponsors. These funds are used to cover the recurring expenses like food, dedicated servers or domain names.