From 6d366d6c3186269c9d392b196e3ce8b01a51c4cd Mon Sep 17 00:00:00 2001 From: therusskiy Date: Sun, 8 Oct 2017 18:11:12 +0400 Subject: [PATCH 1/2] ability to change payload limit --- README.md | 8 ++++++++ config/config.exs | 3 ++- lib/poxa/event_handler.ex | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 00dde7d..60225d3 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,14 @@ config :poxa, keyfile: "priv/ssl/server.key"] ``` +Optionally you can specify a payload limit. The default value is 10kb. To change it pass +``` +PAYLOAD_LIMIT=20000 +``` +where 20000 is number of bytes. + +You can also specify this value via `payload_limit` in your config file (e.g. my_config.exs) as you would for other variables. + ## Release This is the preferred way to deploy a Poxa server. diff --git a/config/config.exs b/config/config.exs index d24d9ea..24f0351 100644 --- a/config/config.exs +++ b/config/config.exs @@ -11,4 +11,5 @@ config :poxa, app_secret: get_env("POXA_SECRET") || "secret", app_id: get_env("POXA_APP_ID") || "app_id", registry_adapter: get_env("POXA_REGISTRY_ADAPTER") || "gproc", - web_hook: get_env("WEB_HOOK") || nil + web_hook: get_env("WEB_HOOK") || nil, + payload_limit: get_env("PAYLOAD_LIMIT") || 10_000 diff --git a/lib/poxa/event_handler.ex b/lib/poxa/event_handler.ex index c5b99a1..207bfa6 100644 --- a/lib/poxa/event_handler.ex +++ b/lib/poxa/event_handler.ex @@ -62,7 +62,8 @@ defmodule Poxa.EventHandler do The event data can't be greater than 10KB """ def valid_entity_length(req, %{event: event} = state) do - valid = byte_size(event.data) <= 10_000 + {:ok, payload_limit} = Application.fetch_env(:poxa, :payload_limit) + valid = byte_size(event.data) <= payload_limit req = if valid do req else From b689d49cc5047abe4ba3371a0af23aa69d5cefca Mon Sep 17 00:00:00 2001 From: therusskiy Date: Mon, 9 Oct 2017 15:40:32 +0400 Subject: [PATCH 2/2] adjust error and docs to reflect configurable payload_limit --- lib/poxa/event_handler.ex | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/poxa/event_handler.ex b/lib/poxa/event_handler.ex index 207bfa6..b821290 100644 --- a/lib/poxa/event_handler.ex +++ b/lib/poxa/event_handler.ex @@ -56,10 +56,8 @@ defmodule Poxa.EventHandler do {authorized, req, state} end - @invalid_data_size_json JSX.encode!(%{error: "Data key must be smaller than 10KB"}) - @doc """ - The event data can't be greater than 10KB + The event data can't be greater than payload_limit which defaults to 10KB """ def valid_entity_length(req, %{event: event} = state) do {:ok, payload_limit} = Application.fetch_env(:poxa, :payload_limit) @@ -67,7 +65,7 @@ defmodule Poxa.EventHandler do req = if valid do req else - :cowboy_req.set_resp_body(@invalid_data_size_json, req) + :cowboy_req.set_resp_body(invalid_data_size_json(payload_limit), req) end {valid, req, state} end @@ -89,4 +87,9 @@ defmodule Poxa.EventHandler do req = :cowboy_req.set_resp_body("{}", req) {true, req, nil} end + + @doc false + defp invalid_data_size_json(payload_limit) do + JSX.encode!(%{error: "Data key must be smaller than #{payload_limit}B"}) + end end