You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2019/11/17 11:20:07 UTC

[GitHub] [incubator-apisix] lilien1010 commented on a change in pull request #863: feature: Allow modify content(status_code&body&header) from upstream, can also support CORS, redirect

lilien1010 commented on a change in pull request #863: feature: Allow modify content(status_code&body&header) from upstream, can also support CORS, redirect
URL: https://github.com/apache/incubator-apisix/pull/863#discussion_r347130690
 
 

 ##########
 File path: lua/apisix/plugins/response-rewrite.lua
 ##########
 @@ -0,0 +1,99 @@
+--
+-- 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 plugin_name = "response-rewrite"
+local ngx         = ngx
+local pairs       = pairs
+
+
+local schema = {
+    type = "object",
+    properties = {
+        headers = {
+            description = "new headers for repsonse",
+            type = "object",
+            minProperties = 1,
+        },
+        body    =   {
+            description = "new body for repsonse",
+            type = "string",
+        },
+    },
+    minProperties = 1,
+}
+
+
+local _M = {
+    version  = 0.1,
+    priority = 899,
+    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
+
+    --reform header from object into array, so can avoid use pairs, which is NYI
+    if conf.headers then
+        conf.headers_for_jit = {}
+        for field, value in pairs(conf.headers) do
+            core.table.insert(conf.headers_for_jit, field)
+            core.table.insert(conf.headers_for_jit, value)
+        end
+    end
+
+    return true
+end
+
+
+do
+
+function _M.body_filter(conf, ctx)
 
 Review comment:
   I didn't got your points

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services