-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
defmodule Kino.Proxy do | ||
@moduledoc """ | ||
A kino for handling proxy requests from the host. | ||
Functionality for handling proxy requests forwarded from Livebook. | ||
## Examples | ||
Kino.Proxy.listen(fn conn -> | ||
conn | ||
|> Plug.Conn.put_resp_header("content-type", "application/text;charset=utf-8") | ||
|> Plug.Conn.send_resp(200, "used " <> conn.method <> " method") | ||
end) | ||
TODO: Write an extensive docs here. | ||
""" | ||
|
||
@doc """ | ||
Persists the function to be listened by the proxy handler. | ||
""" | ||
@spec listen(atom(), module(), (Plug.Conn.t() -> Plug.Conn.t())) :: | ||
DynamicSupervisor.on_start_child() | ||
def listen(name \\ __MODULE__, mod \\ Livebook.Proxy.Handler, fun) when is_function(fun, 1) do | ||
Kino.start_child({mod, name: name, listen: fun}) | ||
@spec listen((Plug.Conn.t() -> Plug.Conn.t())) :: DynamicSupervisor.on_start_child() | ||
def listen(fun) when is_function(fun, 1) do | ||
child_spec = Kino.Bridge.get_proxy_handler_child_spec(fun) | ||
Kino.start_child(child_spec) | ||
end | ||
end |