对了忘记说环境了:
$ /usr/local/openresty/nginx/sbin/nginx -v
nginx version: openresty/1.9.3.1
$ uname -a
Darwin ZoomQuiet-MBP.local 14.4.0 Darwin Kernel Version 14.4.0: Thu
May 28 11:35:04 PDT 2015; root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64
$ brew info pcre
pcre: stable 8.37 (bottled), HEAD
Perl compatible regular expressions library
http://www.pcre.org/
/usr/local/Cellar/pcre/8.36 (146 files, 5.9M)
Poured from bottle
/usr/local/Cellar/pcre/8.37 (146 files, 5.9M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/pcre.rb
==> Options
--universal
Build a universal binary
--HEAD
Install HEAD version
我用 /usr/local/Cellar/pcre/8.37 编译的 OpenResty
2015-08-18 22:17 GMT+08:00 Zoom.Quiet <zoom...@gmail.com>:
> # 背景
> 历史遗留客户端, 只接受特定大小写的 HTTP 响应 HEAD 字段
>
> - 比如 FooBar: 1234567
> - 但是, 后来使用标准化库后,自动将字段名修订为 Foobar 类似字串
> - 客户端就无法接受了
> - 同时,此时的 Nginx 是作为代理,将后端动态系统发布出来的,类似:
> + proxy_pass http://myapi/;
>
> # 尝试
> 发现有两个库可操作 HTTP response HEAD:
>
> - https://github.com/openresty/lua-resty-core
> - https://github.com/openresty/headers-more-nginx-module
>
> 前者是内置的,后者得编译安装
>
> 进行类似尝试时:
>
> ngx.header["X-My-Header"] = 'blah blah'
> local h = ngx.resp.get_headers()
> for k, v in pairs(h) do
> ngx.say(k,'\t', v)
> if k ~='x-my-header' then
> ngx.header["My-Header-X"] = 'blah blah'
> end
> end
>
>
> 报错:
> 2015/08/18 22:06:08 [error] 47371#0: *12 attempt to set
> ngx.header.HEADER after sending out response headers, client:
> 127.0.0.1, server: , request: "GET /echo HTTP/1.1", host:
> "127.0.0.1:8081"
>
>
> 如果将测试脚本部署在代理路径上,类似:
>
> location / {
> proxy_pass http://myapi/;
> content_by_lua_file conf/lua/echo.lua;
> }
>
> 则根本不执行
>
>
> # 提问:
>
> - 如何在 proxy_pass 配置路径上,对代理的响应数据进行提取和修订?
> - 以上两个库,哪个最合理实时对请求响应的 HEAD 字段名进行更改?
>
>
> --
> Life's Pathetic, Let's Pythonic! 人生苦短, Python是岸!
> 俺: http://zoomquiet.io
> 授: http://creativecommons.org/licenses/by-sa/2.5/cn/
> 怒: 冗余不做,日子甭过!备份不做,十恶不赦!
> KM keep growing environment culture which promoting organization be learnning!
--
Life's Pathetic, Let's Pythonic! 人生苦短, Python是岸!
俺: http://zoomquiet.io
授: http://creativecommons.org/licenses/by-sa/2.5/cn/
怒: 冗余不做,日子甭过!备份不做,十恶不赦!
KM keep growing environment culture which promoting organization be learnning!