Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Add scheme to HTTPServerRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Feb 24, 2017
1 parent 024091a commit 5b17dd6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/timber/events/http_server_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module Events
#
# @note This event should be installed automatically through probes,
# such as the {Probes::ActionControllerLogSubscriber} probe.
class HTTPRequest < Timber::Event
class HTTPServerRequest < Timber::Event
attr_reader :host, :method, :path, :port, :query_params, :content_type,
:remote_addr, :referrer, :request_id, :user_agent
:remote_addr, :referrer, :request_id, :scheme, :user_agent

def initialize(attributes)
@host = attributes[:host] || raise(ArgumentError.new(":host is required"))
Expand All @@ -18,13 +18,14 @@ def initialize(attributes)
@remote_addr = attributes[:remote_addr]
@referrer = attributes[:referrer]
@request_id = attributes[:request_id]
@scheme = attributes[:scheme] || raise(ArgumentError.new(":scheme is required"))
@user_agent = attributes[:user_agent]
end

def to_hash
{host: host, method: method, path: path, port: port, query_params: query_params,
headers: {content_type: content_type, remote_addr: remote_addr, referrer: referrer,
request_id: request_id, user_agent: user_agent}}
request_id: request_id, scheme: scheme, user_agent: user_agent}}
end
alias to_h to_hash

Expand Down
2 changes: 1 addition & 1 deletion lib/timber/events/http_server_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Events
#
# @note This event should be installed automatically through probes,
# such as the {Probes::ActionControllerLogSubscriber} probe.
class HTTPResponse < Timber::Event
class HTTPServerResponse < Timber::Event
attr_reader :status, :time_ms, :additions

def initialize(attributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def process_action(event)
status = extract_status(exception_class_name)
end

Events::HTTPResponse.new(
Events::HTTPServerResponse.new(
status: status,
time_ms: event.duration,
additions: additions
Expand Down
3 changes: 2 additions & 1 deletion lib/timber/probes/rails_rack_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def before_dispatch(env)
def http_request_event(request)
# No idea why rails 3.X returns a "/" :/
referrer = request.referer == "/" ? nil : request.referer
Events::HTTPRequest.new(
Events::HTTPServerRequest.new(
host: request.host,
method: request.request_method,
path: request.filtered_path,
Expand All @@ -33,6 +33,7 @@ def http_request_event(request)
remote_addr: request.ip,
referrer: referrer,
request_id: request_id(request.env),
scheme: request.schema,
user_agent: request.user_agent
)
end
Expand Down

0 comments on commit 5b17dd6

Please sign in to comment.