Class: Foam::Otel::PayloadCapture::InputTee

Inherits:
Object
  • Object
show all
Defined in:
lib/foam/otel/payload_capture.rb

Overview

The delegating rack.input tee: observes what the APP reads through the three Rack-SPEC input methods, delegates EVERYTHING else untouched (rewind/size/close/read_nonblock… exist exactly iff the underlying input has them — respond_to? stays truthful, so a Rack 3 non-rewindable input still reports itself non-rewindable). Never reads ahead, never rewinds on its own.

Constant Summary collapse

REPOSITION_METHODS =

EVERY repositioning method is tracked for the re-read dedupe — a middleware that repositions via seek(0) or pos= 0 instead of rewind (all three are common Rack::MethodOverride-shape idioms on the rewindable inputs real servers hand out) must not make the framework's re-read double-capture the body.

%i[rewind seek pos=].freeze

Instance Method Summary collapse

Constructor Details

#initialize(io, acc) ⇒ InputTee

Returns a new instance of InputTee.



522
523
524
525
# File 'lib/foam/otel/payload_capture.rb', line 522

def initialize(io, acc)
  @io = io
  @acc = acc
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object



548
549
550
551
552
# File 'lib/foam/otel/payload_capture.rb', line 548

def method_missing(name, *args, **kwargs, &block)
  result = @io.__send__(name, *args, **kwargs, &block)
  @acc.note_position(position_after(name, args)) if REPOSITION_METHODS.include?(name)
  result
end

Instance Method Details

#each(*args, &block) ⇒ Object



539
540
541
542
543
544
545
546
# File 'lib/foam/otel/payload_capture.rb', line 539

def each(*args, &block)
  return enum_for(:each, *args) unless block

  @io.each(*args) do |chunk|
    @acc.observe(chunk)
    yield chunk
  end
end

#gets(*args) ⇒ Object



533
534
535
536
537
# File 'lib/foam/otel/payload_capture.rb', line 533

def gets(*args)
  line = @io.gets(*args)
  @acc.observe(line)
  line
end

#read(*args) ⇒ Object



527
528
529
530
531
# File 'lib/foam/otel/payload_capture.rb', line 527

def read(*args)
  result = @io.read(*args)
  @acc.observe(result)
  result
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


554
555
556
# File 'lib/foam/otel/payload_capture.rb', line 554

def respond_to_missing?(name, include_private = false)
  @io.respond_to?(name, include_private)
end