Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rewrite:RespHeaders and modify the upstream response headers via request implementation #6426

Merged
merged 10 commits into from
Mar 4, 2022

Conversation

rampagecong
Copy link
Contributor

@rampagecong rampagecong commented Feb 23, 2022

What this PR does / why we need it:

This PR add the ability to call upstream server when change the response header.
When we implement SSO, we can set and modify cookie in APISIX plugin layer and also call upstream at the same time.

This is refer to apache/apisix-go-plugin-runner#67

ext-plugin-proto : api7/ext-plugin-proto#26
apisix-go-plugin-runner : apache/apisix-go-plugin-runner#68

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@tzssangglass
Copy link
Member

need to update

"ext-plugin-proto = 0.3.0",

to 0.4.0

ref: https://github.com/api7/ext-plugin-proto/releases/tag/v0.4.0

Copy link
Member

@spacewander spacewander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a test like:

=== TEST 7: rewrite args

You can prepare data for the mock runner in:

elseif case.rewrite_args == true or case.rewrite_args_only == true then

You can refer to https://github.com/apache/apisix/blob/master/docs/en/latest/internal/testing-framework.md for how to write/run test.

For example,

Check response headers.

--- response_headers
X-Resp: foo
X-Req: foo, bar

@rampagecong
Copy link
Contributor Author

rampagecong commented Feb 28, 2022

The test cases can't be run in both my two centos machines(follow the step in docs). So I have to try follow the exsisting cases and push code to ci to verify it.

[root@localdev apisix]# make test make test [ info ] test -> [ Start ] git submodule update --init --recursive prove -I../test-nginx/lib -I./ -r -s t/ t/node/remote-addr.t ............................ nginx: [error] init_by_lua error: /data/service/test/apisix/deps/share/lua/5.1/protoc.lua:1148: attempt to call field 'load' (a nil value) stack traceback: /data/service/test/apisix/deps/share/lua/5.1/protoc.lua:1148: in function </data/service/test/apisix/deps/share/lua/5.1/protoc.lua:1147> /data/service/test/apisix/deps/share/lua/5.1/protoc.lua:1192: in main chunk [C]: in function 'require' ...vice/test/apisix/apisix/plugins/grpc-transcode/proto.lua:20: in main chunk [C]: in function 'require' /data/service/test/apisix/apisix/admin/proto.lua:23: in main chunk [C]: in function 'require' /data/service/test/apisix/apisix/admin/init.lua:51: in main chunk [C]: in function 'require' /data/service/test/apisix/apisix/init.lua:34: in main chunk [C]: in function 'require' init_by_lua:9: in main chunk

@spacewander

t/lib/ext-plugin.lua Outdated Show resolved Hide resolved
rampagecong and others added 3 commits February 28, 2022 20:49
OK

Co-authored-by: 帅进超 <shuaijinchao@gmail.com>
fix: rename
@rampagecong
Copy link
Contributor Author

[root@iZbp1efn5vn52xspp2bid5Z apisix]# make test [ info ] test -> [ Start ] git submodule update --init --recursive prove -I../test-nginx/lib -I./ -r -s t/ t/stream-node/sni.t ............................. nginx: [error] init_by_lua error: error loading module 'ssl.core' from file '/opt/service/test/apisix/deps/lib/lua/5.1/ssl.so': /opt/service/test/apisix/deps/lib/lua/5.1/ssl.so: undefined symbol: sk_free stack traceback: [C]: at 0x7f6b5dc70a20 [C]: in function 'require' /opt/service/test/apisix/deps/share/lua/5.1/ssl.lua:8: in main chunk [C]: in function 'require' /opt/service/test/apisix/apisix/patch.lua:22: in main chunk [C]: in function 'require' /opt/service/test/apisix/apisix/init.lua:28: in main chunk [C]: in function 'require' init_by_lua:9: in main chunk

@spacewander
Copy link
Member

