nginx lua以html显示,Nginx lua modify html response after proxy_pass

What I'm trying to do for a PoC and is to add a href to web pages coming from a dynamic backend server. Adding the href is easy using "subs_filter", but I need to use information embedded within the response to construct the href.

Is it possible to use LUA to process the response from proxy_pass, modify it and return to requester (client)?

Any and all suggestions welcome.

Below is the code I'm looking at, now I understand Lua better and how nginx uses it I see that 'body_filter' is the correct way to. However the code seems simple enough but i can't get the regex to work.

Further background, I'm trying to parse the returned proxy_pass response, parse it for a start and end time, then construct a JS script url placed into the head.

Example response that I want to regex against.

Informações Adicionais

Horário de início: 08H50

Horário de término: 09H14

The code from within the 'location {}'

body_filter_by_lua '

-- my regex which is validate but doesn't seem to be within LUAJIT

--local from, to, err = ngx.re.find(ngx.arg[1], "(.início: *\d{2}H\d{2})", "jo")

local from, to, err = ngx.re.find(ngx.arg[1], "início", "jo")

replacestr = string.sub(ngx.arg[1], to, 5)

replaceme = ""

ngx.arg[1] = ngx.re.sub(ngx.arg[1],"", replaceme)

';

Changing "início" to "head" for example works, so I'm assuming it is the accented char but I'm unable to find confirmation of this.

Changing "início" to "\d{2}H\d{2}" fails, with "body_filter_by_lua:5: invalid escape sequence near '"'"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值