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-http.git
The following commit(s) were added to refs/heads/main by this push:
new 7def2274d use Locale.ROOT for toLowerCase/toUpperCase (#1086)
7def2274d is described below
commit 7def2274d7a0fb0f778ed80b791b8b4d51f834e6
Author: PJ Fanning <[email protected]>
AuthorDate: Tue Jun 23 20:24:56 2026 +0100
use Locale.ROOT for toLowerCase/toUpperCase (#1086)
---
.../org/apache/pekko/http/impl/engine/http2/Http2Blueprint.scala | 6 +++---
.../org/apache/pekko/http/impl/settings/ParserSettingsImpl.scala | 3 ++-
.../main/scala/org/apache/pekko/http/javadsl/ConnectHttp.scala | 7 ++++---
.../org/apache/pekko/http/javadsl/settings/ParserSettings.scala | 3 ++-
.../scala/org/apache/pekko/http/scaladsl/model/ErrorInfo.scala | 6 ++++--
.../scala/org/apache/pekko/http/scaladsl/model/HttpHeader.scala | 3 ++-
.../scala/org/apache/pekko/http/scaladsl/model/MediaType.scala | 9 +++++----
.../main/scala/org/apache/pekko/http/scaladsl/model/Uri.scala | 3 ++-
.../org/apache/pekko/http/scaladsl/settings/ParserSettings.scala | 3 ++-
.../pekko/http/scaladsl/server/directives/HeaderDirectives.scala | 5 +++--
.../pekko/http/scaladsl/server/directives/MethodDirectives.scala | 4 +++-
.../unmarshalling/PredefinedFromStringUnmarshallers.scala | 3 ++-
12 files changed, 34 insertions(+), 21 deletions(-)
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2Blueprint.scala
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2Blueprint.scala
index 09e498ec6..31454417f 100644
---
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2Blueprint.scala
+++
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2Blueprint.scala
@@ -38,8 +38,8 @@ import pekko.http.scaladsl.settings.{
import pekko.stream.{ BidiShape, Graph, StreamTcpException, ThrottleMode }
import pekko.stream.TLSProtocol._
import pekko.stream.scaladsl.{ BidiFlow, Flow, Keep, Source }
-import pekko.util.ByteString
-import pekko.util.OptionVal
+import pekko.util.{ ByteString, OptionVal }
+import pekko.util.Helpers.toRootLowerCase
import scala.concurrent.duration.{ Duration, FiniteDuration }
import scala.concurrent.{ ExecutionContext, Future }
@@ -226,7 +226,7 @@ private[http] object Http2Blueprint {
}
private[http2] def frameTypeAliasToFrameTypeName(frameType: String):
Option[String] = {
- frameType.toLowerCase match {
+ toRootLowerCase(frameType) match {
case "reset" => Some("RstStreamFrame")
case "headers" => Some("HeadersFrame")
case "continuation" => Some("ContinuationFrame")
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/impl/settings/ParserSettingsImpl.scala
b/http-core/src/main/scala/org/apache/pekko/http/impl/settings/ParserSettingsImpl.scala
index 4e62bc191..aeb3715c9 100644
---
a/http-core/src/main/scala/org/apache/pekko/http/impl/settings/ParserSettingsImpl.scala
+++
b/http-core/src/main/scala/org/apache/pekko/http/impl/settings/ParserSettingsImpl.scala
@@ -27,6 +27,7 @@ import pekko.http.scaladsl.settings.ParserSettings.{
import pekko.http.scaladsl.model._
import pekko.http.scaladsl.settings.ParserSettings
import pekko.util.ConstantFun
+import pekko.util.Helpers.toRootLowerCase
import scala.jdk.CollectionConverters._
@@ -115,7 +116,7 @@ object ParserSettingsImpl extends
SettingsCompanionImpl[ParserSettingsImpl]("pek
Uri.ParsingMode(c.getString("uri-parsing-mode")),
CookieParsingMode(c.getString("cookie-parsing-mode")),
c.getBoolean("illegal-header-warnings"),
-
c.getStringList("ignore-illegal-header-for").asScala.map(_.toLowerCase).toSet,
+
c.getStringList("ignore-illegal-header-for").asScala.map(toRootLowerCase).toSet,
ErrorLoggingVerbosity(c.getString("error-logging-verbosity")),
IllegalResponseHeaderNameProcessingMode(c.getString("illegal-response-header-name-processing-mode")),
IllegalResponseHeaderValueProcessingMode(c.getString("illegal-response-header-value-processing-mode")),
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/javadsl/ConnectHttp.scala
b/http-core/src/main/scala/org/apache/pekko/http/javadsl/ConnectHttp.scala
index 5aa18dd8e..d51bf4610 100644
--- a/http-core/src/main/scala/org/apache/pekko/http/javadsl/ConnectHttp.scala
+++ b/http-core/src/main/scala/org/apache/pekko/http/javadsl/ConnectHttp.scala
@@ -21,6 +21,7 @@ import scala.jdk.OptionConverters._
import org.apache.pekko
import pekko.annotation.{ DoNotInherit, InternalApi }
import pekko.http.javadsl.model.Uri
+import pekko.util.Helpers.toRootLowerCase
@DoNotInherit
abstract class ConnectHttp {
@@ -72,7 +73,7 @@ object ConnectHttp {
}
private def toHost(uriHost: Uri, port: Int): ConnectHttp = {
- val s = uriHost.scheme.toLowerCase(Locale.ROOT)
+ val s = toRootLowerCase(uriHost.scheme)
if (s == "https") new ConnectHttpsImpl(uriHost.host.address,
effectivePort(s, port), context = Optional.empty())
else new ConnectHttpImpl(uriHost.host.address, effectivePort(s, port))
}
@@ -115,7 +116,7 @@ object ConnectHttp {
}
private def toHostHttps(uriHost: Uri, port: Int): ConnectWithHttps = {
- val s = uriHost.scheme.toLowerCase(Locale.ROOT)
+ val s = toRootLowerCase(uriHost.scheme)
require(s == "" || s == "https", "toHostHttps used with non https scheme!
Was: " + uriHost)
new ConnectHttpsImpl(uriHost.host.address, effectivePort("https", port),
context = Optional.empty())
}
@@ -126,7 +127,7 @@ object ConnectHttp {
}
private def effectivePort(scheme: String, port: Int): Int = {
- val s = scheme.toLowerCase(Locale.ROOT)
+ val s = toRootLowerCase(scheme)
if (port >= 0) port
else if (s == "https" || s == "wss") 443
else if (s == "http" || s == "ws") 80
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/javadsl/settings/ParserSettings.scala
b/http-core/src/main/scala/org/apache/pekko/http/javadsl/settings/ParserSettings.scala
index 9948dbc29..df0140066 100644
---
a/http-core/src/main/scala/org/apache/pekko/http/javadsl/settings/ParserSettings.scala
+++
b/http-core/src/main/scala/org/apache/pekko/http/javadsl/settings/ParserSettings.scala
@@ -23,6 +23,7 @@ import pekko.http.impl.engine.parsing.BodyPartParser
import pekko.http.impl.settings.ParserSettingsImpl
import pekko.http.impl.util.JavaMapping.Implicits._
import pekko.http.javadsl.model.{ HttpMethod, MediaType, StatusCode, Uri }
+import pekko.util.Helpers.toRootLowerCase
import com.typesafe.config.Config
import scala.annotation.varargs
@@ -88,7 +89,7 @@ abstract class ParserSettings private[pekko] () extends
BodyPartParser.Settings
self.copy(includeSslSessionAttribute = newValue)
def withModeledHeaderParsing(newValue: Boolean): ParserSettings =
self.copy(modeledHeaderParsing = newValue)
def withIgnoreIllegalHeaderFor(newValue: List[String]): ParserSettings =
- self.copy(ignoreIllegalHeaderFor = newValue.map(_.toLowerCase).toSet)
+ self.copy(ignoreIllegalHeaderFor = newValue.map(toRootLowerCase).toSet)
// special ---
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/ErrorInfo.scala
b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/ErrorInfo.scala
index 7fb70b011..548397a0f 100644
---
a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/ErrorInfo.scala
+++
b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/ErrorInfo.scala
@@ -14,7 +14,9 @@
package org.apache.pekko.http.scaladsl.model
import StatusCodes.ClientError
-import org.apache.pekko.annotation.InternalApi
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.util.Helpers.toRootLowerCase
/**
* Two-level model of error information.
@@ -28,7 +30,7 @@ final class ErrorInfo(
val errorHeaderName: String = "") extends scala.Product with scala.Equals
with java.io.Serializable {
def withSummary(newSummary: String) = copy(summary = newSummary)
def withSummaryPrepended(prefix: String) = withSummary(if (summary.isEmpty)
prefix else prefix + ": " + summary)
- def withErrorHeaderName(headerName: String) = new ErrorInfo(summary, detail,
headerName.toLowerCase)
+ def withErrorHeaderName(headerName: String) = new ErrorInfo(summary, detail,
toRootLowerCase(headerName))
def withFallbackSummary(fallbackSummary: String) = if (summary.isEmpty)
withSummary(fallbackSummary) else this
def formatPretty = if (summary.isEmpty) detail else if (detail.isEmpty)
summary else summary + ": " + detail
def format(withDetail: Boolean): String = if (withDetail) formatPretty else
summary
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpHeader.scala
b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpHeader.scala
index b7bed271e..f5aa9eb82 100644
---
a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpHeader.scala
+++
b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpHeader.scala
@@ -23,6 +23,7 @@ import pekko.http.impl.model.parser.{ CharacterClasses,
HeaderParser }
import pekko.http.javadsl.{ model => jm }
import pekko.http.scaladsl.model.headers._
import pekko.util.OptionVal
+import pekko.util.Helpers.toRootLowerCase
import scala.collection.immutable
@@ -91,7 +92,7 @@ object HttpHeader {
val parser = new HeaderParser(value, settings)
parser.`header-field-value`.run() match {
case Success(preProcessedValue) =>
- HeaderParser.parseFull(name.toLowerCase, preProcessedValue,
settings) match {
+ HeaderParser.parseFull(toRootLowerCase(name), preProcessedValue,
settings) match {
case HeaderParser.Success(header) => ParsingResult.Ok(header, Nil)
case HeaderParser.Failure(info) =>
val errors = info.withSummaryPrepended(s"Illegal HTTP header
'$name'") :: Nil
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/MediaType.scala
b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/MediaType.scala
index ac096cfe2..581a311ca 100644
---
a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/MediaType.scala
+++
b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/MediaType.scala
@@ -18,6 +18,7 @@ import pekko.annotation.DoNotInherit
import pekko.http.impl.util._
import pekko.http.javadsl.{ model => jm }
import pekko.http.impl.util.JavaMapping.Implicits._
+import pekko.util.Helpers.toRootLowerCase
/**
* A MediaType describes the type of the content of an HTTP message entity.
@@ -74,7 +75,7 @@ sealed abstract class MediaType(_mainType: String, _subType:
String) extends jm.
case _ => false
}
- override def hashCode(): Int = value.toLowerCase.hashCode
+ override def hashCode(): Int = toRootLowerCase(value).hashCode
/**
* JAVA API
@@ -327,12 +328,12 @@ object MediaTypes extends ObjectRegistry[(String,
String), MediaType] {
private var extensionMap = Map.empty[String, MediaType]
- def forExtensionOption(ext: String): Option[MediaType] =
extensionMap.get(ext.toLowerCase)
- def forExtension(ext: String): MediaType =
extensionMap.getOrElse(ext.toLowerCase, `application/octet-stream`)
+ def forExtensionOption(ext: String): Option[MediaType] =
extensionMap.get(toRootLowerCase(ext))
+ def forExtension(ext: String): MediaType =
extensionMap.getOrElse(toRootLowerCase(ext), `application/octet-stream`)
private def registerFileExtensions[T <: MediaType](mediaType: T): T = {
mediaType.fileExtensions.foreach { ext =>
- val lcExt = ext.toLowerCase
+ val lcExt = toRootLowerCase(ext)
require(!extensionMap.contains(lcExt),
s"Extension '$ext' clash: media-types '${extensionMap(lcExt)}' and
'$mediaType'")
extensionMap = extensionMap.updated(lcExt, mediaType)
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/Uri.scala
b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/Uri.scala
index 09d7df932..48c72b162 100644
--- a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/Uri.scala
+++ b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/Uri.scala
@@ -28,6 +28,7 @@ import pekko.http.javadsl.{ model => jm }
import pekko.http.impl.model.parser.UriParser
import pekko.http.impl.model.parser.CharacterClasses._
import pekko.http.impl.util._
+import pekko.util.Helpers.toRootLowerCase
import Uri._
import org.parboiled2.{ CharPredicate, CharUtils, ParserInput }
@@ -871,7 +872,7 @@ object Uri {
} else if (allLower) -1
else -2
verify() match {
- case -2 => scheme.toLowerCase
+ case -2 => toRootLowerCase(scheme)
case -1 => scheme
case ix => fail(s"Invalid URI scheme, unexpected character at pos $ix
('${scheme.charAt(ix)}')")
}
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/settings/ParserSettings.scala
b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/settings/ParserSettings.scala
index 20833d2dd..04a658f8c 100644
---
a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/settings/ParserSettings.scala
+++
b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/settings/ParserSettings.scala
@@ -26,6 +26,7 @@ import pekko.http.impl.util._
import pekko.http.javadsl.model
import pekko.http.scaladsl.model._
import pekko.http.scaladsl.{ settings => js }
+import pekko.util.Helpers.toRootLowerCase
import scala.jdk.CollectionConverters._
import scala.jdk.OptionConverters._
@@ -123,7 +124,7 @@ abstract class ParserSettings private[pekko] () extends
pekko.http.javadsl.setti
self.copy(includeSslSessionAttribute = newValue)
override def withModeledHeaderParsing(newValue: Boolean): ParserSettings =
self.copy(modeledHeaderParsing = newValue)
override def withIgnoreIllegalHeaderFor(newValue: List[String]):
ParserSettings =
- self.copy(ignoreIllegalHeaderFor = newValue.map(_.toLowerCase).toSet)
+ self.copy(ignoreIllegalHeaderFor = newValue.map(toRootLowerCase).toSet)
// overloads for idiomatic Scala use
def withUriParsingMode(newValue: Uri.ParsingMode): ParserSettings =
self.copy(uriParsingMode = newValue)
diff --git
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/HeaderDirectives.scala
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/HeaderDirectives.scala
index a594f4c49..aa95f470b 100644
---
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/HeaderDirectives.scala
+++
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/HeaderDirectives.scala
@@ -21,6 +21,7 @@ import org.apache.pekko
import pekko.http.impl.util._
import pekko.http.scaladsl.model._
import pekko.http.scaladsl.model.headers._
+import pekko.util.Helpers.toRootLowerCase
/**
* @groupname header Header directives
@@ -81,7 +82,7 @@ trait HeaderDirectives {
* @group header
*/
def headerValueByName(headerName: String): Directive1[String] =
- headerValue(optionalValue(headerName.toLowerCase)) |
reject(MissingHeaderRejection(headerName))
+ headerValue(optionalValue(toRootLowerCase(headerName))) |
reject(MissingHeaderRejection(headerName))
/**
* Extracts the first HTTP request header of the given type.
@@ -125,7 +126,7 @@ trait HeaderDirectives {
* @group header
*/
def optionalHeaderValueByName(headerName: String):
Directive1[Option[String]] = {
- val lowerCaseName = headerName.toRootLowerCase
+ val lowerCaseName = toRootLowerCase(headerName)
extract(_.request.headers.collectFirst {
case h: HttpHeader if h.is(lowerCaseName) => h.value
})
diff --git
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/MethodDirectives.scala
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/MethodDirectives.scala
index 01ca61ea7..3a18eda3c 100644
---
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/MethodDirectives.scala
+++
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/MethodDirectives.scala
@@ -14,6 +14,8 @@
package org.apache.pekko.http.scaladsl.server
package directives
+import java.util.Locale
+
import org.apache.pekko
import pekko.http.scaladsl.model.{ HttpMethod, StatusCodes }
import pekko.http.scaladsl.model.HttpMethods._
@@ -111,7 +113,7 @@ trait MethodDirectives {
def overrideMethodWithParameter(paramName: String): Directive0 =
parameter(paramName.optional).flatMap {
case Some(method) =>
- getForKey(method.toUpperCase) match {
+ getForKey(method.toUpperCase(Locale.ROOT)) match {
case Some(m) => mapRequest(_.withMethod(m))
case _ => complete(StatusCodes.NotImplemented)
}
diff --git
a/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/PredefinedFromStringUnmarshallers.scala
b/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/PredefinedFromStringUnmarshallers.scala
index 35893f3ce..f0c3dc781 100755
---
a/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/PredefinedFromStringUnmarshallers.scala
+++
b/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/PredefinedFromStringUnmarshallers.scala
@@ -20,6 +20,7 @@ import scala.collection.immutable
import org.apache.pekko
import pekko.http.scaladsl.util.FastFuture
import pekko.util.ByteString
+import pekko.util.Helpers.toRootLowerCase
trait PredefinedFromStringUnmarshallers {
@@ -49,7 +50,7 @@ trait PredefinedFromStringUnmarshallers {
implicit val booleanFromStringUnmarshaller: Unmarshaller[String, Boolean] =
Unmarshaller.strict[String, Boolean] { string =>
- string.toLowerCase match {
+ toRootLowerCase(string) match {
case "true" | "yes" | "on" | "1" => true
case "false" | "no" | "off" | "0" => false
case "" => throw
Unmarshaller.NoContentException
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]