[root@iZbp1efn5vn52xspp2bid5Z apisix]# make test [ info ] test -> [ Start ] git submodule update --init --recursive prove -I../test-nginx/lib -I./ -r -s t/ t/stream-node/sni.t ............................. nginx: [error] init_by_lua error: error loading module 'ssl.core' from file '/opt/service/test/apisix/deps/lib/lua/5.1/ssl.so': /opt/service/test/apisix/deps/lib/lua/5.1/ssl.so: undefined symbol: sk_free stack traceback: [C]: at 0x7f6b5dc70a20 [C]: in function 'require' /opt/service/test/apisix/deps/share/lua/5.1/ssl.lua:8: in main chunk [C]: in function 'require' /opt/service/test/apisix/apisix/patch.lua:22: in main chunk [C]: in function 'require' /opt/service/test/apisix/apisix/init.lua:28: in main chunk [C]: in function 'require' init_by_lua:9: in main chunk

@shuaijinchao
Would you provide help to solve the OpenSSL problem?

@rampagecong
Copy link
Contributor Author

`[root@iZbp1efn5vn52xspp2bid5Z apisix]# prove -I../test-nginx/lib -I./ -r -s t/plugin/ext-plugin/http-req-call.t
t/plugin/ext-plugin/http-req-call.t .. nginx: [warn] stream [lua] health_check.lua:99: report_failure(): update endpoint: http://127.0.0.1:2379 to unhealthy
nginx: [warn] stream [lua] v3.lua:151: _request_uri(): http://127.0.0.1:2379: connection refused. Retrying
nginx: [error] stream [lua] init.lua:822: stream_init(): failed to load the configuration: has no healthy etcd endpoint available
nginx: [warn] [lua] health_check.lua:99: report_failure(): update endpoint: http://127.0.0.1:2379 to unhealthy
nginx: [warn] [lua] v3.lua:151: _request_uri(): http://127.0.0.1:2379: connection refused. Retrying
nginx: [error] [lua] init.lua:86: http_init(): failed to load the configuration: has no healthy etcd endpoint available
t/plugin/ext-plugin/http-req-call.t .. 1/?

Failed test 'TEST 7: rewrite args - status code ok'

at /opt/service/test/apisix/../test-nginx/lib/Test/Nginx/Socket.pm line 948.

got: '404'

expected: '200'

Failed test 'TEST 7: rewrite args - response_body - response is expected (repeated req 0, req 0)'

at /opt/service/test/apisix/../test-nginx/lib/Test/Nginx/Socket.pm line 1589.

@@ -1,3 +1 @@

-uri: /plugin_proxy_rewrite_args

+{"error_msg":"404 Route Not Found"}

-a: foo,bar

-c: bar`

'TEST 7' also failed. Is there a problem with setting it?Please help me.
@shuaijinchao

@shuaijinchao
Copy link
Member

shuaijinchao commented Mar 1, 2022

@rampagecong OK, I need some time to check this question and get back to you later.

@rampagecong
Copy link
Contributor Author

[root@iZbp1efn5vn52xspp2bid5Z apisix]# prove -I. -I../test-nginx/inc -I../test-nginx/lib -r t/plugin/ext-plugin/http-req-call.t t/plugin/ext-plugin/http-req-call.t .. ok All tests successful. Files=1, Tests=18, 2 wallclock secs ( 0.02 usr 0.00 sys + 0.39 cusr 0.10 csys = 0.51 CPU) Result: PASS

Successfully!

fix: Optimize the code
@spacewander spacewander merged commit c4229d1 into apache:master Mar 4, 2022
@lijing-21
Copy link
Contributor

Hi @rampagecong , thank you for your contribution!

Here is the Contributor T-shirt form[1], if you're interested, kindly take a look :)

[1] https://github.com/apache/apisix/blob/master/CONTRIBUTING.md#contributor-t-shirt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants