• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

detailyang/lua-resty-cors: It's the implement of CORS on OpenResty

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

detailyang/lua-resty-cors

开源软件地址(OpenSource Url):

https://github.com/detailyang/lua-resty-cors

开源编程语言(OpenSource Language):

Lua 94.8%

开源软件介绍(OpenSource Introduction):

Name

lua-resty-cors

lua-resty-cors

It's the implement of CORS on OpenResty and It backports the nginx-http-cors to OpenResty

Table of Contents

Status

Build Status

Usage

It may be placed on the nginx http block for a global CORS config or in each server block to configure a different CORS for each virtual host as the following:

http {
      init_by_lua_block {
        local cors = require('lib.resty.cors');

        cors.allow_host([==[.*\.google\.com]==])
        cors.allow_host([==[.*\.facebook\.com]==])
        cors.expose_header('x-custom-field1')
        cors.expose_header('x-custom-field2')
        cors.allow_method('GET')
        cors.allow_method('POST')
        cors.allow_method('PUT')
        cors.allow_method('DELETE')
        cors.allow_header('x-custom-field1')
        cors.allow_header('x-custom-field2')
        cors.max_age(7200)
        cors.allow_credentials(false)
      }
      
      header_filter_by_lua_block {
        local cors = require('lib.resty.cors');
        cors.run()
    }
}

API

allow_host

syntax: cors.allow_host(host)

This will match the host from cors request then be added to the header Access-Control-Allow-Origin like as the following:

Request:
Origin: https://www.google.com

Response:
Access-Control-Allow-Origin: http://www.google.com

expose_header

syntax: cors.expose_header(header)

This will be added to the header Access-Control-Expose-Headers like as the following:

Request:
Origin: https://www.google.com

Response:
Access-Control-Expose-Headers: x-custom-field1,x-custom-field2

allow_method

syntax: cors.allow_method(method)

This will be added to the header Access-Control-Allow-Methods like as the following:

Request:
Origin: https://www.google.com

Response:
Access-Control-Allow-Methods:GET,POST,PUT

allow_header

syntax: cors.allow_header(header)

This will be added to the header Access-Control-Allow-Headers like as the following:

Request:
Origin: https://www.google.com

Response:
Access-Control-Allow-Headers:x-custom-field1,x-custom-field2

max_age

syntax: cors.max_age(age)

This will be added to the header Access-Control-Max-Age like as the following:

Request:
Origin: https://www.google.com

Response:
Access-Control-Max-Age: 7200

Allow-Credentials

syntax: cors.allow_credentials(true or false)

This will be added to the header Access-Control-Allow-Credentials like as the following:

Request:
Origin: https://www.google.com

Response:
Access-Control-Allow-Credentials: true

run

syntax: cors.run()

This is the entry for lua-resty-cors to run

Contributing

To contribute to lua-resty-cors, clone this repo locally and commit your code on a separate branch.

PS: PR Welcome


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
L-JINBIN/AndroidLua: Lua 5.3.1 的 Android 加强版实现发布时间:2022-08-17
下一篇:
latex3/luaotfload: OpenType font loader for LuaTeX发布时间:2022-08-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap