Module: EventStore::HTTP::Session::LogText

Defined in:
lib/event_store/http/session/log_text.rb

Class Method Summary collapse

Class Method Details

.body_data(message) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/event_store/http/session/log_text.rb', line 33

def self.body_data(message)
  if message.body.to_s.empty?
    '(no body)'
  else
    message.body
  end
end

.header_data(message) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/event_store/http/session/log_text.rb', line 15

def self.header_data(message)
  text = String.new

  if message['host']
    text << "host: #{message['host']}\n"
  end

  message.each_header do |name, value|
    next if name == 'host'

    text << "#{name}: #{value}\n"
  end

  text << "(no headers)" if text.empty?

  text
end

.request(request, response = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/event_store/http/session/log_text.rb', line 5

def self.request(request, response=nil)
  text = %[Action: #{request.method}, Path: #{request.path}, RequestLength: #{request.body&.bytesize.to_i}]

  unless response.nil?
    text << %[, StatusCode: #{response.code}, ReasonPhrase: #{response.message}, ResponseLength: #{response.body&.bytesize.to_i}]
  end

  text
end