apisix-nginx-header内容转义

问题

开发apisix插件时, 把签名内容放到header里
但是验签取出的时候, 发现内容不一样了, 换行什么的都被转义了, 导致验签失败

image

解决

使用的是第二种方案

  1. 使用 lua decode 方法

这种方法可以, 但是偶尔会出现解码后的内容与原始的不同

local function decode(s)
    s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end)
    return s
end
  1. 使用 json 序列化, 反序列化
local core = require("apisix.core")

# 客户端序列化
local json_signature = core.json.encode(signature)

# 服务端反序列化
local decode_signature = core.json.decode(signature)
posted @ 2022-04-24 09:02  loseself  阅读(276)  评论(0编辑  收藏  举报