JuanjoA

JuanjoA

Hi, to begin with, I am new to elixir/phoenix (:slight_smile: disclaimer)

For what has already been discussed in this thread:
Benchmark report the-benchmarker and phoenix

I trying to create a response 200, ok, from a custom plug, without others steps in the pipeline.
I have endpoint (default phoenix) → a router (here I declare a new pipeline with only two plugs, html and my custom plug) . . .
but I cant halt the request and return the 200ok status, without return any html.
This is probably very easy, or maybe I need to use a controller, but the idea is to stay in the surface layer of the web server and return the status without touching anything else (template, ecto, etc…)
Any suggestions are welcome!

Some code:

# router.ex
pipeline :browser_for_benchmark do
    plug :accepts, ["html"]
    plug NothingPlug
  end

  scope "/", RumblWeb do
    pipe_through :browser_for_benchmark
    get "/", PageController, :index
  end

And the code plug:

# nothing_plug.ex
defmodule NothingPlug do
  def init(opts), do: opts

  def call(conn, _opts) do
    conn
    |> Plug.Conn.put_status(200)
    # this dont work, dont return any response
    |> Plug.Conn.halt()
  end
end

With halt, we have this log error message:

> 20:03:01.200 request_id=FmOyhkAVtCWcFnwAAAAC [info] GET /
> 20:03:01.212 [error] #PID<0.484.0> running RumblWeb.Endpoint (connection #PID<0.483.0>, stream id 1) terminated
> Server: 127.0.0.1:4000 (http)
> Request: GET /
> ** (exit) an exception was raised:
>     ** (Plug.Conn.NotSentError) a response was neither set nor sent from the connection
>         (phoenix 1.5.7) lib/phoenix/endpoint/cowboy2_handler.ex:110: Phoenix.Endpoint.Cowboy2Handler.maybe_send/2
>         (phoenix 1.5.7) lib/phoenix/endpoint/cowboy2_handler.ex:66: Phoenix.Endpoint.Cowboy2Handler.init/4
>         (cowboy 2.8.0) /home/juanjo/repos/elixir/phoenix/rumbl/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
>         (cowboy 2.8.0) /home/juanjo/repos/elixir/phoenix/rumbl/deps/cowboy/src/cowboy_stream_h.erl:300: :cowboy_stream_h.execute/3
>         (cowboy 2.8.0) /home/juanjo/repos/elixir/phoenix/rumbl/deps/cowboy/src/cowboy_stream_h.erl:291: :cowboy_stream_h.request_process/3
>         (stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

Thanks, it is nice to see a sane community.

Showing Posts 1 to 2

hauleth

hauleth

You need to set the response to anything, even empty response. So the simplest plug that achieve what you want would be:

conn
|> Plug.Conn.send_resp(200, [])
|> Plug.Conn.halt()
JuanjoA

JuanjoA OP

Thanks @hauleth, now it works.

Just for commenting, before (without the plug, only default phoenix index) we have 6369 request/s, now, with this plug, 9098 rps on my dev pc, lenovo i5, 4 cores, wrk (-d 20 -c 20), phoenix same machine and MIX_ENV=prod.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews