question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add response headers documentation incorrect

See original GitHub issue

According to documentation add_response_headers accepts string, bool or object as shown in the example Mapping:

apiVersion: getambassador.io/v3alpha1
kind:  Mapping
metadata:
  name:  quote-backend
spec:
  prefix: /backend/
  add_response_headers:
    x-test-proto: "%PROTOCOL%"
    x-test-ip: "%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT%"
    x-test-static: This is a test header
    x-test-object:
      append: False
      value: this is from object header config
  service: quote

When using anything other than an object you receive error message:

error: error validating "mapping.yaml": error validating data: ValidationError(Mapping.spec.add_response_headers.x-test-proto): invalid type for io.getambassador.v3alpha1.Mapping.spec.add_response_headers: got "string", expected "map"; if you choose to ignore these errors, turn validation off with --validate=false

Looking at the CRD definitions (if my understanding is correct):

          spec:
            description: MappingSpec defines the desired state of Mapping
            properties:
              add_linkerd_headers:
                type: boolean
              add_request_headers:
                type: object
                x-kubernetes-preserve-unknown-fields: true
              add_response_headers:
                type: object
                x-kubernetes-preserve-unknown-fields: true

It looks like it only accepts an object.

Steps to reproduce the behavior:

  1. Create mapping example as shown in the documentation

This error is present on the latest version 2.2.2.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
so-amukcommented, Mar 26, 2022

Following solution worked for me

add_response_headers:
  Strict-Transport-Security:
    value: max-age=15724800

thanks @cindymullins-dw

2reactions
psalaberria002commented, Apr 25, 2022

This is still broken. @so-amuk 's solution works, but that’s just an alternative to defining the headers directly as strings. Even the docs mention both options are supported. The example from the docs isn’t working.

Is this a bug in the schema generation?

add_response_headers:
                additionalProperties:
                  properties:
                    append:
                      type: boolean
                    v2Representation:
                      enum:
                      - ""
                      - string
                      - "null"
                      type: string
                    value:
                      type: string
                  type: object
                type: object
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any documentation for response headers when ...
Hello. When we send request for data and put invalid attribute, we receive response with code 400 (Bad Reqeust). This is perfectly fine....
Read more >
How to troubleshoot the error "Failed to process response ...
In almost every event, this error is caused by a connection failure. The error is correct, the service did not receive any response...
Read more >
HTTP headers - MDN Web Docs - Mozilla
An HTTP header consists of its case-insensitive name followed by a colon ( : ), then by its value. Whitespace before the value...
Read more >
Code Inspection: Incorrect HTTP header - PhpStorm - JetBrains
Reports unknown HTTP headers that do not match any publicly known headers. The quick fix suggests adding the header to the list of...
Read more >
Adding HTTP headers to CloudFront responses
Use a response headers policy to specify the HTTP headers that Amazon CloudFront adds to HTTP responses.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found