8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/influxdb/rails/httplog/adapters/net_http.rb', line 8
def request(req, body = nil, &block)
url = "http://#{@address}:#{@port}#{req.path}"
req['Al-Request-Client-Id'] = SecureRandom.uuid
req['al-source'] = Thread.current["al_request_id"] if Thread.current["al_request_id"]
timestamp = nil
bm = Benchmark.realtime do
timestamp= Time.now.to_i
@response = orig_request(req, body, &block)
end
c = InfluxDB::Rails.configuration
is_influxdb = (c.influxdb_hosts.include? @address ) && (@port == c.influxdb_port)
if !is_influxdb && (HttpLog.url_approved?(url) && started?)
HttpLog.save_in_db(
method: req.method,
url: url,
timestamp: timestamp,
request_body: req.body.nil? || req.body.empty? ? body : req.body,
request_headers: req..collect,
response_code: @response.code,
response_body: @response.body,
response_headers: @response..collect,
benchmark: bm,
encoding: @response['Content-Encoding'],
content_type: @response['Content-Type']
)
end
@response
end
|