gaggle
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)
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #iex
- #elixirconf-us
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Sanjibukai
If I look here, it seems the second argument to
cowboy_req.replyshould be a map (not a tuple) Nine Nines: The Req objectMaybe, try using a map
%{"content-type" => "text/html"}Although I don’t have much experience with bare cowboy..
Also, I don’t remember if we need to use single quotes for string or not (for the Erlang side)..
Good luck..
Edit: According to the above link, the maps fields is expected to be “binaries” and according to here Erlang/Elixir Syntax: A Crash Course - The Elixir programming language using double quotes on the Elixir side is enough..
gaggle
Ah… ah yes!, moving to a map for headers solves that error. I tried that early but apparently got stuck on another error after without realizing, and never went back to try that. Thanks for suggesting it.
nine nines docs show this:
In hindsight I just had to search to confirm
#{}syntax in Erlang means a map in Elixir, d’oh. And I misunderstood what comes back fromcowboy_req.reply, now that I can navigate Erlang code a tiny bit I can see it’sinitthat returns an ok-tuple, not.replyitself.Anyway, everything works now, thanks for the assist @Sanjibukai!
Updated code
defmodule CowboyExample.Application do
use Application
def start(_type, args) do
dispatch = :cowboy_router.compile([{:, [{“/”, CowboyExample.HelloHandler, }]}])
end
end
defmodule CowboyExample.HelloHandler do
def init(req, _opts) do
req = :cowboy_req.reply(200, %{“content-type” => “text/html”}, “
Hello World!
”, req){:ok, req, :nostate}
end
end