Skip to content

Commit

Permalink
Borrow Rack::Utils for building nested query
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikspang committed Nov 5, 2024
1 parent 882c5bd commit 33e9f2d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/excon/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def extract_request_info(env)
result[:query] = env[:query]

# Handle excon 1.0.0+
result[:query] = ::Rack::Utils.build_nested_query(result[:query]) unless result[:query].is_a?(String)
result[:query] = build_nested_query(result[:query]) unless result[:query].is_a?(String)

result[:body] = env[:body]
end
Expand Down
19 changes: 19 additions & 0 deletions sentry-ruby/lib/sentry/utils/http_tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ def propagate_trace?(url)
Sentry.configuration.propagate_traces &&
Sentry.configuration.trace_propagation_targets.any? { |target| url.match?(target) }
end

# Kindly borrowed from Rack::Utils
def build_nested_query(value, prefix = nil)
case value
when Array
value.map { |v|
build_nested_query(v, "#{prefix}[]")
}.join("&")
when Hash
value.map { |k, v|
build_nested_query(v, prefix ? "#{prefix}[#{k}]" : k)
}.delete_if(&:empty?).join("&")
when nil
URI.encode_www_form_component(prefix)
else
raise ArgumentError, "value must be a Hash" if prefix.nil?
"#{URI.encode_www_form_component(prefix)}=#{URI.encode_www_form_component(value)}"
end
end
end
end
end

0 comments on commit 33e9f2d

Please sign in to comment.