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

HTTP header key formatted problem #12395

Open
66li opened this issue Nov 21, 2024 · 17 comments
Open

HTTP header key formatted problem #12395

66li opened this issue Nov 21, 2024 · 17 comments
Labels
kind/support Categorizes issue or PR as a support question. needs-priority needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@66li
Copy link

66li commented Nov 21, 2024

Expecting to convert all HTTP keys to lowercase, but in reality, this does not work,
Is there an existing solution for reference

@66li 66li added the kind/bug Categorizes issue or PR as related to a bug. label Nov 21, 2024
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Nov 21, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If Ingress contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@66li
Copy link
Author

66li commented Nov 21, 2024

i need help

@longwuyuan
Copy link
Contributor

  • Look at the template of a new bug report
  • Edit this issue description and answer those questions here in this issue description
  • Ensure to use markdown format
  • Give some examples
  • Search github for other users having attempted it
  • One good example is geop2 related configs injected into the nginx.conf for variables

This having data, context, links and elaborate descriptions can help draw attention as there are hardly any resources here.

You can even get more people to look at your messages on kubernetes.slack.com in the ingress-nginx-users channel (register at slack.k8s.io if needed)

/remove-kind bug
/kind support

@k8s-ci-robot k8s-ci-robot added kind/support Categorizes issue or PR as a support question. and removed kind/bug Categorizes issue or PR as related to a bug. labels Nov 21, 2024
@66li
Copy link
Author

66li commented Nov 24, 2024

When I use curl https://example.com -H "CC: bb"
I hope that the request header received by the backend service after forwarding through nginx ingress is
cc: bb
In fact, nginx did not do any processing, and the HTTP header received by the backend service is CC: bb

@longwuyuan
Copy link
Contributor

longwuyuan commented Nov 24, 2024 via email

@66li
Copy link
Author

66li commented Nov 24, 2024

I want to format the key in nginx ingress
curl https://example.com -H "CC: bb"
Backend service received
cc: bb

@66li
Copy link
Author

66li commented Nov 24, 2024

This background is my team's migration from Istio provided by cloud service providers to nginx
The default configuration of Istio is to lowercase all http header key

@longwuyuan
Copy link
Contributor

longwuyuan commented Nov 24, 2024 via email

@66li
Copy link
Author

66li commented Nov 24, 2024

It seems that,
I tried using Lua script but it didn't work

@66li
Copy link
Author

66li commented Nov 24, 2024

 k get cm headers-lower -o yaml
apiVersion: v1
data:
  headers_lower.lua: |
    local headers = ngx.req.get_headers()
    local lower_headers = {}

    for key, value in pairs(headers) do
        local lower_key = string.lower(key)
        lower_headers[lower_key] = value
    end

    ngx.req.clear_header()
    for key, value in pairs(lower_headers) do
        ngx.req.set_header(key, value)
    end
    ngx.req.set_header("X-Custom-Header", "Hello, Lua Plugin!")
    ngx.req.set_header("AAX-Custom-Header", headers)
    ngx.log(ngx.DEBUG, headers)
kind: ConfigMap


k get cm nonprod-1-11-2-ingress-nginx-controller -o yaml
apiVersion: v1
data:
  allow-snippet-annotations: "true"
  server-snippet: |
    access_by_lua_file /etc/nginx/lua/headers_lower.lua;
kind: ConfigMap

@66li
Copy link
Author

66li commented Nov 24, 2024

 k get deploy  nonprod-1-11-2-ingress-nginx-controller -o yaml
         volumeMounts:
        - mountPath: /etc/nginx/lua/headers_lower.lua
          name: lua-scripts
          readOnly: true
          subPath: headers_lower.lua
       volumes:
      - configMap:
          defaultMode: 420
          items:
          - key: headers_lower.lua
            path: headers_lower.lua
          name: headers-lower
        name: lua-scripts

@66li
Copy link
Author

66li commented Nov 24, 2024

I think I'm not the only one who has encountered similar problems,
The default configuration of Istio is to format all HTTP header keys
I don't know if there is an elegant solution on nginx ingress

@longwuyuan
Copy link
Contributor

longwuyuan commented Nov 24, 2024 via email

@66li
Copy link
Author

66li commented Nov 24, 2024

ok
Can I use Lua script to implement this feature? I am a newcomer to Lua, so I need help

@66li 66li changed the title HTTP header key not formatted correctly HTTP header key formatted problem Nov 24, 2024
@longwuyuan
Copy link
Contributor

longwuyuan commented Nov 24, 2024 via email

@66li
Copy link
Author

66li commented Nov 24, 2024

ok
Is there any other way to achieve similar functionality,
Lowercase all the keys in the HTTP header

@longwuyuan
Copy link
Contributor

longwuyuan commented Nov 24, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question. needs-priority needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
Development

No branches or pull requests

3 participants