This is an automated email from the ASF dual-hosted git repository.

ashishtiwari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 138d403f7 revert: fix: forward-auth request body too large (#12404)
138d403f7 is described below

commit 138d403f703d55311798b9d660417b0e1fd1db44
Author: Ashish Tiwari <ashishjaitiwari15112...@gmail.com>
AuthorDate: Mon Jul 7 12:56:09 2025 +0530

    revert: fix: forward-auth request body too large (#12404)
---
 apisix/plugins/forward-auth.lua | 14 ++-----
 t/plugin/forward-auth.t         | 87 +----------------------------------------
 2 files changed, 5 insertions(+), 96 deletions(-)

diff --git a/apisix/plugins/forward-auth.lua b/apisix/plugins/forward-auth.lua
index c75593246..bd58364b2 100644
--- a/apisix/plugins/forward-auth.lua
+++ b/apisix/plugins/forward-auth.lua
@@ -118,17 +118,8 @@ function _M.access(conf, ctx)
         method = conf.request_method
     }
 
-    local httpc = http.new()
-    httpc:set_timeout(conf.timeout)
     if params.method == "POST" then
-        local client_body_reader, err = httpc:get_client_body_reader()
-        if client_body_reader then
-            params.body = client_body_reader
-        else
-            core.log.warn("failed to get client_body_reader. err: ", err,
-            " using core.request.get_body() instead")
-            params.body = core.request.get_body()
-        end
+        params.body = core.request.get_body()
     end
 
     if conf.keepalive then
@@ -136,6 +127,9 @@ function _M.access(conf, ctx)
         params.keepalive_pool = conf.keepalive_pool
     end
 
+    local httpc = http.new()
+    httpc:set_timeout(conf.timeout)
+
     local res, err = httpc:request_uri(conf.uri, params)
     if not res and conf.allow_degradation then
         return
diff --git a/t/plugin/forward-auth.t b/t/plugin/forward-auth.t
index b22260c5f..d6f657537 100644
--- a/t/plugin/forward-auth.t
+++ b/t/plugin/forward-auth.t
@@ -109,19 +109,6 @@ property "request_method" validation failed: matches none 
of the enum values
                                             core.response.exit(403, 
core.request.headers(ctx));
                                         end
                                     end]],
-                                    [[
-                                        return function(conf, ctx)
-                                        local core = require("apisix.core")
-                                        if core.request.get_method() == "POST" 
then
-                                            if core.request.header(ctx, 
"Authorization") == "large-body" then
-                                                
core.response.set_header("X-User-ID", "large-body")
-                                                core.response.exit(200)
-                                            end
-                                            if core.request.header(ctx, 
"Authorization") == "i-am-not-an-user-large-body" then
-                                                core.response.exit(403)
-                                            end
-                                        end
-                                    end]],
                                     [[return function(conf, ctx)
                                         local core = require("apisix.core")
                                         if core.request.get_method() == "POST" 
then
@@ -268,24 +255,6 @@ property "request_method" validation failed: matches none 
of the enum values
                         }
                     }]],
                 },
-                {
-                    url = "/apisix/admin/routes/7",
-                    data = [[{
-                        "plugins": {
-                            "forward-auth": {
-                                "uri": "http://127.0.0.1:1984/auth";,
-                                "upstream_headers": ["X-User-ID"],
-                                "request_headers": ["Authorization"],
-                                "request_method": "POST"
-                            },
-                            "proxy-rewrite": {
-                                "uri": "/echo"
-                            }
-                        },
-                        "upstream_id": "u1",
-                        "uri": "/large-body"
-                    }]],
-                },
                 {
                     url = "/apisix/admin/routes/8",
                     data = [[{
@@ -317,7 +286,7 @@ property "request_method" validation failed: matches none 
of the enum values
         }
     }
 --- response_body eval
-"passed\n" x 11
+"passed\n" x 10
 
 
 
@@ -434,57 +403,3 @@ GET /onerror
 --- more_headers
 Authorization: 333
 --- error_code: 503
-
-
-
-=== TEST 14: test large body
---- config
-    location /t {
-        content_by_lua_block {
-            local core = require("apisix.core")
-            local t    = require("lib.test_admin")
-            local http = require("resty.http")
-
-            local tempFileName = os.tmpname()
-            local file = io.open(tempFileName, "wb")
-
-            local fileSizeInBytes = 11 * 1024 * 1024 -- 11MB
-            for i = 1, fileSizeInBytes do
-                file:write(string.char(0))
-            end
-            file:close()
-
-            local large_body = t.read_file(tempFileName)
-
-            local uri = "http://127.0.0.1:"; .. ngx.var.server_port .. 
"/large-body"
-
-            local httpc = http.new()
-            local res1, err = httpc:request_uri(uri,
-                {
-                    method = "POST",
-                    body = large_body,
-                    headers = {
-                        ["Authorization"] = "i-am-not-an-user-large-body",
-                        ["Content-Type"] = "application/x-www-form-urlencoded"
-                    }
-                }
-            )
-            assert(res1.status == 403, "status: " .. res1.status)
-            data1 = core.json.decode(res1.body)
-
-            local res2, err = httpc:request_uri(uri,
-                {
-                    method = "POST",
-                    body = large_body,
-                    headers = {
-                        ["Authorization"] = "large-body",
-                        ["Content-Type"] = "application/x-www-form-urlencoded"
-                    }
-                }
-            )
-            assert(res2.status == 200, "status: " .. res2.status)
-            data2 = core.json.decode(res2.body)
-            assert(data2["x-user-id"] == "large-body", "x-user-id: " .. 
data2["x-user-id"])
-        }
-    }
---- error_code: 200

Reply via email to