endison1986 opened a new issue, #7072:
URL: https://github.com/apache/apisix/issues/7072

   ### Description
   
   When I try to use the CORS plugin in `Consumer`, I get an unexpected 
response header.
   So I analyzed the source code and tried to call `core.request.header(ctx, 
"Origin")` in `_M.header_filter`, and finally CORS worked normally.
   I speculated and confirmed that `_M.rewrite()` cannot be called in 
`Consumer`, but starting from 2.12.1, `APISIX` has modified its practice to get 
the ` in the request header in `_M.rewrite()` Origin` parameter, is this in 
line with the original intention of your design?
   
   当我尝试在`Consumer`中使用CORS插件时,我获得了一个预期外的响应头。
   
于是我分析了源码,并尝试在`_M.header_filter`中调用`core.request.header(ctx,"Origin")`,最终CORS正常的工作了。
   
我推测并印证了`_M.rewrite()`无法在`Consumer`中被调用,但是从2.12.1开始,`APISIX`修改了做法,在`_M.rewrite()`中获取请求头中的`Origin`参数,请问这是符合你们的设计初衷的么?
   
   ```lua
   function _M.rewrite(conf, ctx)
       -- save the original request origin as it may be changed at other phase
       ctx.original_request_origin = core.request.header(ctx, "Origin")
       if ctx.var.request_method == "OPTIONS" then
           return 200
       end
   end
   
   
   function _M.header_filter(conf, ctx)
       // modify here
       local req_origin = core.request.header(ctx, "Origin")
       -- local req_origin =  ctx.original_request_origin
       -- Try allow_origins first, if mismatched, try allow_origins_by_regex.
       local allow_origins
       allow_origins = process_with_allow_origins(conf, ctx, req_origin)
       if not match_origins(req_origin, allow_origins) then
           allow_origins = process_with_allow_origins_by_regex(conf, ctx, 
req_origin)
       end
       if allow_origins then
           ctx.cors_allow_origins = allow_origins
           set_cors_headers(conf, ctx)
       end
   end
   ```
   
   ### Environment
   
   - APISIX version (run `apisix version`):2.12.1
   - Operating system (run `uname -a`):Linux apisix-server-cd8564555-2njxg 
3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 
x86_64 GNU/Linux
   - OpenResty / Nginx version (run `openresty -V` or `nginx 
-V`):openresty/1.19.9.1
   - etcd version, if relevant (run `curl 
http://127.0.0.1:9090/v1/server_info`):
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to