From e38bf92e48e89e058669ac549a74d4d13fdf9bf7 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 25 Oct 2022 21:14:57 +0200 Subject: [PATCH] Handle REQUEST_URI with base url This has been reported to happen on WEBrick, it may happen in other ways depending on how the variable is set. --- lib/datadog/tracing/contrib/rack/middlewares.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/datadog/tracing/contrib/rack/middlewares.rb b/lib/datadog/tracing/contrib/rack/middlewares.rb index 0caa839848..550b5f8828 100644 --- a/lib/datadog/tracing/contrib/rack/middlewares.rb +++ b/lib/datadog/tracing/contrib/rack/middlewares.rb @@ -268,10 +268,12 @@ def parse_url(env, original_env) query_string.empty? ? path : "#{path}?#{query_string}" else - request_uri + # normally REQUEST_URI starts at the path, but it + # might contain the full URL in some cases (e.g WEBrick) + request_uri.sub(/^#{base_url}/, '') end - ::URI.join(base_url, fullpath).to_s + base_url + fullpath end def parse_user_agent_header(headers)