istio / istio.io

Source for the istio.io site
https://istio.io/
Apache License 2.0
761 stars 1.54k forks source link

clarify documentation on headers in HTTPMatchRequest #7622

Open garfieldnate opened 4 years ago

garfieldnate commented 4 years ago

The documentation in question is here: https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPMatchRequest

If the value is empty and only the name of header is specfied, presence of the header is checked.

Reading this, we thought the YAML file should contain no value for the header name entry itself, like so:

  http:
  - match:
      - headers:
          # just check for the presence of the header "my-header"
          my-header:

The key is my-header and the value is NULL. We could also have put in ~ to get the same result. However, istioctl did not like this:

istioctl validate -f istio-test.yaml
Error: 1 error occurred:
    * VirtualService/mp-namespace/my-service: header match my-header cannot be null

There are plenty of YAML parsers out there that can't handle NULL map values, so the next thing we tried was an empty string:

  http:
  - match:
      - headers:
          my-header: ""

However, this lead to another error:

json: cannot unmarshal string into Go value of type map[string]json.RawMessage

Our current guess is that the following is correct:

  http:
  - match:
      - headers:
          my-header: 
            exact: ""

However, reading this is confusing because it looks like a rule that matches when my-header is present and the value is exactly the empty string.

The documentation needs to be updated to clarify the correct structure for matching on the presence of headers. I will gladly update the English documentation for this, but first I need confirmation on exactly what YAML structure to use in this case.

hbeffge commented 4 years ago

Same issue here. I just tried with prefix instead of exact and ended up with PrefixMatch: ["value length must be at least " '\x01' " bytes"]) in the log. Changed it to exact and it seems to work as intended.

jasondamour commented 2 years ago

I had some success with this format:

  - match:                                                                                                                                                                              
    - headers:                                                                                                                                                                          
        my-header: {}