Class: PactBroker::Test::HttpTestDataBuilder::SetRequestId

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/pact_broker/test/http_test_data_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, correlation_id, logger) ⇒ SetRequestId

Returns a new instance of SetRequestId.



13
14
15
16
17
# File 'lib/pact_broker/test/http_test_data_builder.rb', line 13

def initialize(app, correlation_id, logger)
  super(app)
  @correlation_id = correlation_id
  @logger = logger
end

Instance Method Details

#on_request(env) ⇒ Object



19
20
21
22
23
# File 'lib/pact_broker/test/http_test_data_builder.rb', line 19

def on_request(env)
  request_id = "#{@correlation_id}-#{Time.now.to_f.to_s[7... -1]}"
  env.request_headers["X-Request-Id"] = request_id
  @logger.info("X-Request-Id: #{request_id}")
end