我是靠谱客的博主 兴奋绿茶,这篇文章主要介绍apisix插件之修改返回body,现在分享给大家,希望可以做个参考。

1、修改请求返回body的插件,直接上代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
local core = require("apisix.core") local ngx = ngx local string = string --插件配置json语法 local schema = {     properties = {         before_body = {             description = "body before the filter phase.",             type = "string"         },         body = {             description = "body to replace upstream response.",             type = "string"         },         after_body = {             description = "body after the modification of filter phase.",             type = "string"         }     },     anyOf = {         {required = {"before_body"}},         {required = {"body"}},         {required = {"after_body"}}     },     minProperties = 1 } --插件名称 local plugin_name = "eag" local _M = {     version = 0.1,     priority = 20004, --插件优先级     name = plugin_name,     schema = schema, } --插件配置检验 function _M.check_schema(conf)     return core.schema.check(schema, conf) end --返回值body修改同时必须修改ngx.header.content_length function _M.body_filter(conf, ctx)     local request_uri = ngx.var.uri       if conf.after_body then         ngx.arg[1] = string.upper(conf.body)     end     ngx.arg[2] = true end --修改ngx.header.content_length function _M.header_filter(conf, ctx)     if conf.body then         ngx.header.content_length = #conf.body         -- in case of upstream content is compressed content         ngx.header.content_encoding = nil     end end

 

最后

以上就是兴奋绿茶最近收集整理的关于apisix插件之修改返回body的全部内容,更多相关apisix插件之修改返回body内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部