grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.56k stars 762 forks source link

How to match an empty reponse body in hcm local reply filter? #1206

Open dandan2095 opened 2 years ago

dandan2095 commented 2 years ago

I'm trying to add a local response if there is no response body originally. My config is as below, but it doesn't seem to work very well. Is there an easy way to match a no-body response?

{
    "local_reply_config":{
        "mappers":[
            {
                "filter":{
                    "and_filter":{
                        "filters":[
                            {
                                "status_code_filter":{
                                    "comparison":{
                                        "op":"GE",
                                        "value":{
                                            "runtime_key":"400"
                                        }
                                    }
                                }
                            },
                            {
                                "or_filter":{
                                    "filters":[
                                        {
                                            "header_filter":{
                                                "header":{
                                                    "name":"content-length",
                                                    "present_match":false
                                                }
                                            }
                                        },
                                        {
                                            "and_filter":{
                                                "filters":[
                                                    {
                                                        "header_filter":{
                                                            "header":{
                                                                "name":"content-length",
                                                                "present_match":true
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "header_filter":{
                                                            "header":{
                                                                "name":"content-length",
                                                                "string_match":{
                                                                    "exact":"0"
                                                                }
                                                            }
                                                        }
                                                    }
                                                ]
                                            }
                                        }
                                    ]
                                }
                            },
                            {
                                "or_filter":{
                                    "filters":[
                                        {
                                            "header_filter":{
                                                "header":{
                                                    "name":"Transfer-Encoding",
                                                    "present_match":false
                                                }
                                            }
                                        },
                                        {
                                            "and_filter":{
                                                "filters":[
                                                    {
                                                        "header_filter":{
                                                            "header":{
                                                                "name":"Transfer-Encoding",
                                                                "present_match":true
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "header_filter":{
                                                            "header":{
                                                                "name":"Transfer-Encoding",
                                                                "string_match":{
                                                                    "exact":"chunked"
                                                                },
                                                                "invert_match":true
                                                            }
                                                        }
                                                    }
                                                ]
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                },
                "body_format_override":{
                    "text_format_source":{
                        "inline_string":"%RESP(message)%"
                    }
                }
            }
        ]
    }
}
dandan2095 commented 2 years ago

FIY: I'm using envoy 1.20.1