// Copyright 2025 Envoy Project Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package envoy.data.tap.v3;

import "envoy/config/core/v3/base.proto";
import "envoy/data/tap/v3/common.proto";

import "google/protobuf/timestamp.proto";

import "udpa/annotations/status.proto";
import "udpa/annotations/versioning.proto";

option java_package = "io.envoyproxy.envoy.data.tap.v3";
option java_outer_classname = "HttpProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/data/tap/v3;tapv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: HTTP tap data]

// A fully buffered HTTP trace message.
message HttpBufferedTrace {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.data.tap.v2alpha.HttpBufferedTrace";

  // HTTP message wrapper.
  message Message {
    option (udpa.annotations.versioning).previous_message_type =
        "envoy.data.tap.v2alpha.HttpBufferedTrace.Message";

    // Message headers.
    repeated config.core.v3.HeaderValue headers = 1;

    // Message body.
    Body body = 2;

    // Message trailers.
    repeated config.core.v3.HeaderValue trailers = 3;

    // The timestamp after receiving the message headers.
    google.protobuf.Timestamp headers_received_time = 4;
  }

  // Request message.
  Message request = 1;

  // Response message.
  Message response = 2;

  // downstream connection
  Connection downstream_connection = 3;
}

// A streamed HTTP trace segment. Multiple segments make up a full trace.
// [#next-free-field: 8]
message HttpStreamedTraceSegment {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.data.tap.v2alpha.HttpStreamedTraceSegment";

  // Trace ID unique to the originating Envoy only. Trace IDs can repeat and should not be used
  // for long term stable uniqueness.
  uint64 trace_id = 1;

  oneof message_piece {
    // Request headers.
    config.core.v3.HeaderMap request_headers = 2;

    // Request body chunk.
    Body request_body_chunk = 3;

    // Request trailers.
    config.core.v3.HeaderMap request_trailers = 4;

    // Response headers.
    config.core.v3.HeaderMap response_headers = 5;

    // Response body chunk.
    Body response_body_chunk = 6;

    // Response trailers.
    config.core.v3.HeaderMap response_trailers = 7;
  }
}
