Skip to content

Commit

Permalink
Merge pull request #107 from TheRusskiy/feature/change-payload-limit
Browse files Browse the repository at this point in the history
ability to change payload limit
  • Loading branch information
edgurgel authored Oct 14, 2017
2 parents e50d5c3 + 877b2d0 commit 2e26b6e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 10 additions & 3 deletions lib/poxa/event_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,19 @@ defmodule Poxa.EventHandler do
{authorized, req, state}
end


@invalid_data_size_json Poison.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
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
: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
Expand All @@ -88,4 +90,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

0 comments on commit 2e26b6e

Please sign in to comment.