Coder Social home page Coder Social logo

Comments (8)

chobits avatar chobits commented on May 26, 2024
local a=kong.service.response.get_body("application/json")kong.log.err("Logger: "..a.ref_id)

Maybe a.ref_id trigger the error because a is nil. so referring .ref_id from nil(a) table will report runtime error

from kong.

bungle avatar bungle commented on May 26, 2024

@budiprihhastomo, @chobits, yes, this is a known issue. I think we need to fix it.

from kong.

bungle avatar bungle commented on May 26, 2024

As a workaround you can probably use:
kong.service.response.get_raw_body() + https://github.com/Kong/kong/blob/master/kong/tools/gzip.lua#L57-L59C4

from kong.

budiprihhastomo avatar budiprihhastomo commented on May 26, 2024

Thanks for the explanation.

Maybe a.ref_id trigger the error because a is nil. so referring .ref_id from nil(a) table will report runtime error

That's right, that's the reason, but it happens because basically the contents of the body's response have not been decoded from gzip.

As a workaround you can probably use:
kong.service.response.get_raw_body() + https://github.com/Kong/kong/blob/master/kong/tools/gzip.lua#L57-L59C4

CMIIW, I've checked, but unfortunately, it looks like the gzip file is not yet in the tagging version. I only found it on the master branch.

from kong.

budiprihhastomo avatar budiprihhastomo commented on May 26, 2024

Hi, is there any follow-up regarding this issue?

from kong.

bungle avatar bungle commented on May 26, 2024

@budiprihhastomo it has been very long here (and in older versions):
https://github.com/Kong/kong/blob/3.5.0/kong/tools/utils.lua#L1380-L1389

Also the tools.gzip is still usable through tools.utils for backward compatibility.

from kong.

budiprihhastomo avatar budiprihhastomo commented on May 26, 2024

Ah sorry I didn't see it, I thought the file matched the file name you gave earlier. Thank you @bungle for helping me.

I have tried, but there is a little problem here, how to use it correctly? When I use require, it won't work for sandbox mode reasons.

But if I use it like this:

local utils = kong.tools.utils
local rawBody = kong.service.response.get_raw_body()
local inflateGzip = utils.inflate_gzip(rawBody)
kong.log.err("RESPONSE: " .. inflateGzip)

I get a response like the following:

staging-gateway_kong.1.v4px42xqzt54@staging    | 2023/12/14 14:00:32 [error] 1265#0: *2202394 failed to run body_filter_by_lua*: /usr/local/share/lua/5.1/kong/tools/kong-lua-sandbox.lua:164: [string "local kong=kong;local a=kong.tools.utils;loca..."]:1: attempt to index field 'tools' (a nil value)

Sorry that I'm having trouble finding documentation regarding the use of the gzip utility. Thank you.

from kong.

budiprihhastomo avatar budiprihhastomo commented on May 26, 2024

It seems like you can't fully use sandbox mode, right?

I have successfully used inflate_gzip, but I need to ignore that module. Related documents are here untrusted_lua_sandbox_requires.

Thanks @bungle and @chobits for the help, I really appreciate it.
And maybe if there is a better recommendation than this, I really hope for it.

from kong.

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.