{"id":10299,"date":"2019-05-20T17:42:20","date_gmt":"2019-05-20T15:42:20","guid":{"rendered":"https:\/\/pi3g.com\/?p=10299"},"modified":"2019-05-20T17:42:20","modified_gmt":"2019-05-20T15:42:20","slug":"envoy-serving-a-static-response","status":"publish","type":"post","link":"https:\/\/pi3g.com\/de\/envoy-serving-a-static-response\/","title":{"rendered":"Abgesandter, der eine statische Antwort liefert"},"content":{"rendered":"<p>Besides routing and redirecting you can serve static responses with Envoy.<\/p>\n<p>In this case I want to serve a forbidden response (403)<\/p>\n<blockquote>\n<p>route_config:<br \/>&nbsp;&nbsp; virtual_hosts:<br \/>&nbsp;&nbsp; &#8211; name: picockpit<br \/>&nbsp;&nbsp;&nbsp;&nbsp; domains: [&#8220;picockpit.local:443&#8221;, &#8220;picockpit.local&#8221;]<br \/>&nbsp;&nbsp;&nbsp;&nbsp; routes:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; match: { prefix: &#8220;\/demo&#8221; }<br \/><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; direct_response:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; status: 403<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; body:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inline_string: &#8220;Forbidden.&#8221;<\/strong> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; match: {prefix: &#8220;\/&#8221;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; route: {cluster: target_picockpit}<\/p>\n<\/blockquote>\n<p>It can also serve up files from the local filesystem as a response.<\/p>\n<h3>Ref:<\/h3>\n<ul>\n<li><a href=\"https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/api-v2\/api\/v2\/core\/base.proto#envoy-api-msg-core-datasource\">https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/api-v2\/api\/v2\/core\/base.proto#envoy-api-msg-core-datasource<\/a><\/li>\n<li>\n<a href=\"https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/api-v2\/api\/v2\/route\/route.proto#envoy-api-msg-route-directresponseaction\">https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/api-v2\/api\/v2\/route\/route.proto#envoy-api-msg-route-directresponseaction<\/a><\/li>\n<li><a href=\"https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/api-v2\/api\/v2\/route\/route.proto#envoy-api-msg-route-route\">https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/api-v2\/api\/v2\/route\/route.proto#envoy-api-msg-route-route<\/a><\/li>\n<\/ul>\n<p><\/p>\n<p><\/p>\n<p>PS. If you get the error<\/p>\n<p> error initializing configuration &#8216;\/etc\/envoy\/envoy.yaml&#8217;: Unable to parse JSON as proto (INVALID_ARGUMENT:(route_config.virtual_hosts[0].routes[2].direct_response.body): invalid value &#8220;Forbidden.&#8221; for type type.googleapis.com\/envoy.api.v2.core.DataSource), you are trying to set the string directly on body \u2013 you have to set it as a sub-value of inline_string of body. see my sample above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Besides routing and redirecting you can serve static responses with Envoy. In this case I want to serve a forbidden response (403) route_config:&nbsp;&nbsp; virtual_hosts:&nbsp;&nbsp; &#8211; name: picockpit&nbsp;&nbsp;&nbsp;&nbsp; domains: [&#8220;picockpit.local:443&#8221;, &#8220;picockpit.local&#8221;]&nbsp;&nbsp;&nbsp;&nbsp; routes:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; match: { prefix: &#8220;\/demo&#8221; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; direct_response:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; status: 403&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; body:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inline_string: &#8220;Forbidden.&#8221; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; match: {prefix: &#8220;\/&#8221;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; route: {cluster: target_picockpit} It can also serve&hellip;<\/p>\n","protected":false},"author":830,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[402],"tags":[614,481,615,616],"class_list":["post-10299","post","type-post","status-publish","format-standard","hentry","category-development","tag-614","tag-envoy","tag-forbidden","tag-static"],"_links":{"self":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/10299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/users\/830"}],"replies":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/comments?post=10299"}],"version-history":[{"count":1,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/10299\/revisions"}],"predecessor-version":[{"id":10300,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/10299\/revisions\/10300"}],"wp:attachment":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/media?parent=10299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/categories?post=10299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/tags?post=10299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}