Ace: HTTP/2 webserver

Tags: #<Tag:0x00007fbca83e7148> #<Tag:0x00007fbca83e6f40> #<Tag:0x00007fbca83e6dd8>


The latest release of Ace (0.10.0) includes serving content over HTTP/2.

I have started writing a webserver to teach my self more about webservers. Ace

The easiest thing is to probably summarize the plan here and if you want more details head on over to the README.

  1. To take this obviously deficient TCP echo server that I wrote as a beginner elixir developer and create a fully fledged HTTP server.
  2. Keep reasonable notes of progress so others can learn about how to build a web server in elixir.
  3. See what progress I have made in a year as an elixir developer.

Currently I have an issue which is confusing me (yes even at this beginner stage).
When I restart the server it often fails because the port is currently in use.
I call gen_tcp.close and am unsure why there is a delay in the port being properly closed?
Give the computer a few moments and the port does eventually become available again.

I know this is probably a help question but I didn’t want to post about my project twice and there are more things coming this way soon


Hmm, I’ve not experienced that and am not in a short set of tests here. Can you give a reproducable iex or so session or a github repo with a test that demonstrates this? I’m quite curious as this sounds like it is not operating as it should…



What do you mean by reproducible iex session? just the list of commands that I entered that you can manually repeat?

I will also have a look at setting up a test.


Yep, quickest way to test, or a full git test that we can clone works too. :slight_smile:


So this will be some alternative to go ? :slight_smile:


:stuck_out_tongue_winking_eye: mebe.

Actually my goal is for it to have extremely readable source. I “almost” hope this makes it slow so that people know that its for demo purposes.



Thanks for the help. Quick question, Did you remember to comment out line 25 {:reuseaddr, true}. This line fixes the problem but I’m not really sure why.

The walk-through of commands after that takes two terminals.

# terminal 1
vagrant up
vagrant ssh
cd /vagrant
elixir server.ex

# terminal 2
vagrant ssh
telnet localhost 8080

# In telnet
# Connection closed by foreign host.

# terminal 1 
# restart server
elixir server.ex

# ** (MatchError) no match of right hand side value: {:error, :eaddrinuse}
#    server.ex:30: TCPEcho.start/1
#    (elixir) lib/code.ex:363: Code.require_file/2

# Wait a while.
elixir server.ex
# Listening on port: 8080


Thanks to some pointers from helpful people I now understand this issue. I have added comments to the source code explaining reuseaddr.


The latest release of Ace (0.10.0) includes serving content over HTTP/2.

Instructions for getting started can be found in this guide.
An example app is available here.

Features available at this point are

  • Stream isolation; one process per stream
  • Bidirectional streaming; stream data too and from clients
  • TLS(SSL) support via ALPN; data encrypted in transit
  • Raxx interface; simplicitfy for request/response interactions

Also see the Roadmap for remaining features.

An adapter for plug and therefore phoenix is not something I am looking at yet. My preference is to shore up the foundations prior to a 1.0 release. However if anyone wanted to look at this I would be happy to offer some help getting through the codebase.

Any feedback would be great. At this point I am particularly looking for comments around the API.
At this point the project is very alpha. However I hope to stabilise it quickly.


Ace 0.11.0 is now tested with h2spec.

In strict mode Ace passes 143/146 of the h2spec test suite.
The remaining issues are all around hpack and choices on handling compression errors

For the full list of changes see the changelog.


Oooo, that is awesome!!!


Ace 0.11.1 includes a HTTP/2.0 client with streaming or synchronous api.

Here is a quick example. For full story see the docs

alias Ace.HTTP2.Client
alias Ace.Request
alias Ace.Response

{:ok, client} = Client.start_link("")

# simple
request = Request.get("/", [{"accept", "application/json"}])
{:ok, response} = Client.send_sync(client, request)

# streaming
request = Request.get("/", [{"accept", "application/json"}])
{:ok, stream} =, request)

receive do
  {^stream, response = %Response{body: true}} ->
receive do
  {^stream, %{data: data, end_stream: end_stream}} ->


I talked about Ace at Elixir.LDN, the videos is available now.

The talk covers

  • The basics of HTTP/2
  • Design decisions made by Ace, in particular how to make streaming easy
  • Some chosen implementation details
  • Next steps, including a plug adapter, GRPC implementation and GenStage integration


Ace 0.14.0 released

Switches over to using the Latest version of the Raxx.Server interface, which supports streaming.

Raxx docs.


Server specification

defmodule MyProject.WWW do
  use Raxx.Server

  def handle_headers(%Raxx.Request{method: :GET, path: []}, greeting) do
    |> Raxx.set_header("content-type", "text/plain")
    |> Raxx.set_body(greeting)

Server startup

application = {MyProject.WWW, "Hello, World!"}

options = [
  port: 8443,
  certfile: "path/to/certfile"
  keyfile: "path/to/keyfile"
{:ok, pid} = Ace.HTTP2.Service.start_link(application, options)


Ace 0.14.6 released.

Added is the Ace.HTTP.Service. This is the general purpose way start a server, currently supports HTTP/1 but will serve the same content over HTTP/1 and HTTP/2 in next releases

This functionality obsoletes the ace_http previously for serving content over HTTP/1


Ace 0.14.8 Supports HTTP/2 upgrade.

Application layer protocol notification(ALPN) support now means that a single endpoint will serve content over HTTP/1 or HTTP/2 dependant on the client. This was the final step to make Ace useful to most web applications. Test it out by using Ace.HTTP.Service.


Ace 0.15.4 Uses latest version of server interface with better support for streaming.

defmodule Upload do
  use Raxx.Server

  @impl Raxx.Server
  def handle_head(%{method: :PUT, path: ["upload"] body: true}, _state) do
    {:ok, io_device} ="my/path")
    {[], {:file, device}}

  @impl Raxx.Server
  def handle_data(data, state = {:file, device}) do
    IO.write(device, data)
    {[], state}

  @impl Raxx.Server
  def handle_tail(_trailers, state) do
    |> set_header("location", "/")


Ace 0.15.8 Released

  • Fixes all known issues with connection handling processes not terminating.
  • Add’s typespecs to key public functions, uses typespecs added to latest version of Raxx
  • Adds support for OPTIONS TRACE and CONNECT methods.

Also Ace.HTTP.Service now has a child_spec so it can be added to supervision trees in the up to date manner


Ace 0.15.9 Released

Default start_link and child_spec functionality can be set up by using Ace.HTTP.Service


defmodule MyApp do
  use Ace.HTTP.Service, [port: 8080, cleartext: true]

  def handle_request(%{method: :GET, path: []}, %{greeting: greeting}) do
    |> set_header("content-type", "text/plain")
    |> set_body("#{greeting}, World!")

config = %{greeting: "Hello"}

MyApp.start_link(config, [port: 1234])
# [info] Serving cleartext using HTTP/1 and HTTP/2 on port 1234
# => {:ok, service}

Add to supervision tree

children = [
  {MyApp, [%{greeting: "Hello"}, [port: 1234]]},


defmodule MyApp do
  use Raxx.Server

  @impl Raxx.Server
  def handle_request(%{method: :GET, path: []}, %{greeting: greeting}) do
    |> set_header("content-type", "text/plain")
    |> set_body("#{greeting}, World!")

application = {MyApp, %{greeting: "Hello"}}
options = [port: 1234, cleartext: true]

Ace.HTTP.Service.start_link(application, options)
# [info] Serving cleartext using HTTP/1 and HTTP/2 on port 1234
# => {:ok, service}


Major release 0.16.0

Needed to use the latest version of Raxx Raxx - Interface for HTTP webservers, frameworks and clients