Packages
ace
0.11.0
0.19.0
0.18.10
0.18.9
0.18.8
0.18.7
0.18.6
0.18.5
0.18.4
0.18.3
0.18.2
0.18.1
0.18.0
0.17.1
0.17.0
0.16.8
0.16.7
0.16.6
0.16.5
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.11
0.15.10
0.15.9
0.15.8
0.15.7
0.15.6
retired
0.15.5
0.15.4
0.15.3
0.15.2
0.15.1
0.15.0
0.14.8
0.14.7
0.14.6
0.14.5
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
0.13.1
0.13.0
0.12.1
0.12.0
retired
0.11.1
0.11.0
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.1
0.8.0
0.7.1
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.0
0.3.0
0.2.0
HTTP web server and client, supports http1 and http2
Current section
Files
Jump to
Current section
Files
lib/ace/http2.ex
defmodule Ace.HTTP2 do
@moduledoc """
**Hypertext Transfer Protocol Version 2 (HTTP/2)**
> HTTP/2 enables a more efficient use of network
> resources and a reduced perception of latency by introducing header
> field compression and allowing multiple concurrent exchanges on the
> same connection. It also introduces unsolicited push of
> representations from servers to clients.
*Quote from [rfc 7540](https://tools.ietf.org/html/rfc7540).*
"""
use Supervisor
@doc """
Start an endpoint to accept HTTP/2.0 connections
"""
def start_link(app, port, opts) do
name = Keyword.get(opts, :name, __MODULE__)
connections = Keyword.get(opts, :connections, 100)
{:ok, supervisor} = Supervisor.start_link(__MODULE__, {app, port, opts}, name: name)
for _index <- 1..connections do
Supervisor.start_child(supervisor, [])
end
{:ok, supervisor}
end
def init({app, port, opts}) do
# DEBT read name twice
name = Keyword.get(opts, :name, __MODULE__)
# server_name = Module.concat(name, Server)
# stream_supervisor_name = Module.concat(name, Stream.Supervisor)
{:ok, certfile} = Keyword.fetch(opts, :certfile)
{:ok, keyfile} = Keyword.fetch(opts, :keyfile)
tls_options = [
active: false,
mode: :binary,
packet: :raw,
certfile: certfile,
keyfile: keyfile,
reuseaddr: true,
alpn_preferred_protocols: ["h2", "http/1.1"]
]
{:ok, listen_socket} = :ssl.listen(port, tls_options)
children = [
worker(Ace.HTTP2.Connection, [listen_socket, app], restart: :transient)
]
supervise(children, strategy: :simple_one_for_one, max_restarts: 1_000)
end
end