【发布时间】:2020-01-11 22:44:56
【问题描述】:
由于某些遗留软件,我需要更改 SOAP 请求的正文。它使用 SOAP-ENV 作为命名空间,而它需要变成“soap”:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
应该变成:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
尽管它应该无关紧要,但对于旧版软件它确实如此。至少现在我要快速修复一下请求正文中的搜索/替换。 Nginx 在系统之前作为网络服务器运行,所以我搜索了一下,发现它只能由 Lua 完成。我已经安装了nginx-extras,现在正在使用以下脚本:
location ~ '\.php$' {
location ~ ^/webservice/ {
access_by_lua_block
{
ngx.req.read_body()
local body = ngx.req.get_body_data()
if body
body = string.gsub(body, "SOAP-ENV", "soap")
end
ngx.req.set_body_data(body)
}
}
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
include fastcgi_params;
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}
似乎 body 总是为零。我正在使用 SOAP UI 来放置 SOAP 请求。我在这里做错了什么?
【问题讨论】:
-
你为什么要使用
access_by_lua?这是请求处理的访问阶段,也就是。它决定是否允许客户端发出该请求。你想要的是body_filter_by_lua(见readme) -
其实,别管最后的评论了;毕竟,openresty 似乎已经在访问阶段提供了 body。