Skip to content

direct_response: Content-Type is always text/plain and ignores body_format config #43680

@marvin-roesch

Description

@marvin-roesch

Title: When using a direct_response route action with body_format (introduced in #41821), the response Content-Type header is always text/plain regardless of the format configuration

Description:
The SubstitutionFormatString API allows setting a content_type, defaulting to text/plain for a text format and applicaton/json for a JSON format. Using this config option in a direct_response route action's body_format will not result in the route's response having the configured Content-Type header. Instead, text/plain is always returned.

Repro steps:

  1. Configure a route with direct_response action and body_format with content_type: "application/json" configured
  2. Make a GET request to that route
  3. Observe that Content-Type in the response is text/plain

Config:

static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address: { address: 0.0.0.0, port_value: 10000 }
      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
                codec_type: AUTO
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: direct_response
                      domains: ["*"]
                      routes:
                        - match: { prefix: "/" }
                          direct_response:
                            status: 200
                            body_format:
                              content_type: "text/html"
                              text_format_source:
                                inline_string: "<strong>Request Path:</strong> %REQ(:path)%"
                http_filters:
                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

I was not sure whether to file this as a bug or a feature request, since the PR implementing this feature (#41821) did not even intend to address this directly. I decided for bug considering that as a user, I generally only see the API surface which does present me with the content_type option.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions