Packages
ace
0.14.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/worker.ex
defmodule Ace.HTTP2.Worker do
@moduledoc false
use GenServer
def start_link({mod, config}) do
GenServer.start_link(__MODULE__, {mod, config, nil}, [])
end
def handle_info({stream, request = %Raxx.Request{}}, {module, state, nil}) do
module.handle_headers(request, state)
|> handle_return({module, state, stream})
end
def handle_info({stream, %{data: body, end_stream: end_stream}}, {module, state, stream}) do
module.handle_fragment(body, state)
|> handle_return({module, state, stream})
|> case do
{:noreply, {module, state, stream}} ->
if end_stream do
module.handle_trailers([], state)
|> handle_return({module, state, stream})
else
{:noreply, {module, state, stream}}
end
end
end
def handle_info({stream, %{headers: trailers, end_stream: true}}, {module, state, stream}) do
module.handle_trailers(trailers, state)
|> handle_return({module, state, stream})
end
def handle_info({stream, {:reset, reason}}, {module, state, stream}) do
IO.inspect("quiting because: #{inspect(reason)}")
{:stop, :normal, {module, state, stream}}
end
def handle_info(other, {module, state, stream}) do
module.handle_info(other, state)
|> handle_return({module, state, stream})
end
def handle_return(response = %Raxx.Response{}, {module, state, stream}) do
# TODO close here
handle_return({[response], state}, {module, state, stream})
end
def handle_return({messages, new_state}, {module, _old_state, stream}) do
send_messages(messages, stream)
{:noreply, {module, new_state, stream}}
end
def send_messages(messages, stream) do
Enum.each(messages, &send_it(&1, stream))
end
def send_it(response = %Raxx.Response{}, stream) do
Ace.HTTP2.send(stream, response)
end
def send_it(fragment = %Raxx.Fragment{}, stream) do
Ace.HTTP2.send(stream, fragment)
end
def send_it(trailer = %Raxx.Trailer{}, stream) do
Ace.HTTP2.send(stream, trailer)
end
def send_it({:promise, request}, stream) do
request = request
|> Map.put(:scheme, request.scheme || :https)
Ace.HTTP2.send(stream, {:promise, request})
end
end