Coder Social home page Coder Social logo

request body 太大了,不建议 lor 去直接读文件,or 读文件的操作都是阻塞的,建议根据你的需求调大 `client_body_buffer_size ` 的大小 about lor HOT 2 CLOSED

hzgoin avatar hzgoin commented on June 1, 2024
request body 太大了,不建议 lor 去直接读文件,or 读文件的操作都是阻塞的,建议根据你的需求调大 `client_body_buffer_size ` 的大小

from lor.

Comments (2)

sumory avatar sumory commented on June 1, 2024

我个人观点还是不建议通过lor去做上传;另外,针对你说的这个问题,你看下可以提个pr?

from lor.

hzgoin avatar hzgoin commented on June 1, 2024

我们业务中一些非上传业务的body也很大,我是通过middleware给req增加了get_client_body_file函数,然后在body可能超过buffer size的地方主动判断调用,以获取临时文件中的body内容。
pr还的写测试用例😭,以下仅供他人参考吧🙂

----业务代码

if table_is_empty(req.body) then
    data = req.get_client_body_file()
    if data then
        --其他处理逻辑,比如:decode_args或者根据boundary切分
    end
end

----注册中间件

local req_plugin = require("middleware.req_plugin")
app:use(req_plugin())

----middleware/req_plugin.lua----代码参考自《openresty最佳实践》中获取请求body一节的代码

local getFile = function(file_name)
    local f = assert(io.open(file_name, "r"))
    local string = f:read("*all")
    f:close()
    return string
end
return function()
    return function(req, res, next)
        req.get_client_body_file = function(self)
            local file_name = ngx.req.get_body_file()
            if file_name then
                return getFile(file_name)
            end
        end
        next()
    end
end

from lor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.