GithubHelp home page GithubHelp logo

Comments (4)

agentzh avatar agentzh commented on August 17, 2024

你应当使用 ngx.req.read_body(), ngx.req.get_body_data() 和 ngx.req.get_body_file() 来读取请求体。另一种选择是使用 ngx.req.socket().

你上面的代码并没有读取请求体数据。引用 $echo_request_body 变量并不会自动触发请求体读取操作。

from lua-resty-redis.

LazyZhu avatar LazyZhu commented on August 17, 2024

感谢回复!

如果我在content_by_lua前面加proxy_pass是否就可以使 $echo_request_body 变量赋值?

from lua-resty-redis.

LazyZhu avatar LazyZhu commented on August 17, 2024

加入了请求读取操作,请帮忙再看一下:

location /from_proxy {
    proxy_pass http://backend;
}

location /to_redis {
    default_type text/html;
    set $key $url;
    set $exptime 300;
    content_by_lua '

        local res = ngx.location.capture("/from_proxy", {
            method = ngx.HTTP_GET,
            body = ngx.req.get_body_data()})

        local redis = require "resty.redis"
        local red = redis:new()

        red:set_timeout(1000)

        local ok, err = red:connect("127.0.0.1", 6379)
        if not ok then
            return nil
        end

        local ok, err = red:set(ngx.var.key,ngx.var.res.body,ngx.var.exptime)
        if not ok then
            return nil
        end

        red:close()
    ';
}

from lua-resty-redis.

agentzh avatar agentzh commented on August 17, 2024

Hello!

On Mon, Oct 22, 2012 at 10:42 PM, LazyZhu [email protected] wrote:

加入了请求体读取操作,请帮忙再看一下:

location /proxy_request {
proxy_pass http://backend;
}

location /toredis {
default_type text/html;
set $key $url;
set $exptime 300;
content_by_lua '

    local res = ngx.location.capture("/proxy_request", {
        body = ngx.req.get_body_data()})

你这里并没有如你说的那样加入请求体读取操作。ngx.req.read_body() 才是请求体读取操作:

http://wiki.nginx.org/HttpLuaModule#ngx.req.read_body

你调用 ngx.req.get_body_data() 和读取 $echo_request_body 变量的效果几乎是完全相同的。

-agentzh

from lua-resty-redis.

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.