emptygif
语言: 简体中文

所有语言和框架

Envoy (direct_response) YAML

一个用于 Envoy (direct_response) 的 YAML 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。

Envoy (direct_response) YAML

文件
envoy.yaml
运行
envoy -c envoy.yaml
static_resources:
  listeners:
    - name: http
      address:
        socket_address: { address: 0.0.0.0, port_value: 8080 }
      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                stat_prefix: ingress
                http_filters:
                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
                route_config:
                  virtual_hosts:
                    - name: default
                      domains: ["*"]
                      routes:
                        - match: { path: "/pixel.gif" }
                          direct_response:
                            status: 200
                            # bytes fields are base64 in YAML/JSON
                            body: { inline_bytes: "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" }
                          response_headers_to_add:
                            - header: { key: content-type, value: image/gif }
                              append_action: OVERWRITE_IF_EXISTS_OR_ADD
                            - header: { key: cache-control, value: no-store }
                              append_action: OVERWRITE_IF_EXISTS_OR_ADD

我们运行了此代码片段,并比对了它返回的字节。

验证

curl -sI http://localhost:8080/pixel.gif

官方网站: Envoy (direct_response)