Setting control, plug, cowboy options

295 views
Skip to first unread message

randy....@gmail.com

unread,
Oct 27, 2014, 1:14:08 AM10/27/14
to phoeni...@googlegroups.com
Hi,

Starting converting an app over to use phoenix & elixir 1.0+.  I'm working with large files, and need to increase the default limit set by the cowboy adapter.


which is called by the multipart plug:


This is my first time using Plug, so - not quite sure where to init Plug.Conn with the option within Phoenix.  I am looking to set it at the controller level.

For the controller, I am not using Plug.Upload directly, I use the reference supplied by Plug.Conn.  Thus, I am not sure how to pass the length option so the Connection will use it.  How can this be done?

I'd like to know where this should be set (if not at the controller), and what some options for setting the options are?

Thanks
-- Randy

randy....@gmail.com

unread,
Oct 28, 2014, 11:02:44 AM10/28/14
to phoeni...@googlegroups.com, randy....@gmail.com
Perhaps another way to ask this is:

Where do I set the options for a controller?  Are these options passed to Plug.Adapters.Cowboy.Conn?  If not, is there any way to pass options into that adapter?

-- Randy

Chris McCord

unread,
Oct 28, 2014, 2:32:12 PM10/28/14
to phoeni...@googlegroups.com, randy....@gmail.com
Hey Randy,

You should be able to accomplish this within the `http` options, i.e.

    config :phoenix, MyApp.Router,
      ...
      http: [length: 10_000_000]


These values can only be set per router, not per controller. Phoenix supports multiple Routers though if you absolutely have to isolate this setting. Let me know if that works for you.

Chris

randy....@gmail.com

unread,
Oct 28, 2014, 4:04:06 PM10/28/14
to phoeni...@googlegroups.com, randy....@gmail.com
Hey Chris,

Thanks for looking into this.  Setting the option as part of the router http config was one of the things I did try.  I'm not sure the option setting is making it down to Plug.Upload however.

Here is the stack trace I ultimately see ... when I send in a large file:


-- Randy

Randy Secrist

unread,
Oct 30, 2014, 7:07:52 PM10/30/14
to Chris McCord, phoeni...@googlegroups.com
Yep - that works.  Thanks Chris!

-- Randy

On Tue, Oct 28, 2014 at 7:39 PM, Chris McCord <ch...@chrismccord.com> wrote:
I misspoke, the parser option is what you need to configure:

  parsers: [parsers: [:urlencoded, :multipart, :json],
            accept: ["*/*"],
            json_decoder: Poison,
            length: 100_000_000],


Give that a shot and report back.

-- 
You received this message because you are subscribed to the Google Groups "phoenix-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phoenix-talk...@googlegroups.com.
To post to this group, send email to phoeni...@googlegroups.com.
Visit this group at http://groups.google.com/group/phoenix-talk.
To view this discussion on the web visit https://groups.google.com/d/msgid/phoenix-talk/99b97577-b61d-4b37-bacc-226488d4ecf5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Chris McCord

unread,
Oct 31, 2014, 11:35:23 AM10/31/14
to randy....@gmail.com, phoeni...@googlegroups.com
I misspoke, the parser option is what you need to configure:

  parsers: [parsers: [:urlencoded, :multipart, :json],
            accept: ["*/*"],
            json_decoder: Poison,
            length: 100_000_000],


Give that a shot and report back.

On Oct 28, 2014, at 4:04 PM, randy....@gmail.com wrote:

arunve...@gmail.com

unread,
Jan 26, 2016, 12:58:28 PM1/26/16
to phoenix-talk, randy....@gmail.com
How to produce gzip compressed response? I tried to add a configuration to config.exs but it didn't seem to work.

config :cowboy,
  compress: true 

Thanks.

Arunvel Sriram

unread,
Jan 26, 2016, 2:11:51 PM1/26/16
to phoenix-talk, randy....@gmail.com
Got it working by adding compress: true to Phoenix.Endpoint.http

config :app_name, AppName.Endpoint,
  ...
  http: [compress: true]

On Monday, October 27, 2014 at 10:44:08 AM UTC+5:30, randy....@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages