This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-grpc.git


The following commit(s) were added to refs/heads/main by this push:
     new 24c42730 Fix Codecs.negotiate() dropping supported encodings with 
whitespace (#850)
24c42730 is described below

commit 24c42730804b190b0c2f78aad0ac448abc0024e3
Author: haroldb1 <[email protected]>
AuthorDate: Thu Aug 20 10:16:22 2026 +0100

    Fix Codecs.negotiate() dropping supported encodings with whitespace (#850)
    
    Motivation:
    grpc-accept-encoding headers formatted with a space after the comma
    (e.g. "deflate, gzip", as sent by grpc-go/grpc-python/grpcurl) were
    never matched against supported codec names, silently downgrading
    negotiation to Identity even when the client offered gzip.
    
    Modification:
    Trim each split token in `Message-Accept-Encoding`.findIn before
    codec-name lookup.
    
    Result:
    Codecs.negotiate now correctly picks a supported codec regardless of
    whitespace around commas in grpc-accept-encoding.
    
    Tests:
    - sbt "runtime / testOnly org.apache.pekko.grpc.CodecsSpec" - pass
    
    References:
    Fixes #847
---
 .../main/scala/org/apache/pekko/grpc/scaladsl/headers/headers.scala  | 2 +-
 runtime/src/test/scala/org/apache/pekko/grpc/CodecsSpec.scala        | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git 
a/runtime/src/main/scala/org/apache/pekko/grpc/scaladsl/headers/headers.scala 
b/runtime/src/main/scala/org/apache/pekko/grpc/scaladsl/headers/headers.scala
index 7c894dfa..a70437ae 100644
--- 
a/runtime/src/main/scala/org/apache/pekko/grpc/scaladsl/headers/headers.scala
+++ 
b/runtime/src/main/scala/org/apache/pekko/grpc/scaladsl/headers/headers.scala
@@ -44,7 +44,7 @@ object `Message-Accept-Encoding` extends 
ModeledCustomHeaderCompanion[`Message-A
     Try(new `Message-Accept-Encoding`(value))
 
   def findIn(headers: Iterable[jm.HttpHeader]): Array[String] =
-    headers.collectFirst { case h if h.is(name) => h.value().split(',') 
}.getOrElse(Array.empty)
+    headers.collectFirst { case h if h.is(name) => 
h.value().split(',').map(_.trim) }.getOrElse(Array.empty)
 
   /** Java API */
   def findIn(headers: java.lang.Iterable[jm.HttpHeader]): Array[String] = {
diff --git a/runtime/src/test/scala/org/apache/pekko/grpc/CodecsSpec.scala 
b/runtime/src/test/scala/org/apache/pekko/grpc/CodecsSpec.scala
index 33753ce9..4f6b928b 100644
--- a/runtime/src/test/scala/org/apache/pekko/grpc/CodecsSpec.scala
+++ b/runtime/src/test/scala/org/apache/pekko/grpc/CodecsSpec.scala
@@ -72,6 +72,11 @@ class CodecsSpec extends AnyWordSpec with Matchers with 
TryValues {
       Codecs.negotiate(request) should be(Gzip)
     }
 
+    "negotiate gzip when grpc-accept-encoding uses comma+space separators (as 
sent by grpc-go/grpc-python/grpcurl)" in {
+      val request = HttpRequest(headers = 
immutable.Seq(RawHeader("grpc-accept-encoding", "deflate, gzip")))
+      Codecs.negotiate(request) should be(Gzip)
+    }
+
   }
 
   "Detecting message encoding from remote" should {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to