8月 022017
 

 

syntax: headers = ngx.resp.get_headers(max_headers?, raw?)

context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, balancer_by_lua*

Returns a Lua table holding all the current response headers for the current request.

This function has the same signature as ngx.req.get_headers except getting response headers instead of request headers.

 

参考: https://github.com/openresty/lua-nginx-module#ngxrespget_headers

注意: 字段名都会转换成小写

 Posted by at 下午 2:27

lua学习

 lua  No Responses »  2,003 
4月 152015
 

module机制

等同于

 

 Posted by at 上午 10:21
4月 082015
 

缘起

需要写一个lua版的SDK在nginx中使用

基本功能

  1. 通过http请求下载关于SDK的配置文件并cache起来
  2. http的响应信息是json格式的
  3. 需要用到rsa/des/rc4解密

系统环境

ubuntu14.04

相关资料

  • http://www.kyne.com.au/~mark/software/lua-cjson-manual.html
  • http://www.kyne.com.au/~mark/software/lua-cjson.php
  • zlib下载地址: http://www.zlib.net/
  • 安装luajit: http://luajit.org/install.html

学到了什么

 Posted by at 下午 7:20
4月 082015
 

luarocks是lua实现的一个lua包管理工具。对于包管理工具,下载操作是少不了的,对于墙内的那些人来讲,proxy自然就是少不了的。

/etc/luarocks/config.lua 中添加变量 proxy 如下:

 

 Posted by at 下午 6:56
11月 172014
 

缘起

使用ffi给lua包一个rsa算法, 刚刚学习ffi,连文档都没仔细看过,当返回加密结果时,如果直接返回CDATA,则解密没有问题,如果转为lua string(使用ffi.string) ,则后续无法解密

调试

  1. 直接在lua中调试基本无法凑效
  2. 重新编译openssl的libcrypt库,加入调试信息,先是祭出gdb,调的晕乎乎的;然后,则可以地方修改C代码,打印调试信息
  3. 发现,使用ffi.string 和不使用ffi.string 的差别在于,字符串的前面一部分是相同的,后面一部分是不同的,出于对零字节的敏感,发现是从零字节之后开始不同的;猜测ffi.string()或许可以有第二个参数(悲催,因为给一个参数也好使过,所以再没看过文档)
  4. 查ffi的文档,发现ffi.string()是有第二个参数的,添加第二个参数,问题解决
  5. 这个花费了我大约2天的时间,欲哭无泪

结论

  1. ffi.string(cdata, len) 是有第二个参数的,如果不写第二个参数,则从第一个零字节处截断
  2. 学习要循序渐进,文档是要看的

成果

 

 Posted by at 下午 4:29