From de74ee47ba2a427967ca4a8819a6d7efcea76ec7 Mon Sep 17 00:00:00 2001 From: Luiz Carlos Manhani Junior <139877977+luizmanhani@users.noreply.github.com> Date: Tue, 24 Sep 2024 11:54:21 -0300 Subject: [PATCH] fix Guzzle psr7 invalid header error (#20) --- class_map/TextCodec.php | 7 +++++- src/Support/GuzzleHeaderValidate.php | 37 ++++++++++++++++++++++++++++ src/Support/TextCodecOtel.php | 6 ++++- tests/GuzzleHeaderValidateTest.php | 35 ++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 src/Support/GuzzleHeaderValidate.php create mode 100644 tests/GuzzleHeaderValidateTest.php diff --git a/class_map/TextCodec.php b/class_map/TextCodec.php index 84fe86c..9c35b46 100644 --- a/class_map/TextCodec.php +++ b/class_map/TextCodec.php @@ -2,6 +2,7 @@ namespace Jaeger\Codec; +use Hyperf\Tracer\Support\GuzzleHeaderValidate; use Hyperf\Tracer\Support\TextCodecOtel; use Exception; use Jaeger\SpanContext; @@ -76,8 +77,12 @@ public function inject(SpanContext $spanContext, &$carrier) if ($this->urlEncoding) { $encodedValue = urlencode($value); } + $headerName = $this->baggagePrefix . $key; - $carrier[$this->baggagePrefix . $key] = $encodedValue; + if (!GuzzleHeaderValidate::isValidHeader($headerName, $encodedValue)) { + continue; + } + $carrier[$headerName] = $encodedValue; } } diff --git a/src/Support/GuzzleHeaderValidate.php b/src/Support/GuzzleHeaderValidate.php new file mode 100644 index 0000000..a392d73 --- /dev/null +++ b/src/Support/GuzzleHeaderValidate.php @@ -0,0 +1,37 @@ + $value) { - $baggageHeader[] = $key . '=' . $value; + $value = $key . '=' . $value; + if (!GuzzleHeaderValidate::isValidHeaderValue($value)) { + continue; + } + $baggageHeader[] = $value; } $carrier[$this->traceStateHeader] = implode(',', $baggageHeader); } diff --git a/tests/GuzzleHeaderValidateTest.php b/tests/GuzzleHeaderValidateTest.php new file mode 100644 index 0000000..5cc3cef --- /dev/null +++ b/tests/GuzzleHeaderValidateTest.php @@ -0,0 +1,35 @@ +