membphis commented on a change in pull request #1327: features: append cors plugin URL: https://github.com/apache/incubator-apisix/pull/1327#discussion_r397175160
########## File path: lua/apisix/plugins/cors.lua ########## @@ -0,0 +1,142 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +local core = require("apisix.core") +local ngx = ngx +local plugin_name = "cors" +local str_find = string.find +local str_gmatch = string.gmatch + +local schema = { + type = "object", + properties = { + allow_origins = { + description = + "you can use '*' to allow all origins when no credentials,".. + "'**' to allow forcefully(it will bring some security risks, be carefully),".. + "multiple origin use ',' to split. default: *.", + type = "string" + }, + allow_methods = { + description = + "you can use '*' to allow all methods when no credentials and '**',".. + "'**' to allow forcefully(it will bring some security risks, be carefully),".. + "multiple method use ',' to split. default: *.", + type = "string" + }, + allow_headers = { + description = + "you can use '*' to allow all header when no credentials,".. + "multiple header use ',' to split. default: *.", + type = "string" + }, + expose_headers = { + description = + "you can use '*' to expose all header when no credentials,".. + "multiple header use ',' to split. default: *.", + type = "string" + }, + max_age = { + description = + "maximum number of seconds the results can be cached.".. + "-1 mean no cached,the max value is depend on browser,".. + "more detail plz check MDN. default: 5.", + type = "integer" + }, + allow_credential = { + type = "boolean" + }, + } +} + +local _M = { + version = 0.1, + priority = 4000, + type = 'auth', + name = plugin_name, + schema = schema, +} + +function _M.check_schema(conf) + local ok, err = core.schema.check(schema, conf) + if not ok then + return false, err + end + + if not conf.allow_origins then + conf.allow_origins = "*" + end + + if not conf.allow_methods then + conf.allow_methods = "*" Review comment: ditto, please fix other similar issues ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
