If you want to add the header to the request, add something like this:
headers:
request:
add:
name: test
If you want to add the header for all routes, put it just before the route: field.
If you only want it to be added to one of the routes, put it after the weight field of the corresponding route.
Your VirtualService is configuring the route for requests that have the name2=test-2 header. Your rule is also saying, btw, add the name=test header for requests taking this route.
So that will do what you want, but what’s missing in your VirtualService is what route to take when the name2=test-2 header is not present in the request. If you want it to take the same route just without adding your header, you need to add a complete copy of the rule (minus the header and match) and add it as a second rule. That’s not the nicest way to achieve your goal.
If you really want to add custom logic in the request path, it may be better to do it in the application code, or maybe using a policy adapter or an EnvoyFilter to do it.