def add_device_type_header()

in callouts/python/extproc/example/normalize_header/service_callout_example.py [0:0]


  def add_device_type_header(
      self, headers: service_pb2.HttpHeaders) -> service_pb2.HeadersResponse:
    """Generate a client-device-type header response.

    Args:
      headers: Current headers presented in the callout.
    Returns:
      The constructed HeadersResponse object.
    """

    host_value = next((header.raw_value.decode('utf-8')
                       for header in headers.headers.headers
                       if header.key == ':authority'), None)

    header_mutation = service_pb2.HeadersResponse()

    if host_value:
      device_type = get_device_type(host_value)
      header_mutation = callout_tools.add_header_mutation(
          add=[('client-device-type', device_type)], clear_route_cache=True)

    return header_mutation