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 response header rewrite via Ingress annotations #1861

Merged
merged 3 commits into from Jun 29, 2023

Conversation

Revolyssup
Copy link
Contributor

@Revolyssup Revolyssup commented Jun 13, 2023

Type of change:

  • New feature provided
  • Documentation
  • CI/CD or Tests

What this PR does / why we need it:

Allows users to use the header manipulation feature of response-rewrite plugin in APISIX via annotations in Ingress resource. Solves #1860

Example
Case 1: Remove Server header

# use v1beta1 if your Kubernetes cluster version is older than v1.19.0
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: httpserver-ingress
  annotations:
    k8s.apisix.apache.org/response-rewrite-remove-header: "Server"
    k8s.apisix.apache.org/enable-response-rewrite: "true"
spec:
  # we use APISIX Ingress and it watches Ingress resources with "apisix" ingressClassName
  ingressClassName: apisix
  rules:
  - host: mockbin.org
    http:
      paths:
      - backend:
          service:
            name: httpbin

            port:
              number: 80
        path: / 
        pathType: Prefix

No server header in response
testdel


Case 2: Adding headers

# use v1beta1 if your Kubernetes cluster version is older than v1.19.0
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: httpserver-ingress
  annotations:
    k8s.apisix.apache.org/response-rewrite-add-header: "testkey1:testval1,testkey2:testval2"
    k8s.apisix.apache.org/enable-response-rewrite: "true"
spec:
  # we use APISIX Ingress and it watches Ingress resources with "apisix" ingressClassName
  ingressClassName: apisix
  rules:
  - host: mockbin.org
    http:
      paths:
      - backend:
          service:
            name: httpbin

            port:
              number: 80
        path: / 
        pathType: Prefix

testset

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

Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
@tao12345666333 tao12345666333 added this to the 1.8.0 milestone Jun 16, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #1861 (cbf02d1) into master (7540872) will increase coverage by 0.04%.
The diff coverage is 100.00%.

❗ Current head cbf02d1 differs from pull request most recent head ce809e5. Consider uploading reports for the commit ce809e5 to get more accurate results

@@            Coverage Diff             @@
##           master    #1861      +/-   ##
==========================================
+ Coverage   39.82%   39.87%   +0.04%     
==========================================
  Files          92       92              
  Lines        7261     7266       +5     
==========================================
+ Hits         2892     2897       +5     
  Misses       3985     3985              
  Partials      384      384              
Impacted Files Coverage Δ
...ranslation/annotations/plugins/response_rewrite.go 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tao12345666333
Copy link
Member

Thanks! I will re-run the failed job.

@Gallardot Gallardot merged commit e809cfb into apache:master Jun 29, 2023
86 of 89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants