Merge branch 'fix/otp-parsers' into 'develop'
authorlain <lain@soykaf.club>
Mon, 9 Dec 2019 15:10:05 +0000 (15:10 +0000)
committerlain <lain@soykaf.club>
Mon, 9 Dec 2019 15:10:05 +0000 (15:10 +0000)
OTP: Fix runtime upload limit config being ignored

Closes #1109

See merge request pleroma/pleroma!2045

lib/pleroma/plugs/parsers_plug.ex [new file with mode: 0644]
lib/pleroma/web/endpoint.ex

diff --git a/lib/pleroma/plugs/parsers_plug.ex b/lib/pleroma/plugs/parsers_plug.ex
new file mode 100644 (file)
index 0000000..2e493ce
--- /dev/null
@@ -0,0 +1,21 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Plugs.Parsers do
+  @moduledoc "Initializes Plug.Parsers with upload limit set at boot time"
+
+  @behaviour Plug
+
+  def init(_opts) do
+    Plug.Parsers.init(
+      parsers: [:urlencoded, :multipart, :json],
+      pass: ["*/*"],
+      json_decoder: Jason,
+      length: Pleroma.Config.get([:instance, :upload_limit]),
+      body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
+    )
+  end
+
+  defdelegate call(conn, opts), to: Plug.Parsers
+end
index 49735b5c2f858fd38e0cb8aa13baa2b7a7e9de1e..bbea31682c1f6533eb95f53011774df6f6c8f0cc 100644 (file)
@@ -61,14 +61,7 @@ defmodule Pleroma.Web.Endpoint do
   plug(Plug.RequestId)
   plug(Plug.Logger)
 
-  plug(
-    Plug.Parsers,
-    parsers: [:urlencoded, :multipart, :json],
-    pass: ["*/*"],
-    json_decoder: Jason,
-    length: Pleroma.Config.get([:instance, :upload_limit]),
-    body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
-  )
+  plug(Pleroma.Plugs.Parsers)
 
   plug(Plug.MethodOverride)
   plug(Plug.Head)