Skip to content

Commit

Permalink
Merge pull request #10 from http4s/prepare-1.0
Browse files Browse the repository at this point in the history
Prepare 1.0 series
  • Loading branch information
rossabaker authored May 26, 2022
2 parents 004b7e7 + f681b0b commit e1c5b64
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 35 deletions.
16 changes: 1 addition & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.12.15, 2.13.8, 3.1.2]
scala: [2.13.8, 3.1.2]
java: [temurin@8, temurin@11, temurin@17]
exclude:
- scala: 2.12.15
java: temurin@11
- scala: 2.12.15
java: temurin@17
- scala: 3.1.2
java: temurin@11
- scala: 3.1.2
Expand Down Expand Up @@ -220,16 +216,6 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.12.15)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.15

- name: Inflate target directories (2.12.15)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.8)
uses: actions/download-artifact@v2
with:
Expand Down
7 changes: 3 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
ThisBuild / tlBaseVersion := "0.23"
ThisBuild / tlMimaPreviousVersions ++= (0 to 11).map(y => s"0.23.$y").toSet
ThisBuild / tlBaseVersion := "1.0"
ThisBuild / developers := List(
tlGitHubDev("rossabaker", "Ross A. Baker")
)

val Scala213 = "2.13.8"
ThisBuild / crossScalaVersions := Seq("2.12.15", Scala213, "3.1.2")
ThisBuild / crossScalaVersions := Seq(Scala213, "3.1.2")
ThisBuild / scalaVersion := Scala213

lazy val root = project.in(file(".")).aggregate(scalaXml).enablePlugins(NoPublishPlugin)

val http4sVersion = "0.23.12"
val http4sVersion = "1.0.0-M33"
val scalaXmlVersion = "2.1.0"
val munitVersion = "0.7.29"
val munitCatsEffectVersion = "1.0.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ import scala.xml.XML
trait ElemInstances {
protected def saxFactory: SAXParserFactory

implicit def xmlEncoder[F[_]](implicit charset: Charset = `UTF-8`): EntityEncoder[F, Elem] =
EntityEncoder
.stringEncoder[F]
implicit def xmlEncoder(implicit charset: Charset = `UTF-8`): EntityEncoder.Pure[Elem] =
EntityEncoder.stringEncoder
.contramap[Elem] { node =>
val sw = new StringWriter
XML.write(sw, node, charset.nioCharset.name, true, null)
Expand Down
28 changes: 15 additions & 13 deletions scala-xml/src/test/scala/org/http4s/scalaxml/ScalaXmlSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ScalaXmlSuite extends CatsEffectSuite with ScalaCheckSuite {
def getBody(body: EntityBody[IO]): IO[String] =
body.through(utf8.decode).foldMonoid.compile.lastOrError

def strBody(body: String): EntityBody[IO] = Stream(body).through(utf8.encode)
def strEntity(body: String): Entity[IO] = Entity(Stream(body).through(utf8.encode))

def writeToString[A](a: A)(implicit W: EntityEncoder[IO, A]): IO[String] =
Stream
Expand All @@ -57,14 +57,16 @@ class ScalaXmlSuite extends CatsEffectSuite with ScalaCheckSuite {
}

test("xml should parse the XML") {
server(Request[IO](body = strBody("<html><h1>h1</h1></html>")))
server(Request[IO](entity = strEntity("<html><h1>h1</h1></html>")))
.flatMap(r => getBody(r.body))
.assertEquals("html")
}

test("parse XML in parallel") {
val req = Request(body =
strBody("""<?xml version="1.0" encoding="UTF-8" standalone="yes"?><html><h1>h1</h1></html>""")
val req = Request(entity =
strEntity(
"""<?xml version="1.0" encoding="UTF-8" standalone="yes"?><html><h1>h1</h1></html>"""
)
)
// https://github.com/http4s/http4s/issues/1209
(0 to 5).toList
Expand All @@ -77,8 +79,8 @@ class ScalaXmlSuite extends CatsEffectSuite with ScalaCheckSuite {
}

test("return 400 on parse error") {
val body = strBody("This is not XML.")
val tresp = server(Request[IO](body = body))
val entity = strEntity("This is not XML.")
val tresp = server(Request[IO](entity = entity))
tresp.map(_.status).assertEquals(Status.BadRequest)
}

Expand All @@ -94,8 +96,8 @@ class ScalaXmlSuite extends CatsEffectSuite with ScalaCheckSuite {

test("encode to UTF-8") {
val hello = <hello name="Günther"/>
assertIO(
xmlEncoder[IO](Charset.`UTF-8`)
assertEquals(
xmlEncoder(Charset.`UTF-8`)
.toEntity(hello)
.body
.through(fs2.text.utf8.decode)
Expand All @@ -109,10 +111,10 @@ class ScalaXmlSuite extends CatsEffectSuite with ScalaCheckSuite {
test("encode to UTF-16") {
val hello = <hello name="Günther"/>
assertIO(
xmlEncoder[IO](Charset.`UTF-16`)
xmlEncoder(Charset.`UTF-16`)
.toEntity(hello)
.body
.through(decodeWithCharset(StandardCharsets.UTF_16))
.through(decodeWithCharset[IO](StandardCharsets.UTF_16))
.compile
.string,
"""<?xml version='1.0' encoding='UTF-16'?>
Expand All @@ -123,10 +125,10 @@ class ScalaXmlSuite extends CatsEffectSuite with ScalaCheckSuite {
test("encode to ISO-8859-1") {
val hello = <hello name="Günther"/>
assertIO(
xmlEncoder[IO](Charset.`ISO-8859-1`)
xmlEncoder(Charset.`ISO-8859-1`)
.toEntity(hello)
.body
.through(decodeWithCharset(StandardCharsets.ISO_8859_1))
.through(decodeWithCharset[IO](StandardCharsets.ISO_8859_1))
.compile
.string,
"""<?xml version='1.0' encoding='ISO-8859-1'?>
Expand All @@ -136,7 +138,7 @@ class ScalaXmlSuite extends CatsEffectSuite with ScalaCheckSuite {

property("encoder sets charset of Content-Type") {
forAll { (cs: Charset) =>
assertEquals(xmlEncoder[IO](cs).headers.get[`Content-Type`].flatMap(_.charset), Some(cs))
assertEquals(xmlEncoder(cs).headers.get[`Content-Type`].flatMap(_.charset), Some(cs))
}
}

Expand Down

0 comments on commit e1c5b64

Please sign in to comment.