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: allow sending headers upstream returned by OPA server #9710

Merged
merged 11 commits into from
Jul 19, 2023

Conversation

Revolyssup
Copy link
Contributor

@Revolyssup Revolyssup commented Jun 21, 2023

Description

Fixes #9704

Documentation to be updated

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@monkeyDluffy6017
Copy link
Contributor

monkeyDluffy6017 commented Jun 26, 2023

Please make the ci pass and no test cases?

@monkeyDluffy6017 monkeyDluffy6017 added the wait for update wait for the author's response in this issue/PR label Jun 26, 2023
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@Revolyssup
Copy link
Contributor Author

Please make the ci pass and no test cases?

Added test case @monkeyDluffy6017

Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@lingsamuel lingsamuel removed the wait for update wait for the author's response in this issue/PR label Jun 26, 2023
lingsamuel
lingsamuel previously approved these changes Jun 26, 2023
@Revolyssup
Copy link
Contributor Author

Comment on lines 130 to 134
else if conf.send_header_upstream and result.headers then
for key,value in pairs(result.headers) do
core.request.set_header(ctx,key,value)
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to proxy all of opa's request headers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What else do you propose? How to select which ones to proxy?

Copy link
Contributor

Choose a reason for hiding this comment

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

what HTTP header should pass upstream? instead of forwarding all HTTP header

@Sn0rt
Copy link
Contributor

Sn0rt commented Jul 7, 2023

@chusov pls help us take a look

@chusov
Copy link

chusov commented Jul 10, 2023

Maybe add a parameter with a list of headers?
send_header_upstream_list

@Revolyssup
Copy link
Contributor Author

Maybe add a parameter with a list of headers? send_header_upstream_list

@monkeyDluffy6017 What do you think about this?

@monkeyDluffy6017
Copy link
Contributor

@chusov i think the headers that need to be passed to upstream from OPA server should be fixed, what headers do you exactly need?

@chusov
Copy link

chusov commented Jul 11, 2023

@monkeyDluffy6017
at the moment it is enough X-Username, in the future there were plans to add more depending on the service

@monkeyDluffy6017
Copy link
Contributor

Maybe add a parameter with a list of headers? send_header_upstream_list

@monkeyDluffy6017 What do you think about this?

LGTM

@Revolyssup
Copy link
Contributor Author

Maybe add a parameter with a list of headers? send_header_upstream_list

@monkeyDluffy6017 What do you think about this?

LGTM

Okay I'm making the change. @Sn0rt This one change remaining as suggested above by user

Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Comment on lines 40 to 47
send_headers_upstream = {
type = "array",
minItems = 0,
items = {
type = "string"
},
description = "list of headers to pass to upstream in request"
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
send_headers_upstream = {
type = "array",
minItems = 0,
items = {
type = "string"
},
description = "list of headers to pass to upstream in request"
},
send_headers_upstream = {
type = "array",
minItems = 1,
items = {
type = "string"
},
description = "list of headers to pass to upstream in request"
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 136 to 147
else if result.headers and #conf.send_headers_upstream > 0 then
local headersToSend = {}
for key in pairs(conf.send_headers_upstream) do
headersToSend[key] = true
end
for key,value in pairs(result.headers) do
if headersToSend[key] then
core.request.set_header(ctx,key,value)
end

end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
else if result.headers and #conf.send_headers_upstream > 0 then
local headersToSend = {}
for key in pairs(conf.send_headers_upstream) do
headersToSend[key] = true
end
for key,value in pairs(result.headers) do
if headersToSend[key] then
core.request.set_header(ctx,key,value)
end
end
end
else if result.headers and conf.send_headers_upstream then
local headersToSend = {}
for key in pairs(conf.send_headers_upstream) do
headersToSend[key] = true
end
for key,value in pairs(result.headers) do
if headersToSend[key] then
core.request.set_header(ctx,key,value)
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

The indent is not right, only four spaces are needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@monkeyDluffy6017 monkeyDluffy6017 added wait for update wait for the author's response in this issue/PR and removed discuss labels Jul 18, 2023
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
for key in pairs(conf.send_headers_upstream) do
headersToSend[key] = true
end
for key,value in pairs(result.headers) do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for key,value in pairs(result.headers) do
for key, value in pairs(result.headers) do
if headersToSend[key] then
core.request.set_header(ctx,key,value)
end

Copy link
Contributor

Choose a reason for hiding this comment

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

No blank is needed

end
for key,value in pairs(result.headers) do
if headersToSend[key] then
core.request.set_header(ctx,key,value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
core.request.set_header(ctx,key,value)
core.request.set_header(ctx, key, value)
Copy link
Contributor

@monkeyDluffy6017 monkeyDluffy6017 Jul 18, 2023

Choose a reason for hiding this comment

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

I think you could refactor this block like this:

        for _, name in ipairs(conf.send_headers_upstream) do
            if result.headers[name] then
                core.request.set_header(ctx, name, value)
            end
        end
Copy link
Contributor Author

@Revolyssup Revolyssup Jul 18, 2023

Choose a reason for hiding this comment

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

Makes more sense. Done

Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@monkeyDluffy6017 monkeyDluffy6017 added approved and removed wait for update wait for the author's response in this issue/PR labels Jul 18, 2023
@monkeyDluffy6017 monkeyDluffy6017 merged commit 79b24cd into apache:master Jul 19, 2023
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6 participants