Skip to content

Commit

Permalink
move cowboy ws proxy to seperate git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ajuvercr committed Jul 21, 2021
1 parent 72c4243 commit ad7b94d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 139 deletions.
6 changes: 1 addition & 5 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ config :dispatcher,
# log whenever a layer starts processing
log_layer_start_processing: CH.system_boolean("LOG_LAYER_START_PROCESSING"),
# log whenever a layer matched, and if no matching layer was found
log_layer_matching: CH.system_boolean("LOG_LAYER_MATCHING"),
log_ws_all: CH.system_boolean("LOG_WS_ALL"),
log_ws_backend: CH.system_boolean("LOG_WS_BACKEND"),
log_ws_frontend: CH.system_boolean("LOG_WS_FRONTEND"),
log_ws_unhandled: CH.system_boolean("LOG_WS_UNHANDLED")
log_layer_matching: CH.system_boolean("LOG_LAYER_MATCHING")

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
Expand Down
4 changes: 0 additions & 4 deletions lib/dispatcher/log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ defmodule Dispatcher.Log do
@type log_name ::
:log_layer_start_processing
| :log_layer_matching
| :log_ws_all
| :log_ws_backend
| :log_ws_frontend
| :log_ws_unhandled

@spec log(log_name, any()) :: any()
def log(name, content) do
Expand Down
6 changes: 3 additions & 3 deletions lib/manipulators/remove_accept_encoding_header.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ defmodule Manipulators.RemoveAcceptEncodingHeader do

@impl true
def headers(headers, connection) do
# headers =
# headers
# |> Enum.reject( &match?( {"accept_encoding", _}, &1 ) )
headers =
headers
|> Enum.reject( &match?( {"accept_encoding", _}, &1 ) )
{headers, connection}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/matcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ defmodule Matcher do
defp sort_and_group_accept_headers(accept) do
accept
|> safe_parse_accept_header()
|> IO.inspect(label: "parsed_accept_header")
# |> IO.inspect(label: "parsed_accept_header")
|> Enum.sort_by(&elem(&1, 3))
|> Enum.group_by(&elem(&1, 3))
|> Map.to_list()
Expand Down
18 changes: 16 additions & 2 deletions lib/mu_dispatcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule MuDispatcher do

children = [
# this is kinda strange, but the 'plug:' field is not used when 'dispatch:' is provided (my understanding)
{Plug.Adapters.Cowboy,
{Plug.Cowboy,
scheme: :http, plug: PlugRouterDispatcher, options: [dispatch: dispatch, port: port]}
]

Expand All @@ -21,10 +21,24 @@ defmodule MuDispatcher do
end

defp dispatch do
default = %{
host: "localhost",
port: 80,
path: "/"
}

f = fn req ->
{_, target} =
:cowboy_req.parse_qs(req)
|> Enum.find(fn {head, _} -> head == "target" end)

Dispatcher.get_websocket(target)
end

[
{:_,
[
{"/ws/[...]", WebsocketHandler, %{}},
{"/ws/[...]", WsHandler, {f, default}},
{:_, Plug.Cowboy.Handler, {PlugRouterDispatcher, []}}
]}
]
Expand Down
2 changes: 0 additions & 2 deletions lib/plug_router_dispatcher.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
alias Dispatcher.Log

defmodule PlugRouterDispatcher do
use Plug.Router

Expand Down
122 changes: 0 additions & 122 deletions lib/websocket_handler.ex

This file was deleted.

1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ defmodule Dispatcher.Mixfile do
# Type `mix help deps` for more examples and options
defp deps do
[
{:cowboy_ws_proxy, git: "https://github.com/ajuvercr/elixir-cowboy-ws-proxy-handler.git", tag: "v0.1"},
{:plug_mint_proxy,
git: "https://github.com/madnificent/plug-mint-proxy.git", tag: "v0.0.2"},
# {:plug, "~> 1.10.4"},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"castore": {:hex, :castore, "0.1.11", "c0665858e0e1c3e8c27178e73dffea699a5b28eb72239a3b2642d208e8594914", [:mix], [], "hexpm", "91b009ba61973b532b84f7c09ce441cba7aa15cb8b006cf06c6f4bba18220081"},
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"},
"cowboy_ws_proxy": {:git, "https://github.com/ajuvercr/elixir-cowboy-ws-proxy-handler.git", "e015e27775af30d4e3d7ca5629d97191cca61555", [tag: "v0.1"]},
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
"exsync": {:hex, :exsync, "0.2.4", "5cdc824553e0f4c4bf60018a9a6bbd5d3b51f93ef8401a0d8545f93127281d03", [:mix], [{:file_system, "~> 0.2", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "f7622d8bb98abbe473aa066ae46f91afdf7a5346b8b89728404f7189d2e80896"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
Expand Down

0 comments on commit ad7b94d

Please sign in to comment.