From a3cdf1b9a559ac56c0d4683a83403451a67b8f86 Mon Sep 17 00:00:00 2001 From: "John A. De Goes" Date: Wed, 27 Sep 2023 08:48:25 +0100 Subject: [PATCH] buildfix (#2461) --- .gitignore | 1 + zio-http/src/main/scala/zio/http/Header.scala | 52 ++++++++----------- .../scala/zio/http/codec/RichTextCodec.scala | 2 +- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 0b964178a8..0f591e9dcc 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ out dist/* target/ bin/ +null/ libexec/ lib_managed/ src_managed/ diff --git a/zio-http/src/main/scala/zio/http/Header.scala b/zio-http/src/main/scala/zio/http/Header.scala index 96df8c62d3..bfd2bf6b9d 100644 --- a/zio-http/src/main/scala/zio/http/Header.scala +++ b/zio-http/src/main/scala/zio/http/Header.scala @@ -2491,14 +2491,11 @@ object Header { val type1 = RichTextCodec.string.collectOrFail("unsupported main type") { case value if MediaType.mainTypeMap.get(value).isDefined => value } - val type1x = (RichTextCodec.literalCI("x-") ~ token.repeat.string).transform[String](in => s"${in._1}${in._2}", in => ("x-", s"${in.substring(2)}")) - val codecType1 = (type1 | type1x).transform[String]( - _.merge, - { - case x if x.startsWith("x-") => Right(x) - case x => Left(x) - }, - ) + val type1x = (RichTextCodec.literalCI("x-") ~ token.repeat.string).transform[String](in => s"${in._1}${in._2}")(in => ("x-", s"${in.substring(2)}")) + val codecType1 = (type1 | type1x).transform[String](_.merge) { + case x if x.startsWith("x-") => Right(x) + case x => Left(x) + } val codecType2 = token.repeat.string val codecType = (codecType1 <~ RichTextCodec.char('/').const('/')) ~ codecType2 val attribute = token.repeat.string @@ -2508,32 +2505,27 @@ object Header { val param = (( RichTextCodec.char(';').const(';') ~> - (RichTextCodec.whitespaceChar.repeat | RichTextCodec.empty).transform[Char](_ => ' ', _ => Left(Chunk(()))).const(' ') ~> + (RichTextCodec.whitespaceChar.repeat | RichTextCodec.empty).transform[Char](_ => ' ')(_ => Left(Chunk(()))).const(' ') ~> attribute <~ RichTextCodec.char('=').const('=') ) ~ value) - .transformOrFailLeft[ContentType.Parameter]( - in => ContentType.Parameter.fromCodec(in), - in => in.toCodec, - ) + .transformOrFailLeft[ContentType.Parameter](in => ContentType.Parameter.fromCodec(in))(in => in.toCodec) val params = param.repeat - (codecType ~ params).transform[ContentType]( - { case (mainType, subType, params) => - ContentType( - MediaType.forContentType(s"$mainType/$subType").get, - params.collect { case p if p.key == ContentType.Parameter.Boundary.name => zio.http.Boundary(p.value) }.headOption, - params.collect { case p if p.key == ContentType.Parameter.Charset.name => java.nio.charset.Charset.forName(p.value) }.headOption, - ) - }, - in => - ( - in.mediaType.mainType, - in.mediaType.subType, - Chunk( - in.charset.map(in => Parameter.Charset(Parameter.Payload(Parameter.Charset.name, in, false))), - in.boundary.map(in => Parameter.Boundary(Parameter.Payload(Parameter.Boundary.name, in, false))), - ).flatten, - ), + (codecType ~ params).transform[ContentType] { case (mainType, subType, params) => + ContentType( + MediaType.forContentType(s"$mainType/$subType").get, + params.collect { case p if p.key == ContentType.Parameter.Boundary.name => zio.http.Boundary(p.value) }.headOption, + params.collect { case p if p.key == ContentType.Parameter.Charset.name => java.nio.charset.Charset.forName(p.value) }.headOption, + ) + }(in => + ( + in.mediaType.mainType, + in.mediaType.subType, + Chunk( + in.charset.map(in => Parameter.Charset(Parameter.Payload(Parameter.Charset.name, in, false))), + in.boundary.map(in => Parameter.Boundary(Parameter.Payload(Parameter.Boundary.name, in, false))), + ).flatten, + ), ) } diff --git a/zio-http/src/main/scala/zio/http/codec/RichTextCodec.scala b/zio-http/src/main/scala/zio/http/codec/RichTextCodec.scala index 6acbb08091..aedc47f8f3 100644 --- a/zio-http/src/main/scala/zio/http/codec/RichTextCodec.scala +++ b/zio-http/src/main/scala/zio/http/codec/RichTextCodec.scala @@ -34,7 +34,7 @@ import zio.{Chunk, NonEmptyChunk} sealed trait RichTextCodec[A] { self => final def string(implicit ev: A =:= Chunk[Char]): RichTextCodec[String] = - self.asType[Chunk[Char]].transform(_.mkString, a => Chunk(a.toList: _*)) + self.asType[Chunk[Char]].transform(_.mkString)(a => Chunk(a.toList: _*)) /** * Returns a new codec that is the sequential composition of this codec and