Hey all,
Maybe my tired eyes are just tiredly overlooking a tired tiny detail, but for all the staring and experimenting I’ve done I can’t seem to get past this
I start iex and start my cowboy module:
$ iex -S mix
Erlang/OTP 26 [erts-14.2.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [dtrace]
Interactive Elixir (1.16.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Cowboy.start
Cowboy server started on port 8080
:ok
Then I curl in another terminal:
$ curl http://localhost:8080
And the server throws this:
21:58:22.288 [error] Ranch listener :my_http_listener, connection process #PID<0.247.0>, stream 1 had its request process #PID<0.248.0> exit with reason {:badmap, [{"content-type", "text/html"}]} and stacktrace [{:cowboy_req, :reply, 4, [file: ~c"/cowboy_example/deps/cowboy/src/cowboy_req.erl", line: 837]}, {HelloHandler, :init, 2, [file: ~c"lib/application.ex", line: 19]}, {:cowboy_handler, :execute, 2, [file: ~c"/cowboy_example/deps/cowboy/src/cowboy_handler.erl", line: 37]}, {:cowboy_stream_h, :execute, 3, [file: ~c"/cowboy_example/deps/cowboy/src/cowboy_stream_h.erl", line: 306]}, {:cowboy_stream_h, :request_process, 3, [file: ~c"/cowboy_example/deps/cowboy/src/cowboy_stream_h.erl", line: 295]}, {:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 241]}]
Headers are “:badmap
”?
Here’s the sourcecode:
defmodule Cowboy do
def start() do
dispatch = :cowboy_router.compile([ {:_, [ {"/", HelloHandler, []} ]} ])
{:ok, _} = :cowboy.start_clear(
:my_http_listener,
[{:port, 8080}],
%{env: %{dispatch: dispatch}}
)
IO.puts("Cowboy server started on port 8080")
end
end
defmodule HelloHandler do
def init(req, _opts) do
{:ok, resp} = :cowboy_req.reply( 200, [{"content-type", "text/html"}], "<h1>Hello World!</h1>", req )
{:ok, resp, :nostate}
end
end
I must be doing something wrong but I’m pretty new to navigating Erlang docs and translating it into Elixir… can you spot it, or help me spot it?
(And mix.exs
is configured with {:cowboy, "~> 2.11"}
in deps
, and extra_applications: [:logger, :cowboy]
in application
FWIW)