Class: HttpStore::Middleware::RequestLog
- Inherits:
-
Object
- Object
- HttpStore::Middleware::RequestLog
show all
- Includes:
- Helpers::Storable
- Defined in:
- lib/http_store/middleware/request_log.rb
Constant Summary
collapse
- STRING_LIMIT_SIZE =
30_000
Helpers::Storable::TEXT_LIMIT_SIZE
Instance Method Summary
collapse
#gen_storable_meta, #json_safe_parse, #load_storeable_record, #storable, #storable_string, #store_class, #store_request, #storeable_record, #use_cache?
Constructor Details
Returns a new instance of RequestLog.
8
9
10
|
# File 'lib/http_store/middleware/request_log.rb', line 8
def initialize(app)
@app = app
end
|
Instance Method Details
20
21
22
23
24
25
|
# File 'lib/http_store/middleware/request_log.rb', line 20
def build_meta(env, status, , body)
request = ActionDispatch::Request.new(env)
@meta = Hashie::Mash.new(format_req(request))
@meta.merge!(format_rsp(status, , body))
end
|
#call(env) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/http_store/middleware/request_log.rb', line 12
def call(env)
status, , body = @app.call(env)
[status, , body]
ensure
build_meta(env, status, , body)
store_request
end
|
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/http_store/middleware/request_log.rb', line 27
def format_req(request)
{
url: request.url,
path: request.path,
http_method: request.request_method,
data: request.params,
client_type: request.params[:client_type],
is_system: true,
headers: request..select { |k, _v| k.start_with? 'HTTP_' }.to_h,
query_params: request.query_parameters,
force: true,
}
end
|
41
42
43
44
45
46
47
|
# File 'lib/http_store/middleware/request_log.rb', line 41
def format_rsp(status, , body)
{
status_code: status,
response_headers: ,
response: body.try(:body) || body
}
end
|