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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews